Brooks Computing Systems Delphi Blog Headline Animator

Friday, October 1, 2010

Anatomy Of Delphi Object Pascal Source Code

Before continuing make sure to format your source code so it at least adheres to the specification established via the IDE. This makes subsequent tidying much more succinct.

Programs and units comprise Object Pascal applications. This phase of the Delphi Tidy program will address primarily the unit as opposed to the program. Tidy for program source code will commence shortly after the Delphi Tidy for units is complete.

Generally there are two main sections to Delphi 2010 unit source code they are the interface and implementation sections respectively.

The interface section structure is different from the implementation section. The interface section deals primarily with the classes and their associated variables properties and various housekeeping.

The implementation section deals with variables and the actual methods and functions of the associated class(es).

Sub sections of the interface section are as follows:

1. Any code preceding the uses declaration. This would include the unit, interface code. This code typically will not need any tidying. This should be stored intact and retrieved when all tiding is complete and the output source is to be produced.

2. The uses statement should appear on a single line. The actual module names appear after the units declarative. These module names should be unstrung based on comma and or space separators, sorted in ascending sequence and reconstructed to fill the code block to acceptable specifications.

3. The next section should consist of the code proceeding the complete uses statement up to the first class declaration. The class of course concludes with the end declarative. The class name should be extracted because it will be used as a key in subsequent procesing.

a) The first subsection would include all code below the class statement up to the first procedure declaration. These component contents should be sorted in ascending alphabetical order and if comments do not exist a blank comment will be inserted for each entry.

b) The next subsection would include procedures functions and any codes before the private directive. These codes should be sorted in ascending alphabetical order. These declarations will be kept in tact and the procedure name will be extracted and used as a key for each entry.

c) The next subsection would include private variable declarations. They will include everything below the private declarative until the first function or procedure in the private declaration area. Any variable declared without comments will be furnished with comments.

d) The next subsection would include all functions and procedures up to the public declarative. These functions and procedures should be sorted in ascending alphabetical sequence.

e) The next subsection would include all entries after the public directive through the end directive for the class. These entries are sorted in ascending order.

This process will repeat until all classes in the implementation section are converted.

4. Any local variables should be sorted in ascending alphabetical order and if comments are not in place a blank comment will be inserted. Repeat this process until the implementation directive in encountered.

5. The implementation section should be kept in tact up to the first procedure or function is encountered. The application must be intelligent enough to accommodate any documentation prior to and after its formal implementation. The documentation and all code is kept in tact until the next procedure or function is detected. If the documentation does not exist it should be initiated and inserted in a rough in style of coding. The procedure or function name of code section must be extracted and stored as it will be used as a key for insertion into the database and subsequent ordering of the implementation section. This process is repeated until the “end.” directive is encountered.

This is the initial program specification for the BCS Delphi Tidy Project. It is a work in progress. The document will be finalized after team members have reach a consensus.

1 comment:

  1. This comment has been removed by a blog administrator.