Understanding Delphi classes (10)-in-depth methods [25]-use method types

Source: Internet
Author: User
// To understand this, use the callback function {define method type} type tfuntype = function (X: integer): integer; {function type} tproctype = procedure (Name: string); {process type} {define a function that meets the tfuntype} function myfun (X: integer): integer; begin result: = x * 2; end; {define a process that complies with the tproctype type} procedure myproc (Name: string); begin showmessage ('I am' + name); end; {use} procedure tform1.button1click (Sender: tobject); var fun: tfuntype; {defines a tfuntype variable} proc: tproctype; {defines a tproctype variable} begin fun: = myfun; {Let the variable fun point to the custom function myfun} proc: = myproc that has the same parameters and return values as it; {Let the variable proc point to the custom process myproc} with the same parameters {now the variables fun and proc can use} showmessage (inttostr (fun (4) of the two methods ))); {8} proc ('case'); {I am in case} end;

 

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.