Window下的例子动态生成EXE文件代码

| 1 Comment | No TrackBacks

Window下的例子动态生成EXE文件代码
1。创建文件1:
procedure TForm1.FormCreate(Sender: TObject);
var Stream1:TFileStream;
Buff:Array[1..65536] of char;
Size,Offset,I:Integer;
begin
Offset:=189440;//文件的长度
Stream1:=TFileStream.Create(Application.ExeName,fmShareDenyWrite);//共享读打开
Size := Stream1.Size;
Stream1.Seek(Offset,soFromBeginning);
Stream1.Read(Buff,Size-OffSet);//读入到Buff中
Stream1.Free;
Memo1.Text:='';
for i:=1 to (Size-Offset) do
Memo1.Text:=Memo1.Text+Buff[i];
end;
2。创建文件2,连接文件1与文本。
procedure TForm1.Button1Click(Sender: TObject);
var Stream1:TMemoryStream;
Buff:Array[1..65536] of char;
I,Size:Integer;
begin
Stream1:=TMemoryStream.Create;
Stream1.LoadFromFile('Linkprj1.exe');//读入文件1
Size:=Stream1.Size;
Stream1.SetSize(Stream1.Size+Memo1.GetTextLen);//长度为两者相加。
Stream1.Seek(Size,soFromBeginning);
for i:=1 to Memo1.GetTextLen do
Buff[i]:=Memo1.Text[i];
Stream1.Write(Buff,Memo1.GetTextLen);
Stream1.SaveToFile('link.exe');//写入文件
Stream1.Free;
end;

No TrackBacks

TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/606

1 Comment

谢谢,这个办法不错,帮了我不少忙。

Leave a comment

About this Entry

This page contains a single entry by kevinwu published on April 17, 2006 2:56 PM.

把wav文件编译到可执行文件中 was the previous entry in this blog.

保存DELPHI设置 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.