To overcome a bug in 10.3.3 (see QC report https://quality.embarcadero.com/browse/RSP-29565) relating to TFDTable detailed elsewhere (Delphi TFDTable open fails when indexname is set), I want to be able to define a class with a method in a common unit that can be assigned (programmatically) as a BeforeOpen event in the relevant DFM for TFDTable components defined on a Form or DataModule.
I realize that this question has been asked before (e.g. How to make a separate unit for event methods, which IDE allows me to assign to component events at design time?), but the solutions batted about there match what I have done, and they do not work.
So, in a unit that must already be listed in the uses clause of the units using TFDTable, I define my class thus:
Common_unit:
type
TmyMethodHolder = class(TComponent)
published
procedure FDTableBeforeOpen(DataSet: TDataSet);
end;
...
var
myMethodHolder : TmyMethodHolder=nil;
...
procedure TmyMethodHolder.FDTableBeforeOpen(DataSet: TDataSet);
begin
// this procedure below is also defined within this "common_unit"
FDTableSetCatalogName(Dataset);
end;
...
initialization
myMethodHolder := TmyMethodHolder.Create(nil);
finalization
myMethodHolder.Free;
In the Registration unit, the component (and the class - though this seems to make no difference) are registered as follows:
RegisterComponents('MyComponents', [TmyMethodHolder]);
RegisterClass(TmyMethodHolder);
Finally, in a test unit, I define a Form with a TFDTable. That unit uses the "common_unit" above:
unit FDTable_Bug_Demo2;
interface
uses
... Common_Unit, ....
type
TForm2 = class(TForm)
DBGrid1: TDBGrid;
Button1: TButton;
FDConnection1: TFDConnection;
DataSource1: TDataSource;
edServer: TLabeledEdit;
edDatabase: TLabeledEdit;
edUserName: TLabeledEdit;
edPassword: TLabeledEdit;
Button2: TButton;
Button3: TButton;
FDTable1: TFDTable;
...
With the above in place, I can assign the BeforeOpen event of FDTable1 at runtime like so, and everything works as expected:
FDTable1.BeforeOpen := myMethodHolder.FDTableBeforeOpen;
However, I cannot assign the BeforeOpen event of FDTable1 at design-time (to e.g. myMethodHolder.FDTableBeforeOpen). The IDE complains that it is not a valid identifier.
Even if I drop a TMyMethodHolder component onto the Form as myMethodHolder1 (which rather defeats my purpose), I cannot assign the BeforeOpen event to myMethodHolder1.FDTableBeforeOpen. Again, not a valid identifier.
I assume what I am trying to do is possible, and I have just missed something basic. Help please.