3
votes

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.

1
What is a TsAlphaButton? Google doesn't know of it.Andreas Rejbrand
IN which file did you have that $R directive?jachguate
An AlphaSkin component. Now I found the source of the error, they are uses hInstance, what is not equal my hInstance. I corrected their code. Thanks for your help! dddurumdara

1 Answers

11
votes

You can't use *.res. That is the file generated by the IDE that matches the DFM/unit it's name matches.

Create your own resource file (you can create it as a text file) and compile it yourself (or have the IDE do it for you, if you're using Delphi 7 or higher).

/* YourResources.rc */
SCROLLPNGBUTTON  BITMAP MyBitmap.bmp

In your source:

{$R YourResources.res YourResources.rc}  // The IDE will compile .rc to make .res