Delphi: "Resource not found" in design mode - why?

I have a mistake and I don’t know why I got it ...

So: I have a new component based on sAlphaButton. This has an ImageList property, and my component extends this button with its own Hungarian captions / images.

I used LoadRes to get predefined images.

Watch 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 works well when I use it from code. But when I registered it and I try to enter a form, I got an error:

Error Resource scrollpngbutton_ok not found. Ok

I don’t understand this, because I put {$ R * .res}, and from the code it works. Why is the resource not found? Failed to create creation or what?

, Loaded; , Loaded .

+3
1

*.res. , IDE, DFM/, .

( ) ( IDE , Delphi 7 ).

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

:

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

Source: https://habr.com/ru/post/1795775/


All Articles