Declaration¶
Source position: pascodegen.pp line 47
type
TPascalCodeGenerator = class(TComponent)
public
constructor Create;
destructor Destroy;
procedure EnsureSection;
procedure PushSection;
function PopSection : TCodeSection;
procedure CreateHeader;
procedure CreateUnitClause;
procedure Indent;
procedure Undent;
function IsKeyWord : Boolean;
function EscapeKeyWord : string;
function MakePascalString : string;
function PrettyPrint : string;
procedure AddLn(const aLine: string);
procedure AddLn(const TheLines: Array of string = string);
procedure AddLn(const TheLines: TStrings);
procedure AddLn(const Fmt: string; Args: Array of const);
procedure Comment(const AComment: string; Curly: Boolean=False);
procedure Comment(const AComment: Array of string = string);
procedure Comment(const AComment: TStrings);
procedure ClassComment;
procedure ClassHeader;
procedure SimpleMethodBody;
procedure SaveToStream;
procedure SaveToFile;
property Source: TStrings; {r}
property CurrentSection: TCodeSection; {rw}
published
property OutputUnitName: string; {rw}
property ExtraUnits: string; {rw}
property DottedExtraUnits: string; {rw}
property DottedDefine: string; {rw}
property DottedUnitsSupport: TDottedUnitsSupport; {rw}
property LicenseText: TStrings; {rw}
property Switches: TStrings; {rw}
property OnLog: TCodeGeneratorLogEvent; {rw}
property AddTimeStamp: Boolean; {rw}
property KeywordSuffix: string; {rw}
property KeywordPrefix: string; {rw}
end;
Inheritance¶
Description¶
TPascalCodeGenerator is a class that provides functionality for generating Pascal code. It offers utility methods for code indentation, section management, logging and automatic handling of code blocks. The resulting generated code is available in a string list accessible through the TPascalCodeGenerator.Source property. The class supports dotted unit names and provides configurable keyword escaping.
Properties¶
| Member | Visibility | Description |
|---|---|---|
| AddTimeStamp | published | Whether to include timestamp in header |
| CurrentSection | public | Current code section type |
| DottedDefine | published | Compiler define for dotted units |
| DottedExtraUnits | published | Additional units for dotted uses clause |
| DottedUnitsSupport | published | Level of dotted units support |
| ExtraUnits | published | Additional units for uses clause |
| KeywordPrefix | published | Prefix for escaped keywords |
| KeywordSuffix | published | Suffix for escaped keywords |
| LicenseText | published | License text for header comment |
| OutputUnitName | published | Name of the output unit |
| Source read only | public | Generated source code string list |
| Switches | published | Compiler switches for the unit |
Methods¶
| Member | Visibility | Description |
|---|---|---|
| AddLn | public | Add line to source code with current indentation |
| ClassComment | public | Add formatted class comment header |
| ClassHeader | public | Add class header comment (deprecated) |
| Comment | public | Add comment to source code |
| Create | public | Create new Pascal code generator instance |
| CreateHeader | public | Create unit header section |
| CreateUnitClause | public | Create unit clause |
| Destroy | public | Destroy Pascal code generator instance |
| EnsureSection | public | Ensure code is in specified section |
| EscapeKeyWord | public | Escape Pascal keyword if needed |
| Indent | public | Increase indentation level |
| IsKeyWord | public | Check if string is Pascal keyword |
| MakePascalString | public | Convert string to Pascal string literal |
| PopSection | public | Pop section from section stack |
| PrettyPrint | public | Format string with proper capitalization |
| PushSection | public | Push section onto section stack |
| SaveToFile | public | Save generated source code to file |
| SaveToStream | public | Save generated source code to stream |
| SimpleMethodBody | public | Generate simple method body |
| Undent | public | Decrease indentation level |
See also¶
| Name | Description |
|---|---|
| TCodeSection | Pascal code section types |
| TCodeGeneratorLogEvent | Event handler type for logging messages |