delphi 哪个是TFDQuery的TableentEditor?

e4yzc0pl  于 2023-10-18  发布在  其他
关注(0)|答案(1)|浏览(129)

我需要在自定义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的引用。

  1. constructor TKpQuery.Create(AOwner: TComponent);
  2. begin
  3. inherited Create(AOwner);
  4. ShowMessage( (GetComponentEditor(Self, NIL) as TObject).ClassName );
  5. ShowMessage( (GetComponentEditor(Self, NIL) as TObject).UnitName );
  6. end;

这是我的自定义ComponentEditor:

  1. interface
  2. uses System.Classes, DesignIntf, DesignEditors, FireDAC.Comp.Client;
  3. type
  4. {$REGION 'TKpQuery Editor Declaration'}
  5. TKpQueryEditor=class(TComponentEditor)
  6. function GetVerbCount: Integer; override;
  7. function GetVerb(Index: Integer): string; override;
  8. procedure ExecuteVerb(Index: Integer); override;
  9. end;
  10. {$ENDREGION}
  11. {$REGION 'TKpQuery Declaration'}
  12. ...
  13. ...
  14. {$ENDREGION}
  15. procedure Register;
  16. implementation
  17. uses
  18. Data.DB,
  19. System.Types,
  20. System.SysUtils,
  21. System.StrUtils,
  22. System.RegularExpressions;
  23. procedure Register;
  24. begin
  25. {$IFDEF WIN32}
  26. RegisterComponents('My Custom Data Access', [TKpQuery]);
  27. RegisterComponentEditor(TKpQuery, TKpQueryEditor);
  28. {$ENDIF}
  29. end;
  30. {$REGION 'TKpQuery Editor Implementation'}
  31. procedure TKpQueryEditor.ExecuteVerb(Index: Integer);
  32. begin
  33. inherited;
  34. case Index of
  35. 0: (Component as TKpQuery).SetDisplayLabels;
  36. end;
  37. end;
  38. function TKpQueryEditor.GetVerb(Index: Integer): string;
  39. begin
  40. case Index of
  41. 0: Result := 'Set DisplayLabels';
  42. end;
  43. end;
  44. function TKpQueryEditor.GetVerbCount: Integer;
  45. begin
  46. Result := 1;
  47. end;
  48. {$ENDREGION}
hsvhsicv

hsvhsicv1#

由于Uwe Raabe已经确认派生FDQuery组件编辑器所需的单元不可用,因此我复制了Blurry Sterk建议的解决方案。
这似乎工作得很好:

  1. unit MyCustom.Query.Editor;
  2. interface
  3. uses
  4. Windows, SysUtils, Classes, DesignIntf, DesignEditors;
  5. type
  6. TgkQueryEditor = class(TComponentEditor)
  7. private
  8. FOldEditor: IComponentEditor;
  9. protected
  10. public
  11. constructor Create(AComponent: TComponent; ADesigner: IDesigner); override;
  12. procedure ExecuteVerb(Index: Integer); override;
  13. function GetVerb(Index: Integer): string; override;
  14. function GetVerbCount: Integer; override;
  15. procedure Edit; override;
  16. procedure Copy; override;
  17. end;
  18. procedure Register;
  19. implementation
  20. uses
  21. MyCustom.Query;
  22. var
  23. PrevEditorClass: TComponentEditorClass = nil;
  24. constructor TgkQueryEditor.Create(AComponent: TComponent; ADesigner: IDesigner);
  25. begin
  26. inherited Create(AComponent, ADesigner);
  27. if Assigned(PrevEditorClass) then
  28. FOldEditor := TComponentEditor(PrevEditorClass.Create(AComponent, ADesigner));
  29. end;
  30. procedure TgkQueryEditor.ExecuteVerb(Index: Integer);
  31. var
  32. i: Integer;
  33. begin
  34. i := Index - FOldEditor.GetVerbCount;
  35. case i of
  36. 0: (Component as TKpQuery).SetDisplayLabels; // This is my new custom action
  37. else
  38. if Assigned(FOldEditor) then
  39. FOldEditor.ExecuteVerb(Index)
  40. end;
  41. end;
  42. function TgkQueryEditor.GetVerb(Index: Integer): string;
  43. var
  44. i: Integer;
  45. begin
  46. i := Index - FOldEditor.GetVerbCount;
  47. case i of
  48. 0: Result := 'Set Display Label';
  49. else
  50. if Assigned(FOldEditor) then
  51. Result := FOldEditor.GetVerb(Index)
  52. end;
  53. end;
  54. function TgkQueryEditor.GetVerbCount: Integer;
  55. begin
  56. Result := 1;
  57. if Assigned(FOldEditor) then
  58. Inc(Result, FOldEditor.GetVerbCount);
  59. end;
  60. procedure TgkQueryEditor.Edit;
  61. begin
  62. if Assigned(FOldEditor) then
  63. FOldEditor.Edit;
  64. end;
  65. procedure TgkQueryEditor.Copy;
  66. begin
  67. if Assigned(FOldEditor) then
  68. FOldEditor.Copy;
  69. end;
  70. procedure Register;
  71. var
  72. Query: TKpQuery;
  73. Editor: IComponentEditor;
  74. begin
  75. Query := TKpQuery.Create(nil);
  76. try
  77. Editor := GetComponentEditor(Query, nil);
  78. if Assigned(Editor) then
  79. PrevEditorClass := TComponentEditorClass((Editor as TObject).ClassType);
  80. finally
  81. Editor := nil;
  82. FreeAndNIL(Query);
  83. end;
  84. RegisterComponentEditor(TKpQuery, TgkQueryEditor);
  85. end;
  86. end.
展开查看全部

相关问题