【问题标题】:Custom Firemonkey Component that implements TComponentEditor. Add child control to parent at design time实现 TComponentEditor 的自定义 Firemonkey 组件。在设计时将子控件添加到父控件
【发布时间】:2016-12-24 14:38:31
【问题描述】:

我有一个自定义的 FireMonkey 控件 (TComboBox),它也有一个自定义的 TComponentEditor。当我覆盖 ExecuteVerb 方法并尝试将子组件(自定义 TListBoxControl)添加到自定义 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 类不适用于该模块

【问题讨论】:

  • 我不知道扩展 TCustomListbox 的项目编辑器是否更容易在下拉列表中添加一个新的 TListBoxItem 以及所有其他 TListBoxItem 类型?

标签: delphi components firemonkey custom-component delphi-10.1-berlin


【解决方案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;
...

瞧!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-06
    • 1970-01-01
    • 2011-05-18
    • 2023-03-27
    • 2013-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    相关资源
    最近更新 更多