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

Still curious? Ask our experts.

Chat with our AI personalities

EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga

Add your answer:

Earn +20 pts
Q: What is a Delphi unit?
Write your answer...
Submit
Still have questions?
magnify glass
imp