|
CD Chili Code plugin - Delphi |
|
|
|
Demo for Core Design Chili Code plugin - Delphi.
(*
extracted from "Avoiding memory leaks"
(http://www.delphibasics.co.uk/Article.asp?Name=Memory)
*)
unit MyClass;
interface
uses
Classes;
type
TMyClass = class
private
fileData : TStringList;
published
Constructor Create(const fileName : string);
Destructor Destroy; override;
procedure PrintFile;
end;
implementation
uses
Printers, Dialogs, SysUtils;
// Constructor - builds the class object
constructor TMyClass.Create(const fileName: string);
begin
// Create the string list object used to hold the file contents
fileData := TStringList.Create;
// And load the file data into it
try
fileData.LoadFromFile(fileName);
except
ShowMessage('Error : '+fileName+' file not found.');
end;
end;
// Destructor - frees up memory used by the class object
destructor TMyClass.Destroy;
begin
// Free up the memory used by the string list object
FreeAndNil(fileData);
// Call the parent class destructor
inherited;
end;
// Print the file passed to the constructor
procedure TMyClass.PrintFile;
var
myFile : TextFile;
i : Integer;
begin
// Open a printer file
AssignPrn(myFile);
// Now prepare to write to the printer
ReWrite(myFile);
// Write the lines of the file to the printer
for i := 0 to fileData.Count-1 do
WriteLn(myFile, fileData[i]);
// Close the print file
CloseFile(myFile);
end;
end.
Article Supporters:
0 (total)
|