Example Delphi Multiple Units: ACCESSING UNIT / FORM UNIT ![]() unit mainUi; interface uses //Here we need to declare which units need to be accessed. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, DBU, Dialogs, Menus, SpyArrayU, StdCtrls, ComCtrls, jpeg, ExtCtrls; //make sure to include required units names. type procedure TFrmSpy.mmDisplayClick(Sender: TObject); begin iSpyArray.Sort; //Call sort procedure. //This procedure is in the SpyyArray Unit. Rchoutput.Lines.Add(iSpyArray.ToString) //Call ToString Function. end; ![]() Example Delphi Multiple Units: SOURCE UNIT / SpyArray UNIT ![]()
unit SpyArrayU; //Please note this is an OOP unit, but principle remains the same.
interface
uses Sysutils, SpyU, DBU; //Further links to other objects/units.
Type TSpyArray = Class
Private
SpyArr: Array[1..100] of spy; //Will require a Loop in most code.
Size: Integer;
protected
Public
Constructor create; //Always in Public.
//Accessor Methods
//Mutator Methods
//Other Methods
Procedure Sort;
Function Search(which: string):string;
Function ViewCoded: string;
Function ToString: string;
End;
Var
iSpyArray: TSpyArray; //Declare object. Used to call object/unit.
![]() Example Delphi Multiple Units: AVOIDING CIRCULAR REFERENCE ERROR ![]()
unit SpyArrayU; //Please note this is an OOP unit, but principle remains the same.
interface
uses Sysutils, SpyU, MainUI, DBU; //You can not declare the accessing unit from the source unit.
Type TSpyArray = Class
Private
SpyArr: Array[1..100] of spy; //Will require a Loop in most code.
Size: Integer;
protected
Public
Constructor create; //Always in Public.
//Accessor Methods
//Mutator Methods
//Other Methods
Procedure Sort;
Function Search(which: string):string;
Function ViewCoded: string;
Function ToString: string;
End;
Var
iSpyArray: TSpyArray; //Declare object/ unit. Used to call object/unit.
implementation
{ TSpyArray }
uses MenuUI; //Thus to avoid the error simply place a new uses under implementation.
|
Multiple Units & Forms: ![]() Current Tutorial Info: In oder to create another unit you will need to select <File> <New> <Unit - Delphi for Win32>. A unit consist only of code and therefore has no attached form. Often related procedures or functions are placed in a separate unit. However, multiple units are more often used in Object Orientated Programming. Where each class/object has its own unit. When using multiple units & forms, they need to be linked. However, when linking forms we need to avoid the <circular Reference Error>. Most often only the accessing unit is linked to the source unit but his can differ when both units are required to be linked. To avoid the above error look at the example codes: ![]() Current Tutorial Principle: When using multiple forms the same linking methods are used and the same method is used to solve the <circular Reference Error>. However, when using multiple forms you will need to use <FormName.show/hide> |


Delphi Multi Units


