1

我有一个自定义的 FireMonkey 控件 (TComboBox),它也有一个自定义的 TComponentEditor。当我覆盖 ExecuteVerb 方法并尝试添加子组件(自定义 TListBoxControl)自定义 TComboBox 时,它不会在设计时显示

默认 TComboBox 行为:

默认 TComboBox 行为

自定义 TComboBox

自定义 TComboBox

我的 ExecuteVerb 代码:

var
  PpComboItem : TPpListBoxItem;
  PpCombo: TPpComboBox;
begin
  if (Component is TPpComboBox) then
    PpCombo := (Component as TPpComboBox) else
      exit;

  PpComboItem := TPpListBoxItem.Create(PpCombo);
  PpComboItem.Parent := PpCombo;
end

我试图追踪 TComboBox 尝试执行此操作的方式,但似乎无法找到具有正确实现的单元

** 编辑 **

好的 - 我已经设法了解了 TMS 的人如何通过他们的组件(购买和支付)实现这一目标,并且我已经设法推断出以下内容

var
  PpComboItem : TPpListBoxItem;
  PpCombo: TPpComboBox;
begin
  inherited;
  if (Component is TPpComboBox) then
    PpCombo := (Component as TPpComboBox) else
      exit;

  PpComboItem := (TPpListBoxItem(Designer.CreateComponent(TPpListBoxItem,  PpCombo, 10, 10, 100, 100)));
  PpComboItem.Parent := PpCombo;
  Designer.Modified;
end;

但是当我在 ComponentEditor 中单击 AddTPpListBoxItem 时,我收到以下错误:

TPpListBoxItem 类不适用于此模块

4

1 回答 1

1

我找到了我的答案。要使其正常工作,您需要

确保您尝试作为子组件添加到父组件的组件也已注册:

USES TPpListBoxItem.pas, TPpComboBox.pas, DesignIntf, DesignEditors

//TComponentEditor Type Decleration //

procedure Register;
begin
  RegisterComponents('Sample', [TPpListBoxItem]);
  RegisterComponents('Sample', [TPpComboBox]);
  RegisterComponentEditor(TPpComboBox, TComboComponentEditor);
end;

覆盖父组件的 TComponentEditor 的 ExecuteVerb 方法(在我的问题中找到第一个编辑所在的代码):

基本上肉是:

...
PpComboItem := (TPpListBoxItem(Designer.CreateComponent(TPpListBoxItem, PpCombo, 10, 10, 100, 100)));
PpComboItem.Parent := PpCombo;
Designer.Modified;
...

瞧!

于 2016-08-18T21:17:40.687 回答