多个资源文件释放的问题
2009-02-03 09:47
204 查看
多个资源文件释放的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061113192259243.html
已经做好了一个资源文件,里面包含有若干二进制文件,我有TResourceStream来实现资源的释放,问题就在这里,我现在用的格式是
if FileExists('C:\a.exe') then
begin
rs:=TResourceStream.Create(HInstance,'a.exe','exefile');
rs.SaveToFile('C:\a.exe');
rs.Free;
end;
if FileExists('C:\b.exe') then
begin
rs:=TResourceStream.Create(HInstance,'b.exe','exefile');
rs.SaveToFile('C:\b.exe');
rs.Free;
end;
if FileExists('C:\c.exe') then
begin
rs:=TResourceStream.Create(HInstance,'c.exe','exefile');
rs.SaveToFile('C:\c.exe');
rs.Free;
end;
总感觉不是很好,每次都要构造新的对象,能不能在原来对象的基础上继续读资源的方法?
上面的判断语句统一加上not,刚才忘记写了
把公用的部分写成一个函数
procedure ExportResToFile(const ResName, ResType, FileName: string);
var
Res: TResourceStream;
begin
if not FileExists(FileName) then
begin
Res:= TResourceStream.Create(HInstance, ResName, PChar(ResType));
try
Res.SaveToFile(FileName); //将资源保存为文件,即还原文件
finally
Res.Free;
end;
end;
end;
http://www.delphi2007.net/DelphiAPI/html/delphi_20061113192259243.html
已经做好了一个资源文件,里面包含有若干二进制文件,我有TResourceStream来实现资源的释放,问题就在这里,我现在用的格式是
if FileExists('C:\a.exe') then
begin
rs:=TResourceStream.Create(HInstance,'a.exe','exefile');
rs.SaveToFile('C:\a.exe');
rs.Free;
end;
if FileExists('C:\b.exe') then
begin
rs:=TResourceStream.Create(HInstance,'b.exe','exefile');
rs.SaveToFile('C:\b.exe');
rs.Free;
end;
if FileExists('C:\c.exe') then
begin
rs:=TResourceStream.Create(HInstance,'c.exe','exefile');
rs.SaveToFile('C:\c.exe');
rs.Free;
end;
总感觉不是很好,每次都要构造新的对象,能不能在原来对象的基础上继续读资源的方法?
上面的判断语句统一加上not,刚才忘记写了
把公用的部分写成一个函数
procedure ExportResToFile(const ResName, ResType, FileName: string);
var
Res: TResourceStream;
begin
if not FileExists(FileName) then
begin
Res:= TResourceStream.Create(HInstance, ResName, PChar(ResType));
try
Res.SaveToFile(FileName); //将资源保存为文件,即还原文件
finally
Res.Free;
end;
end;
end;
相关文章推荐
- 调用Excel导出文件的两种方式,主要解决了资源释放的问题。
- "资源托管"及"非托管资源"问题 --- 创建MDB文件时如何释放LDB为例
- 说说jQuery easyUI的那些事之一——资源文件(css\js)加载问题
- Android 资源文件的命名规范问题
- Android将Activity打成jar包供第三方调用(解决资源文件不能打包的问题)
- 刚注册,问个问题,在asp.net里有个xml文档以MemoryStream存在资源文件中,现在我如何把他读出来,还原成xml文档。
- Android将Activity打成jar包供第三方调用(解决资源文件不能打包的问题)
- web工程在eclipse中的类编译路径与发布后的类编译路径问题和web工程中的资源文件读写问题
- Infragistics NetAdvantage 控件资源释放问题的实际经验
- sivlerlight绑定资源Resx文件里的字符串问题
- Spring MVC程序中怎么得到静态资源文件css,js,图片文件的路径问题
- linux删除文件未释放空间问题处理
- Linux中删除文件,磁盘空间未释放问题追踪
- linux频繁存取文件内存不释放问题
- 释放资源中某类型的文件
- as3 Loader 加载资源后内存泄露无法释放的问题。
- web服务端访问xml资源文件的路径问题
- 解决duilib使用zip换肤卡顿的问题:修改duilib并使用资源文件换肤
- 浅谈C#托管程序中的资源释放问题(摘自网络)
- 浅谈C#托管程序中的资源释放问题