Hallo!
Ich bin verzweifelt: ich gerade eine eigene Komponente, die unter Anderem aus mehreren TImage besteht. Dabei habe ich das Problem, dass die bei designtime gesetzte Grafiken zur Laufzeit nicht angezeigt werden. Hier ein Beispiel, wie ich es mache?
Delphi-Quellcode:
type
TTestControl = class(TPanel)
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
private
FButtonNormal: TImage;
FButtonHot: TImage;
FPictureNormal: TPicture;
FPictureHot: TPicture;
procedure SetPictureNormal(APicture: TPicture);
procedure SetPictureHot(APicture: TPicture);
published
property PictureNormal: TPicture read FPictureNormal write SetPictureNormal;
property PictureHot: TPicture read FPictureHot write SetPictureHot;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('TestControls', [TTestControl]);
end;
constructor TTestControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 150;
Height := 150;
FButtonNormal := TImage.Create(Self);
FButtonNormal.Parent := Self;
FButtonNormal.Top := 20;
FButtonNormal.Left := 20;
FButtonNormal.Width := 50;
FButtonNormal.Height := 50;
FButtonHot := TImage.Create(Self);
FButtonHot.Parent := Self;
FButtonHot.Top := 20;
FButtonHot.Left := 50;
FButtonHot.Width := 50;
FButtonHot.Height := 50;
FPictureNormal := TPicture.Create;
FPictureHot := TPicture.Create;
end;
destructor TTestControl.Destroy;
begin
if Assigned(FPictureHot) then FreeAndNil(FPictureHot);
if Assigned(FPictureNormal) then FreeAndNil(FPictureNormal);
if Assigned(FButtonHot) then FreeAndNil(FButtonHot);
if Assigned(FButtonNormal) then FreeAndNil(FButtonNormal);
inherited Destroy;
end;
procedure TTestControl.SetPictureNormal(APicture: TPicture);
begin
FPictureNormal.Assign(APicture);
FButtonNormal.Picture := FPictureNormal;
end;
procedure TTestControl.SetPictureHot(APicture: TPicture);
begin
FPictureHot.Assign(APicture);
FButtonHot.Picture := FPictureHot;
end;
Was mache ich falsch?