zoukankan      html  css  js  c++  java
  • 深入方法(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.
  • 相关阅读:
    结构和联合
    字符串、字符和字节
    数组
    函数
    指针
    操作符和表达式
    语句
    数据
    TinyXML2 使用
    是否忘记了向源中添加“#include "StdAfx.h"”?
  • 原文地址:https://www.cnblogs.com/fansizhe/p/12729715.html
Copyright © 2011-2022 走看看