zoukankan      html  css  js  c++  java
  • 深入方法(25)- 使用方法类型

    //弄明白这一点, 才好使用回调函数
    
    {定义方法类型}
    type
      TFunType  = function(x: Integer): Integer; {函数类型}
      TProcType = procedure(name: string);       {过程类型}
    
    {定义一个符合 TFunType 类型的函数}
    function MyFun(x: Integer): Integer;
    begin
      Result := x * 2;
    end;
    
    {定义一个符合 TProcType 类型的过程}
    procedure MyProc(name: string);
    begin
      ShowMessage('我是' + name);
    end;
    
    
    {使用}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Fun : TFunType;  {定义一个 TFunType  类型的变量}
      Proc: TProcType; {定义一个 TProcType 类型的变量}
    begin
      Fun  := MyFun;   {让变量 Fun 指向和它具有同样参数和返回值的自定义函数 MyFun}
      Proc := MyProc;  {让变量 Proc 指向和它具有同样参数的自定义过程 MyProc}
    
      {现在这两个方法的变量 Fun、Proc 可以使用了}
      ShowMessage(IntToStr(Fun(4))); {8}
      Proc('万一');                  {我是万一}
    end;
  • 相关阅读:
    Thread Based Parallelism
    Thread Based Parallelism
    The Divide and Conquer Approach
    Algorithms
    FTP
    POP and IMAP
    通过 python 处理 email
    Android开发环境搭建简介
    Hello world
    mybatis3.2初学感悟
  • 原文地址:https://www.cnblogs.com/fansizhe/p/12729741.html
Copyright © 2011-2022 走看看