我需要在自定义TFDQuery的上下文菜单上添加一个新选项,所以我遵循了这个指南,它工作得很好。How to add context-menu actions in Delphi Form Designer for a custom component?
问题是它替换了TFDQuery的当前TComponentEditor,因此我无法再访问其字段编辑器、查询编辑器...
我想我需要的是从FireDAC基TComponentEditor派生我的TComponentEditor,但我还没有能够识别它。你能告诉我为TFDQuery声明常规TComponentEditor的单元和类吗?.
**更新:**我已经将此代码添加到我的自定义查询中,以获取TFDQuery的当前默认编辑器,它在FireDAC. dcl. Reg单元中显示为TFDQueryEditor。但是我的系统没有任何FireDAC.Dcl.Reg.pas,也找不到任何对FireDAC源代码的TFDQueryEditor的引用。
constructor TKpQuery.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ShowMessage( (GetComponentEditor(Self, NIL) as TObject).ClassName );
ShowMessage( (GetComponentEditor(Self, NIL) as TObject).UnitName );
end;
这是我的自定义ComponentEditor:
interface
uses System.Classes, DesignIntf, DesignEditors, FireDAC.Comp.Client;
type
{$REGION 'TKpQuery Editor Declaration'}
TKpQueryEditor=class(TComponentEditor)
function GetVerbCount: Integer; override;
function GetVerb(Index: Integer): string; override;
procedure ExecuteVerb(Index: Integer); override;
end;
{$ENDREGION}
{$REGION 'TKpQuery Declaration'}
...
...
{$ENDREGION}
procedure Register;
implementation
uses
Data.DB,
System.Types,
System.SysUtils,
System.StrUtils,
System.RegularExpressions;
procedure Register;
begin
{$IFDEF WIN32}
RegisterComponents('My Custom Data Access', [TKpQuery]);
RegisterComponentEditor(TKpQuery, TKpQueryEditor);
{$ENDIF}
end;
{$REGION 'TKpQuery Editor Implementation'}
procedure TKpQueryEditor.ExecuteVerb(Index: Integer);
begin
inherited;
case Index of
0: (Component as TKpQuery).SetDisplayLabels;
end;
end;
function TKpQueryEditor.GetVerb(Index: Integer): string;
begin
case Index of
0: Result := 'Set DisplayLabels';
end;
end;
function TKpQueryEditor.GetVerbCount: Integer;
begin
Result := 1;
end;
{$ENDREGION}
1条答案
按热度按时间hsvhsicv1#
由于Uwe Raabe已经确认派生FDQuery组件编辑器所需的单元不可用,因此我复制了Blurry Sterk建议的解决方案。
这似乎工作得很好: