In the Delphi window unit, how to invoke the cells of other windows.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.