Delphi:“找不到资源”在设计模式中 - 为什么?
我收到一个错误,我不知道为什么会收到它...
所以:我有一个基于 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;
当我从代码中使用它时,它工作得很好。 但是当我注册它并尝试输入表单时,出现错误:
错误 找不到资源scrollpngbutton_ok。 好的
我不明白,因为我输入了 {$R *.res},并且从代码来看这是有效的。 为什么找不到资源?是创建失败了还是怎么的?
好的,我可以使用 Loaded;在设计时设置图像,但在运行时不会调用 Loaded。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用 *.res。这是 IDE 生成的文件,与名称匹配的 DFM/单元相匹配。
创建您自己的资源文件(您可以将其创建为文本文件)并自行编译(或者让 IDE 为您完成,如果您使用的是 Delphi 7 或更高版本)。
在你的来源中:
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).
In your source: