Re: Structure of a Delphi app.


[ Delphi Forum ] [ Delphi Tutorials -- by DelphiLand ]

Posted by webmaster Guido on May 26, 2003

In Reply to: Structure of a Delphi app. posted by Mac on May 26, 2003

: Hi! I'm attempting to write an application using Delphi and I am somewhat uncertain of my coding style. I find that all the code for my application is in the same file, i.e. not like C++ whereas each class usually represents a file. I find there is not much structure to my application. Can anyone give me a little light on this subject? Are there any good Delphi books/tutorials I can read that could help me with this?
---------

As you probably know already, for a GUI (Windows) application written with Delphi you always have a project file (.DPR), maintained for you by Delphi. Further on, for each form of the application, there is a unit file (.PAS) and a form file (.FRM). In fact, the files for the forms each define a class (the class TForm1, TForm2, and so on), and the .DPR file describes the program that creates objects from these classes.

For each additional class that you define yourself, it's best to have a separate unit-file (only a .PAS file). With the exception of classes that have one or more descendants, where it's sometimes easier to keep the parent-class and its descendants in one unit.

For large applications, it's a good rule of thumb to keep only the interface in the forms units, and put all other processing in separate units: one for your "general" functions and procedures, plus one for each class that you define, plus maybe a data-module if you work with databases.

But these are not fixed rules. E.g., for a small project where you have only one form (the main form), it's often easier to put everything in one single unit.



[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]