unit PictureList;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type
TPictureArray =
array of TPicture;
TPictureList =
class(TComponent)
private
FPicture: TPicture;
FPictureArray: TPictureArray;
procedure SetPicture(Value: TPicture);
function GetPictureCount: Integer;
function GetPictureArray(
Index: Integer): TPicture;
procedure WritePic(Stream: TStream);
procedure ReadPic(Stream: TStream);
protected
procedure DefineProperties(Filer: TFiler);
override;
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
property PictureCount: Integer
read GetPictureCount;
property PictureArray[
Index: Integer]: TPicture
read GetPictureArray;
published
property Picture: TPicture
read FPicture
write SetPicture;
end;
//....
procedure TPictureList.WritePic(Stream: TStream);
var i: Integer;
bl: Boolean;
procedure Write(pic: TPicture);
begin
pic.SaveToStream(Stream);
end;
begin
i:=Length(FPictureArray);
Stream.
Write(i, sizeof(Integer));
for i:=0
to High(FPictureArray)
do
begin
bl:=FPictureArray[i]<>
nil;
Stream.
Write(bl, sizeof(Boolean));
if bl
then
Write(FPictureArray[i]);
end;
end;
procedure TPictureList.ReadPic(Stream: TStream);
var i: Integer;
bl: Boolean;
procedure Read(pic: TPicture);
begin
pic.LoadFromStream(Stream);
end;
begin
for i:=0
to High(FPictureArray)
do
if FPictureArray[i]<>
nil then
begin
FPictureArray[i].Free;
FPictureArray[i]:=nil;
end;
//
Stream.
Read(i, sizeof(Integer));
SetLength(FPictureArray, i);
for i:=0
to High(FPictureArray)
do
begin
Stream.
Read(bl, sizeof(Boolean));
if bl
then
begin
FPictureArray[i]:=TPicture.Create;
Read(FPictureArray[i]);
end;
end;
end;
procedure TPictureList.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineBinaryProperty('
PictureArray', ReadPic, WritePic, True);
end;