Reputation: 565
I have code like this:
TServer = class
private
fOnMsgFromServer: TProc<String, String, String>;
public
procedure RegisterOnMsgFromServer(aCallBack: TProc<String, String, String>);
procedure Execute;
end;
procedure TServer.RegisterOnMsgFromServer(aCallBack: TProc<String, String, String>);
begin
fOnMsgFromServer := aCallBack;
end;
procedure TServer.Execute;
begin
fOnMsgFromServer('userName', 'password', 'message');
end;
Problem is in procedure Execute when I want put arguments to fOnMsgFromServer. "helper" shows me (Arg1: string; Arg2: string; Arg3: string), and i just don't know which parameter is which.
There is any solution to name this arguments?
Upvotes: 3
Views: 143
Reputation: 613382
You cannot avoid these generic names if you use the generic TProc<T1,T2,T3>
type. Its declaration looks like this:
type
TProc<T1,T2,T3> = reference to procedure (Arg1: T1; Arg2: T2; Arg3: T3);
As you can see, this is where the names originate. If you use this type, you are stuck with these names.
Instead you should declare a bespoke reference procedure type rather than using the generic type. Not only will this let you impart meaningful names to the arguments, it also lets you stop repeating your self over and over.
type
TMsgFromServerProc = reference to procedure(UserName, Password, Msg: string);
TServer = class
private
fOnMsgFromServer: TMsgFromServerProc;
public
procedure RegisterOnMsgFromServer(aCallBack: TMsgFromServerProc);
end;
Upvotes: 7