Registriert seit: 20. Jan 2006
Ort: Lübbecke
11.487 Beiträge
Delphi 12 Athens
|
AW: Interface Methode als Parameter übergeben
26. Jul 2022, 13:01
Ist nur so eine Idee:
Delphi-Quellcode:
type
TJSONObjectFunc = reference to function( const Param: TJSONObject): TJSONObject;// of object;
type
TPubFunc = record
class function InstallEvent(Target: IPubFunc): TJSONObjectFunc; static;
class function UninstallEvent(Target: IPubFunc): TJSONObjectFunc; static;
class function SubscribeEvent(Target: IPubFunc): TJSONObjectFunc; static;
class function UnsubscribeEvent(Target: IPubFunc): TJSONObjectFunc; static;
class function CancelSubscriber(Target: IPubFunc): TJSONObjectFunc; static;
class function FireEvent(Target: IPubFunc): TJSONObjectFunc; static;
end;
implementation
class function TPubFunc.InstallEvent(Target: IPubFunc): TJSONObjectFunc;
begin
Result := function(const Param: TJSONObject) : TJSONObject
begin
Result := Target.InstallEvent(Param);
end;
end;
{ analog für die anderen Methoden }
Aufruf dann so:
Delphi-Quellcode:
procedure HandlePubFunc(xPubFunc: IPubFunc; AFunc: TJSONObjectFunc);
begin
...
json := AFunc(jsonPara);
...
end
var
xPubFunc : IPubFunc;
begin
xPubFunc := xClient.Service<IPubFunc>;
HandlePubFunc(xPubFunc, TPubFunc.InstallEvent(xPubFunc));
...
HandlePubFunc(xPubFunc, TPubFunc.FireEvent(xPubFunc));
...
end;
|