Alberto Rossi
Alberto Rossi

Reputation: 1800

Share procedure for different units

I have 4 units in my Delphi project (4 forms too) and I have a procedure in Unit 2 that is called "controlla".

procedure TForm2.controlla(numero:TEdit);
var a:string;
begin
 // the code
end; 

I made this procedure because it converts a decimal number to a fractional number. By the way, I have to use this function in Unit 4 too.

I thought I could do a *.dll library with this function. Before trying the libraby way, is there any method that allows me to use controlla(numero:TEdit), that is in unit 2, in Unit 4 without a dll?

Upvotes: 0

Views: 136

Answers (1)

Bruce McGee
Bruce McGee

Reputation: 15334

I would create a fifth unit and put your common methods in there. MiscUtils.pas, for example. Then use that unit anywhere you need to call any of the methods.

As an aside, instead of passing in a TEdit, use a string parameter. That way this method doesn't have to know anything about TEdits, arguably making it more flexible.

Upvotes: 3

Related Questions