我的流程序错误! (20分)

  • 主题发起人 主题发起人 qbtxx
  • 开始时间 开始时间
Q

qbtxx

Unregistered / Unconfirmed
GUEST, unregistred user!
unit TUPIA;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtDlgs;

type
TForm1 = class(TForm)
Edit1: TEdit;
OpenPictureDialog1: TOpenPictureDialog;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
Function ExtractRes(ResType, ResName, ResNewName : String):boolean;
Function qbt_AddtoFile(SourceFile,TargetFile:string):Boolean;
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.dfm}
{$R EROSX.RES}

Function TForm1.ExtractRes(ResType, ResName, ResNewName : String):boolean;
var
Res : TResourceStream;
begin

try
Res := TResourceStream.Create(Hinstance, Resname, Pchar(ResType));
try
Res.SavetoFile(ResNewName);
Result:=true;
finally
Res.Free;
end;

except
Result:=false;
end;

end;


Function TForm1.qbt_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;


procedure TForm1.FormCreate(Sender: TObject);
begin

form1.Caption:='Bmp2Exe演示程序';
Edit1.Text:='';
OpenPictureDialog1.DefaultExt := GraphicExtension(TBitmap);
OpenPictureDialog1.Filter := GraphicFilter(TBitmap);
Button1.Caption:='选择BMP图片';
Button2.Caption:='生成EXE';
end;


procedure TForm1.Button1Click(Sender: TObject);
begin

if OpenPictureDialog1.Execute then

Edit1.Text:=OpenPictureDialog1.FileName;
end;


procedure TForm1.Button2Click(Sender: TObject);
var
HeadTemp:String;
begin

if FileExistS(Edit1.Text) then

begin

Application.MessageBox('BMP图片文件不存在,请重新选择!','信息',MB_ICONINFORMATION+MB_OK);
Exit;
end;

HeadTemp:=ChangeFileExt(Edit1.Text,'.exe');
if ExtractRes('exefile','EROSX',HeadTemp) then

if qbt_AddtoFile(Edit1.Text,HeadTemp) then

Application.MessageBox('EXE文件生成成功!','信息',MB_ICONINFORMATION+MB_OK)
else

begin

if FileExists(HeadTemp) then
DeleteFile(HeadTemp);
Application.MessageBox('EXE文件生成失败!','信息',MB_ICONINFORMATION+MB_OK)
end;

end;


end.


个位DFW大哥请帮帮小弟看看上面这个流程序出现了什么错误!
为什么我选中了BMP图片可还是出现了[BMP图片文件不存在,请重新选择!]为什么???
 
这样的问题.用不着重复提.
 
if FileExistS(Edit1.Text) then
//此句错了。这意思是说,假如文件存在,那么就提示文件不存在。当然不对了。前面加个not
begin

Application.MessageBox('BMP图片文件不存在,请重新选择!','信息',MB_ICONINFORMATION+MB_OK);
Exit;
end;

 
晕~~~整理一下首尾再帖出来嘛~~~~~~
 
谢谢了!小弟最近心情有点烦燥没有看清楚所以就出现了。。。 。。。
 
后退
顶部