Leo*_*uno 1 delphi components custom-controls
调用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;
Run Code Online (Sandbox Code Playgroud)
这是覆盖的编辑方法:
procedure TLBIWXDataGridEditor.Edit;
var
_DsgForm: TLBIWXDataGridDesigner;
begin
_DsgForm := TLBIWXDataGridDesigner(Application);
try
_DsgForm.DataGrid := TLBIWXDataGrid(Self.Component);
_DsgForm.ShowModal;
finally
FreeAndNil(_DsgForm);
end;
end;
Run Code Online (Sandbox Code Playgroud)
所有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;
Run Code Online (Sandbox Code Playgroud)
我想念什么?
这行是错误的:
_DsgForm := TLBIWXDataGridDesigner(Application);
Run Code Online (Sandbox Code Playgroud)
据类型转换的Application对象为TLBIWXDataGridDesigner,这是行不通的。
使用此代替:
_DsgForm := TLBIWXDataGridDesigner.Create(Application);
Run Code Online (Sandbox Code Playgroud)
或这样,因为您是手动释放对话框,所以不需要Owner分配:
_DsgForm := TLBIWXDataGridDesigner.Create(nil);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
78 次 |
| 最近记录: |