Nagut, hier noch der Rest: Ich verwende eine globale Variable, STOP, bitte nicht hauen, das ist auch die einzige in allen 10 Units und einfach schnell und unkompliziert
.
Delphi-Quellcode:
type
TBitmapCollection = class
private
FBitmapList: TObjectList;
FNameList: TStringList;
function GetBitmap(AName: string): TBitmap32;
procedure LoadGraphicRessources;
public
constructor Create;
destructor Destroy; override;
procedure Add(ABit: TBitmap32; AName: string);
function AddNew(AName: string): TBitmap32;
property Bitmap[AName: string]: TBitmap32 read GetBitmap; default;
end;
var
BitmapCollection: TBitmapCollection;
implementation
{ TBitmapCollection }
function TBitmapCollection.GetBitmap(AName: string): TBitmap32;
begin
Result := TBitmap32(FBitmapList.Items[FNameList.IndexOf(AName)]);
end;
procedure TBitmapCollection.Add(ABit: TBitmap32; AName: string);
begin
FBitmapList.Add(ABit);
FNameList.Add(AName);
end;
function TBitmapCollection.AddNew(AName: string): TBitmap32;
begin
Result := TBitmap32.Create;
Add(Result, AName);
end;
destructor TBitmapCollection.Destroy;
begin
FBitmapList.Free;
FNameList.Free;
inherited;
end;
constructor TBitmapCollection.Create;
begin
inherited;
FBitmapList := TObjectList.Create;
FNameList := TStringList.Create;
LoadGraphicRessources;
end;
procedure TBitmapCollection.LoadGraphicRessources;
var
Stream: TFileStream;
Alpha: Boolean;
begin
try
Stream := TFileStream.Create('Graphics.prr', fmOpenRead);
LoadPNGintoBitmap32(AddNew('Hugo'), Stream, Alpha);
LoadPNGintoBitmap32(AddNew('Helmut'), Stream, Alpha);
LoadPNGintoBitmap32(AddNew('Hannes'), Stream, Alpha);
LoadPNGintoBitmap32(AddNew('Hannah'), Stream, Alpha);
finally
Stream.Free;
end;
end;
initialization
BitmapCollection := TBitmapCollection.Create;
finalization
BitmapCollection.Free;
end.