-
Notifications
You must be signed in to change notification settings - Fork 0
RADProgrammer Style Guide File Layout (.pas .dpr)
Most of your Delphi code will reside in .pas source files. These files have a few requirements determined by the compiler and also some preferences dictated by this style guide.
The first section present in a unit is an optional comment header.
If descriptions are included in a comment header, the first line of the unit should be a one-line description followed by a blank line and then an optional longer description.
Copyright and license information should follow the description lines. Any copyright notice must be left in-place and not altered in any way.
Optional modification and version history should be the last portion of the comment header section.
A clean looking interface
section is a sign of a healthy unit! Only one class should normally be defined per unit, with the common exceptions of a paired set of classes.
The preferred order of declarations in the body of a class definition should be Constants
, Fields
, Methods
, and then Properties
. Identifiers should be grouped by visibility level and then grouped together as desired (sorted alphabetically if no other logical grouping is desired.)
As is common practice, methods that implement specific Interfaces should be grouped together and prefixed with the Interface name in a comment line as demonstrated below:
{ IOTAThreadNotifier160 }
procedure EvaluateComplete(const pExprStr:string; const pResultStr:string; pCanModify:Boolean; pResultAddress:TOTAAddress; pResultSize:LongWord; pReturnCode:Integer); overload;
{ IOTANotifier }
procedure BeforeSave();
procedure AfterSave();
procedure Destroyed();
procedure Modified();
The preferred order of blocks is: const
, type
, var
, and then methods. There can be an occasional second const
declaration referring back to types or vars, but there typically is no reason to have multiple block declarations of the same type within the same scope (with the obvious exception of inline variables and nested types.)
Any variable or type not expected to be used outside of the current unit should be defined in a separate strict private
section within the main class unit and grouped separately at the top of the implementation section (placed above of the main class constructor.)
The first two methods defined in the implementation
section should be the constructor
and destructor
methods of the main class. If there are multiple constructors, list them by parameter count order with the parameterless constructor listed first.
Class constructors should be at the end of the unit, just above a related class destructor and above the unit initialization section.
These sections are always located at the bottom of the unit, just above the final end.