在Delphi的視窗單元中,如何調用其它視窗的單元。

來源:互聯網
上載者:User

標籤:

在Delphi的視窗單元中,如何調用其它視窗的單元。(轉載)
.
在Delphi中簡單的調用單元
unit執行個體 
一,建立一個工程檔案,預設的檔案是unit1,代碼如下:unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls;

type
   TForm1 = class(TForm)
     Button1: TButton;
     Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
   Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
   nTemp:integer;
begin
   nTemp:=add(3,4);
  //也可以這樣nTemp:=unit2.add(3,4);

   edit1.Text:=inttostr(nTemp);
end;

end.

 

2,建立一個unit,預設名稱是unit2,代碼如下:

unit Unit2;

interface
  uses windows,messages, SysUtils, Variants, Classes;
  function add(a,b:integer):integer;

implementation

function add(a,b:integer):integer;
begin
   result:=a+b;
end;

end.

 

從這裡我們可以看到,單元的引用是非常簡單的.
我們的unit2隻是一個代碼單元,沒有表單.在interface節中我們相當於聲明了單元的對外可見部分,在implementation中,定義了實現部分.
在unit1當中,我們引用unit2後,直接可以調用add函數了,當然,也可以在前面加上unit2.add()這樣的形式.
.
在這個單元中,我們可以把一些公用函數,類等東西放進去,實現程式的模組化.便於程式結構明晰.也便於程式維護。

在Delphi的視窗單元中,如何調用其它視窗的單元。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.