TBaseParams = class(TObject);
TParamsForA = class(TBaseParams)
Param1: string;
Param2: string;
end;
TParamsForB = class(TBaseParams)
Param1: double;
Param2: double;
Param10: double;
end;
TMyMethod = procedure(const Params: TBaseParams);
implementation
procedure MethodA(const Params: TBaseParams);
var
MyParams: TParamsForA;
begin
MyParams := Params as TParamsForA;
//do stuff
end;
procedure MethodB(const Params: TBaseParams);
var
MyParams: TParamsForB;
begin
MyParams := Params as TParamsForB;
//do stuff
end;
procedure CallMyMethod(const Params: TBaseParams; const MyMethod: TMyMethod);
begin
try
//do some common stuff
MyMethod(Params);
finally
//and more common stuff here
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
ParamsForA: TParamsForA;
ParamsForB: TParamsForB;
begin
ParamsForA := TParamsForA.Create;
ParamsForA.Param1 := 'aaa';
ParamsForA.Param2 := 'bbb';
CallMyMethod(ParamsForA, MethodA);
ParamsForA.Free;
ParamsForB := TParamsForB.Create;
ParamsForB.Param1 := 1;
ParamsForB.Param2 := 2;
ParamsForB.Param10 := 3;
CallMyMethod(ParamsForB, MethodB);
ParamsForB.Free;
end;