调用 TComponentEditor 类的 Edit 方法时遇到访问冲突:
type
TLBIWXDataGridEditor = class(TComponentEditor)
public
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
procedure Edit; override;
end;
这是重写的编辑方法:
procedure TLBIWXDataGridEditor.Edit;
var
_DsgForm: TLBIWXDataGridDesigner;
begin
_DsgForm := TLBIWXDataGridDesigner(Application);
try
_DsgForm.DataGrid := TLBIWXDataGrid(Self.Component);
_DsgForm.ShowModal;
finally
FreeAndNil(_DsgForm);
end;
end;
所有 TLBIWXDataGrid 属性只能在设计表单内更改,因为它没有任何已发布的属性。
在设计时通过双击组件来调用 Edit 方法时,我要么收到 AV,要么 IDE 突然崩溃。
我认为问题与其他重写方法无关,但以下是它们的实现:
procedure TLBIWXDataGridEditor.ExecuteVerb(Index: Integer);
begin
case Index of
0: MessageDlg ('add info here', mtInformation, [mbOK], 0);
1: Self.Edit;
end;
end;
function TLBIWXDataGridEditor.GetVerb(Index: Integer): string;
begin
case Index of
0: Result := '&About...';
1: Result := '&Edit...';
end;
end;
function TLBIWXDataGridEditor.GetVerbCount: Integer;
begin
result := 2;
end;
我错过了什么?
最佳答案
这一行是错误的:
_DsgForm := TLBIWXDataGridDesigner(Application);
这是将Application
对象类型转换到TLBIWXDataGridDesigner
中,这是行不通的。
改用这个:
_DsgForm := TLBIWXDataGridDesigner.Create(Application);
或者这样,因为您是手动释放对话框,所以它不需要分配 Owner
:
_DsgForm := TLBIWXDataGridDesigner.Create(nil);
关于delphi - 如何在delphi中正确调用组件的自定义组件编辑器表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57538270/