zoukankan      html  css  js  c++  java
  • 深入方法(15)- 调用其他单元的函数

    //要点15: 调用其他单元的函数
    //包含函数的单元:
    unit Unit2;
    
    interface
    
    function MyFun(x,y: Integer): Integer; {函数必须在接口区声明}
    
    implementation
    
    function MyFun(x,y: Integer): Integer; {函数必须在函数区实现}
    begin
      Result := x + y;
    end;
    
    end.
    
    
    //调用函数的单元:
    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    uses Unit2; {必须 uses 定义函数的单元}
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i: Integer;
    begin
      i := MyFun(1,2);         {调用函数}
      //i := Unit2.MyFun(1,2); {有时为了避免重名, 需要这样调用}
      ShowMessage(IntToStr(i)); {3}
    end;
    
    end.
  • 相关阅读:
    安装wamp的方法及过程
    js原生获取className&多选一
    构造函数
    轮播图
    NaN
    ++与--运算练习
    if语句的练习
    switch语句的练习
    九九乘法表
    mac下git提交github代码
  • 原文地址:https://www.cnblogs.com/fansizhe/p/12729716.html
Copyright © 2011-2022 走看看