In the Delphi window unit, how to invoke the cells of other windows. Reproduced
.
Simple Call Unit in Delphi
Unit instance
First, create a new project file, the default file is Unit1, the code is as follows: 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);
can also be so ntemp:=unit2.add (3,4);
Edit1. Text:=inttostr (NTEMP);
End
End.
2, create a new unit, the default name is Unit2, the code is as follows:
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.
From here we can see that the reference to the unit is very simple.
Our unit2 is just a unit of code, no form. In the interface section we declare the externally visible part of the unit, and in implementation, the implementation part is defined.
In Unit1, after we quote Unit2, we can call the Add function directly, and of course, we can add the form of Unit2.add () in front of it.
.
In this unit, we can put some common functions, classes and other things in order to achieve the modularity of the program. Easy program structure. It also facilitates program maintenance.
In the Delphi window unit, how to invoke the cells of other windows.