Resource可以是任意文件(图像、声音、office都可以),直接打包到编译的exe文件中,调用也非常方便
打开一个新的或已有的delphi工程
1.先在 Project->resources..添加一个图片,并更改名字为myfirst,类型为RT_RCDATA
2.在窗体上方一个image和button
3.button代码如下
procedure TForm2.Button1Click(Sender: TObject);
var
rs: TResourceStream;
jp: TJPEGImage;
begin
rs := TResourceStream.Create(HInstance, 'myfirst', RT_RCDATA);
try
jp := TJPEGImage.Create;
try
jp.LoadFromStream(rs);
Image1.Picture.Graphic := jp;
finally
jp.Free;
end;
finally
rs.Free;
end;
end;