Reputation: 408
i have component with function getsomedata (key:string;listener:Tlistener)
which listener declared like event as follow :
Tlistener = procedure (name,age,sex:string) of object ;
but in my component listener manager when i add the new listener takes listener parameter as TObject class like .
ListenerManager.addListener(key:string;Listener:TObject);
when i complile the code i got error message
Not enough actual parameters
because Event Object (TListener) and ListenerManager Parameter (TObject).
sample of full function code .
procedure getsomedata (key:string;listener:Tlistener) ;
begin
ListenerManager.addListener(key,listener); //error Here >>> addListener input parameters (key:string;Listener:TObject);
end;
how can i resolve it ?
Upvotes: 0
Views: 726
Reputation: 612784
In this code:
procedure getsomedata (key:string;listener:Tlistener) ;
begin
ListenerManager.addListener(key,listener);
end;
You are attempting to pass a variable of type TListener
to the second parameter of addListener
. That parameter is typed as being TObject
.
Now, TListener
is typed as being
procedure(name,age,sex:string) of object;
A variable of procedural type cannot be passed to a parameter of type TObject
.
It's rather difficult to know exactly what the correct code would look like because the question doesn't contain enough background information. Perhaps addListener
should receive a TListener
rather than a TObject
. But that's just a guess. If you want more complete advice, then you will need to add sufficient detail to the question.
You state in a comment that:
I can not change the parameter type
TObject
toTListener
.
In that case you are stuck. It's simply not possible to cast a TListener
to a TObject
. Now, you could implement a class that had a single field of type TListener
, and pass that. But I doubt very much that's really the right solution.
Upvotes: 1