zoukankan      html  css  js  c++  java
  • 理解 Delphi 的类(十) 深入方法[14] 在TForm1 类内声明的方法

    //要点14: 如果声明在 TForm1 类内, 那它就是 TForm1 类的一个方法了
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        function MyFun(x,y: Integer): Integer; {函数声明在 TForm1 类的体内}
        {现在这个函数 MyFun 已经是 TForm1 类的一个方法了}
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    {函数在实现区必须有 TForm1. 作为前缀}
    function TForm1.MyFun(x,y: Integer): Integer;
    begin
      Result := x + y;
    end;
    
    {调用}
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    begin
      i := MyFun(1,2);
      ShowMessage(IntToStr(i)); {3}
    end;
    
    end.
    
  • 相关阅读:
    请假两时间的小时数差
    Python3之旅
    python语法总结1
    关于命令行的小结
    从Java到C#再到python
    数据库知识
    Visual Studio高低版本的问题(以2008和2015为例)
    web api
    readoney和const
    null
  • 原文地址:https://www.cnblogs.com/del/p/1038854.html
Copyright © 2011-2022 走看看