unit CollectionExt;
interface
Uses SysUtils, Classes;
Type
TExtCollection =
class(TCollection)
private
function GetFormatSignature:
String;
public
procedure SaveToFile(
const Filename : TFilename);
procedure SaveToStream(Stream : TStream);
procedure LoadFromFile(
const Filename : TFilename);
procedure LoadFromStream(Stream : TStream);
end;
implementation
const
iFilerBufferSize = 4096;
{ TExtCollection }
function TExtCollection.GetFormatSignature:
String;
begin
Result := ItemClass.ClassName;
end;
procedure TExtCollection.LoadFromFile(
const Filename: TFilename);
var
FileStream : TFileStream;
begin
Clear;
FileStream:=TFileStream.Create(Filename,fmOpenRead);
Try
LoadFromStream(FileStream);
Finally
FileStream.Free;
end;
end;
procedure TExtCollection.LoadFromStream(Stream: TStream);
var
Reader : TReader;
begin
Reader:=TReader.Create(Stream,iFilerBufferSize);
Try
Reader.ReadValue;
Reader.ReadCollection(Self);
Finally
Reader.Free;
end;
end;
procedure TExtCollection.SaveToFile(
const Filename: TFilename);
var
FileStream : TFileStream;
begin
FileStream:=TFileStream.Create(Filename,fmCreate);
Try
SaveToStream(FileStream);
Finally
FileStream.Free;
end;
end;
procedure TExtCollection.SaveToStream(Stream: TStream);
var
Writer : TWriter;
begin
Writer:=TWriter.Create(Stream,iFilerBufferSize);
Try
Writer.WriteCollection(Self);
Finally
Writer.Free;
end;
end;
end.