Gets the address of the function (three methods, respectively @,addr,methodaddress)

Source: Internet
Author: User

Problem Source: http://www.cnblogs.com/del/archive/2008/07/30/1039045.html#1272783


In the compiler's view, overloaded functions are fundamentally different functions, and of course there are different function addresses; The address we get with the usual method is just the first overloaded address.


Code files:

UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs;typeTForm1 =class(Tform)procedureFormcreate (Sender:tobject);End;varForm1:tform1;Implementation{$R *.DFM}{Example two overloaded functions first}functionMyfun (S:string):string;Overload;beginResult: = s;End;functionMyfun (I:integer):string;Overload;beginResult: = IntToStr (i);End;{Get the address of the overloaded function separately}procedureTform1.formcreate (Sender:tobject);type {Two method types need to be defined, with arguments corresponding to the overloaded function above}TF1 =function(s:string):string; TF2 =function(I:integer):string;varF1:TF1;{corresponds to overloading one}F2:TF2;{corresponds to overloaded two}S1,S2:string;beginF1: = Myfun;{Let F1 point to overload one}F2: = Myfun;{Let F2 point to overloaded two}{Test Function}S1: = F1 (' abc '); S2: = F2 (123); SHOWMESSAGEFMT ('%s ',%s ', [S1,S2]);{ABC, 123}{The first two values are the addresses of two overloaded functions; the third value is obtained from the function name, which is the same as the address of the first overload}SHOWMESSAGEFMT ('%p,%p,%p ', [@f1, @f2, @MyFun]);{Another method}SHOWMESSAGEFMT ('%p,%p,%p ', [Addr (F1), ADDR (F2), Addr (Myfun)]);{If it is a method in the class published, you can also get the address using methodaddress}End;End.

Http://www.cnblogs.com/del/archive/2008/07/30/1256889.html

Gets the address of the function (three methods, respectively @,addr,methodaddress)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.