The essence of the callback function is to treat the function as a parameter (first define the function type)

Source: Internet
Author: User

//A method as a parameter to another method, which is called a callback method, is used to call the callback functiontypeTfuntype =function(I:integer): Integer;{Declaring a method type}functionMyfun (I:integer): Integer;{Establish a type-compatible function}beginResult: = i*2;End;{function as argument, define a function}functionMyTest (X:integer; F:tfuntype): Integer;beginResult: = F (x);End;{test}procedureTform1.button1click (Sender:tobject);varFun:tfuntype;{Declare a tfuntype variable}I:integer;beginFun: = Myfun;{Let the method variable fun point to a method that is compatible with its type}{test fun; Fun is a method variable, and now to execute that method, it can be used as that method.}I: = Fun (4); ShowMessage (IntToStr (i));//8{Use fun as a parameter; use function as a parameter, this is the callback function}I: = MyTest (4, fun); ShowMessage (IntToStr (i));//8End;

Http://www.cnblogs.com/del/archive/2008/01/15/1039476.html

The essence of the callback function is to treat the function as a parameter (first define the function type)

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.