Wikia

Delphi Programming

Pointer to overloaded procedure

2,918pages on
this wiki
Talk0

Delphi 4 introduced function and method overloading and added one problem: How do you get a pointer to an particular overlaoded method / function.

Example:

 unit1; 
 
 interface 
 
 function add(n1,n2 : integer):integer;overload; 
 
 function add(f1,f2 : double):double;overload; 
 
 implementation 
 
 ... 
 
 end. 

Is there a way to get address of second add (with double) function ?

 Unit2; 
 
 interface 
 
 uses 
   Unit1; 
 
 function addr1:Pointer; 
 
 implementation 
 
 function addr1:pointer; 
 begin 
   Result:=@Add; 
 end; 
 
 end. 

addr1 returns first add's address, how can I obtain seconds ?

 type
   TDoubleFunc = function(f1,f2:double):double; 
 
 function addr2:pointer; 
 var
   f:TDoubleFunc; 
 begin 
   f := Add; 
   Result:=@f; 
 end; 

(Curtesy of Marc Rohloff [TeamB])

Around Wikia's network

Random Wiki