I got an error, and I don't know why I got it...
So: I have a new component, based on sAlphaButton. This have ImageList property, and my component extend this button with my own captions/images, translated to hungarian.
I used LoadRes to get the predefined images.
See this:
procedure TScrollPNGButton.LoadAsImageListFromRes(ResNames : TStrings; IL : TsAlphaImageList);
var
s : string;
i : integer;
begin
IL.CLear;
for i := 0 to ResNames.Count - 1 do begin
s := ResNames[i];
AddImageFromRes(hInstance, IL, s, ifPNG);
end;
end;
procedure TScrollPNGButton.LoadResToImageList;
var
sl : TStringList;
begin
sl := TStringList.Create;
try
sl.Text :=
Trim(
'scrollpngbutton_ok'#13 +
'scrollpngbutton_cancel'#13 +
'scrollpngbutton_close'#13 +
'scrollpngbutton_yes'#13 +
'scrollpngbutton_no'#13 +
'scrollpngbutton_refresh'#13 +
'scrollpngbutton_print'#13 +
'scrollpngbutton_email'#13 +
'scrollpngbutton_add'#13 +
'scrollpngbutton_delete'#13 +
'scrollpngbutton_edit'#13 +
''
);
LoadAsImageListFromRes(sl, FImgs);
finally
sl.Free;
end;
end;
constructor TScrollPNGButton.Create(aOwner : TComponent);
begin
inherited Create(aOwner);
FImgs := TsAlphaImageList.Create(nil);
inherited Images := FImgs;
LoadResToImageList;
end;
It is working good when I use it from code. But when I registered it, and I try to put into a form, I got error:
Error Resource scrollpngbutton_ok not found. OK
I don't understand it, because I put the {$R *.res}, and from code this is working. Why the Resource not found? Is creation failed, or what?
Ok, I can use Loaded; to set the images in design time, but Loaded is not called in runtime.
TsAlphaButton
? Google doesn't know of it. – Andreas Rejbrand