相关疑难解决方法(0)

"无法为未命名的组件创建方法"

以下代码(在包中注册时)为我们提供了一个TParentComponent在托盘中注册的组件Test.

但是,使用属性编辑器(在相同代码中提供)创建Child对象时,IDE将显示错误消息" 无法为未命名的组件创建方法".

奇怪的是,Child对象确实有一个名字.

这是来源:

unit TestEditorUnit;

interface

uses
  Classes, DesignEditors, DesignIntf;

type  
  TParentComponent = class;

  TChildComponent = class(TComponent)
  private
    FParent: TParentComponent;
    FOnTest: TNotifyEvent;
    procedure SetParent(const Value: TParentComponent);
  protected
    procedure SetParentComponent(AParent: TComponent); override;
  public
    destructor Destroy; override;
    function GetParentComponent: TComponent; override;
    function HasParent: Boolean; override;
    property Parent: TParentComponent read FParent write SetParent;
  published
    property OnTest: TNotifyEvent read FOnTest write FOnTest;
  end;

  TParentComponent = class(TComponent)
  private
    FChilds: TList;
  protected
    procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  public
    constructor …
Run Code Online (Sandbox Code Playgroud)

delphi events properties editor

8
推荐指数
1
解决办法
1232
查看次数

集合编辑器不会为TPersistent属性中的TCollection属性打开

我有自定义集合属性,当它是我的组件的直接成员时,它工作得很好.

但我想将集合属性移动到我的组件中的TPersistent属性.现在出现问题,它不起作用:双击对象检查器中的集合属性通常会打开集合编辑器,但它不再存在.

所有的拳头 - 我应该传递给TPersistent属性的构造函数?

TMyCollection = class(TCollection)
  constructor Create(AOwner: TComponent); // TMyCollection constuctor
  ...
Run Code Online (Sandbox Code Playgroud)

我无法通过自我,所以我应该通过我的执着主人?

constructor TMyPersistent.Create(AOwner: TComponent);
begin
  inherited Create;
  fOwner := AOwner;
  fMyCollection := TMyCollection.Create(AOwner); // hmmm... doesn't make sense
end;
Run Code Online (Sandbox Code Playgroud)

我想我错过了什么.如果需要更多代码,请评论此帖.

Da visualizationz

delphi delphi-2010 tpersistent

2
推荐指数
1
解决办法
2046
查看次数

将集合转换为"命名组件" - 编译器错误

这与我提出另一个问题的接受答案有关.在将我已经存在的集合转换为这个新的"命名集合项"结构(如前一个问题中所解释)的过程中,我遇到了编译器错误......

[Error] JDSockets.pas(818): Incompatible types: 'tagWNDCLASSA' and 'Class reference'

这是来自Register第一行的程序RegisterClass(TSvrCommandComp);

TSvrCommandComp是我TChildComponent在上一个答案的TJDServerSocket版本,是我的版本TParentComponent.

现在在上一个答案中,实际上定义了2个单元.我跳过了这个概念并将它们构建到同一个单元中.这个单位非常庞大.在这里,我有尽可能多的无关紧要的东西...

unit JDSockets;

interface

uses
  Classes, Windows, SysUtils, StrUtils, ScktComp, ExtCtrls,
  DesignEditors, DesignIntf;

type
  TSvrCommands = class;
  TSvrCommand = class;
  TSvrCommandComp = class; 
  TSvrCommandParentComp = class;
// ---------- CODE REMOVED HERE ------------

////////////////////////////////////////////////////////////////////////////////
//  Command Collections
//  Goal: Allow entering pre-set commands with unique Name and ID
//  Each command has its own event which …
Run Code Online (Sandbox Code Playgroud)

delphi delphi-7 tcollection

1
推荐指数
1
解决办法
557
查看次数