Posted by webmaster Guido on October 15, 2005
In Reply to: Procedures - Is there any order they should be
placed in coding ? posted by Lionel E Joyner on October 14, 2005:
If a routine is also declared in the interface section of a unit, this acts as a "forward" declaration. In that case, its location (order) in the "implementation" section doesn't matter. That's why Delphi programmers often write routines as "methods" of a form, because then they are always declared in the interface section (under private or under public).
... private // First, all of the private variables, e.g.: N1, N2, N3: integer; // and so on... // Next, the private methods, in any order: procedure Print123; ... implementation ... procedure TForm1.Print123; begin ... end;
But if the procedure Print123 is declared as a "normal" routine (not as a method) and isn't mentioned in the interface, then it must be located BEFORE any code that uses this procedure.
So, this example works:
implementation ... procedure Print123; begin ... end; procedure TForm1.Button1OnClick(...); begin
But the following example does not work:
implementation ... procedure TForm1.Button1OnClick(...); begin PrintSomething; // error: Print123 must be declared before Button1OnClick end; procedure Print123; begin ... end;
Form objects in form procedures|
I needed to have 'Tform1.' in my procedure name and also declare my procedure in the 'type' list for the unit.