type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
public
sunny, cloudy: TImage;
procedure CreateImages;
function IconVisibleSetOK(const aImageName: String; isVisable: Boolean): Boolean;
procedure ShowSunWithNoClouds;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.CreateImages;
begin
cloudy := TImage.Create(Self);
cloudy.Name := 'cloudy';
//cloudy.Picture.Icon.LoadFromFile(...);
sunny := TImage.Create(Self);
sunny.Name := 'sunny';
//sunny.Picture.Icon.LoadFromFile(...);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CreateImages;
ShowSunWithNoClouds;
end;
function TForm1.IconVisibleSetOK(const aImageName: String; isVisable: Boolean): Boolean;
var
cmp: TComponent;
begin
cmp := FindComponent(aImageName);
Result := Assigned(cmp) and (cmp is TImage);
if Result then
TImage(cmp).Visible := isVisible;
end;
procedure TForm1.ShowSunWithNoClouds;
begin
Assert(IconVisibleSetOK('sunny', True), 'missing sunny icon!');
Assert(IconVisibleSetOK('cloudy', False), 'missing cloudy icon!');
end;