The BCS Delphi Tidy for XE8 is a Delphi source beautifier. It uses Delphi source code as input and as sorts component pats in ascending alphabetical order that makes it easier to locate program parts quickly. The resulting code is updated in place. Always make sure to backup you source code before using this or any other source code modifying tool. That way if things do not go as planned simply restore the backup source code.
What the BCS Delphi Tidy Accomplishes the following tasks:
- Reading the Delphi XE8 source code into a string collection.
- Loads a collection of string with the source code before the first process procedure of function is located.
- Detects and stores every block of executable code by location.
- Build a key for sorting component members by name.
- Sort the keys in an additional string list.
- Rebuild the source code by:
- Restoring the source code before the procedures commence.
- Retrieve sorted procedure blocks and add then to the newly created output.
- Add the remaining source code at the end of the program.
The BCS Tidy application is not designed for spaghetti code. In order to successfully use BCS Tidy you source code must be formatted (per Delphi XE8) and have no errors after being processes by Delphi Code To Doc. I have no interest in writing a Tidy for spaghetti code. I you are usable to meet these minimum requirements the BCS Delphi Tidy will probably not work for you.
There is another section of code that sorts the uses statements of the Delphi XE8 source code. It can be reviewed by clicking here.
Currently the BCS Tidy for Delphi XE8 is limited to 500 procedures. Of course this value can be increased but if you have over 500 procedures in your Delphi XE8 source code that would typically be indicative of a severe design flaw.
The Delphi keywords like constructor, function and procedure must all be in lower case.
The blood life of this application is the prec_area record.
[codesyntax lang=”delphi”]
/// Procedure Record Area prec_area = record istart: integer; istop: integer; name: String; mem: TStringList; end;
[/codesyntax]
To establish an array based on this record the following line is issued.
[codesyntax lang=”delphi”]
/// Procedure Record Array pr: array [1 .. 500] of prec_area;
[/codesyntax]
This array tells us where procedures begin and end. A keyword is generated which is used later for sorting. Finally the actual code itself is stored without modifications.
Our newly created Delphi XE8 source code listing is sorted in ascending alphabetical order by process name.
A single dimension array coupled with a complex data type can be quite powerful in an application of this nature.
The source code can be retrieved by clicking here.
This component documentation can be viewed by clicking here.
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.