- UID
- 31191
注册时间2007-5-1
阅读权限20
最后登录1970-1-1
以武会友
TA的每日心情 | 开心 2024-6-9 16:20 |
---|
签到天数: 24 天 [LV.4]偶尔看看III
|
玩世不恭
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,inifiles,shellapi;
type
TForm1 = class(TForm)
Button1: TButton;
Button3: TButton;
Button4: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
public
function Cjt_AddtoFile(SourceFile,TargetFile:string):Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.Cjt_AddtoFile(SourceFile,TargetFile:string):Boolean;
var
Target,Source:TFileStream;
MyFileSize:integer;
begin
try
Source:=TFileStream.Create(SourceFile,fmOpenRead or fmShareExclusive);
Target:=TFileStream.Create(TargetFile,fmOpenWrite or fmShareExclusive);
TRY
Target.Seek(0,soFromEnd);//往尾部添加资源
Target.CopyFrom(Source,0);
MyFileSize:=Source.Size+Sizeof(MyFileSize);//计算资源大小,并写入辅程尾部
Target.WriteBuffer(MyFileSize,sizeof(MyFileSize));
finally
Target.Free;
Source.Free;
end;
except
Result:=False;
Exit;
end;
Result:=True;
end;
Function Cjt_LoadFromFile(SourceFile,TargetFile :string):Boolean;
var
Source:TFileStream;
Target:TMemoryStream;
MyFileSize:integer;
begin
try
Target:=TMemoryStream.Create;
Source:=TFileStream.Create(SourceFile,fmOpenRead or fmShareDenyNone);
try
Source.Seek(-sizeof(MyFileSize),soFromEnd);
Source.ReadBuffer(MyFileSize,sizeof(MyFileSize));//读出资源大小
Source.Seek(-MyFileSize,soFromEnd);//定位到资源位置
Target.CopyFrom(Source,MyFileSize-sizeof(MyFileSize));//取出资源
Target.SaveToFile(TargetFile);//存放到文件
finally
Target.Free;
Source.Free;
end;
except
Result:=false;
Exit;
end;
Result:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Cjt_AddtoFile('F:\8.exe','F:\31.exe');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Cjt_LoadFromFile('F:\ctk\31.exe','F:\ctk\ZXC.EXE');
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
// ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
ShellExecute(handle, 'open', 'F:\CTK\zxc.exe', '', '', SW_SHOWNORMAL);
end;
end. |
|