gpt4 book ai didi

Delphi:设计模式下为 "Resource not found"- 为什么?

转载 作者:行者123 更新时间:2023-12-03 15:41:16 25 4
gpt4 key购买 nike

我遇到了一个错误,但我不知道为什么会出现这个错误...

所以:我有一个基于 sAlphaButton 的新组件。它有 ImageList 属性,我的组件用我自己的标题/图像扩展了这个按钮,翻译成匈牙利语。

我使用 LoadRes 来获取预定义的图像。

看这个:

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;

当我从代码中使用它时,它运行良好。但是当我注册它并尝试输入表单时,出现错误:

Error Resource scrollpngbutton_ok not found. OK

我不明白,因为我放置了 {$R *.res},并且从代码来看这是有效的。为什么找不到资源?是创建失败还是什么?

好的,我可以使用Loaded;在设计时设置图像,但在运行时不会调用 Loaded。

最佳答案

您不能使用 *.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

关于Delphi:设计模式下为 "Resource not found"- 为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5170354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com