answersLogoWhite

0

A Delphi unit is a separate file used to store procedures and functions. If you know what a form is, a unit is exactly the same, except it has no visual interface. So you can't put windows controls on it like buttons and edit boxes. A form has windows controls and their associated code behind them, a unit only has the code.

They are useful if you have some functions that you use often from many different forms and you only want to write them once. For example:

function LeftStr(const S : String; Index : Integer) : String;

begin

If Index <= 0

then

Result := ''

else

Result := Copy(S, 1, Index);

end;

function RightStr(const S : String; Index : Integer) : String;

begin

If Index > Length(S)

then

Result := ''

else

Result := Copy(S, Index, (Length(S)-Index+1));

end;

Then you can have your unit's name in a forms uses clause and then use the functions LeftStr and RightStr from several different forms.

User Avatar

Wiki User

13y ago

What else can I help you with?