已有代码:
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, UrlMon;type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Button1: TButton;
    Button3: TButton;
    Button2: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}function DownloadFile(Source, Dest: string): Boolean; 
begin
try
Result := UrlDownloadToFile(nil, PChar(source), PChar(Dest), 0, nil) = 0;
except
Result := False;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if DownloadFile('ftp://1.2.3.4/Patch.exe', ExtractFilePath(Application.ExeName)+'Patch.exe') then
begin
button2.Enabled := true;
end
else
ShowMessage('网络通讯出错!');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
if FileExists(ExtractFilePath(Application.ExeName)+'line.exe')
then
DownloadFile('ftp://1.2.3.4/iExp.cfg', ExtractFilePath(Application.ExeName)+'iExp.ini')
else
begin
ShowMessage('请把我放在app的目录下,这个位置不对!');
button1.Enabled :=false
end
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if FileExists(ExtractFilePath(Application.ExeName)+'line.exe') then
begin
winexec ('Patch.exe',1);
close;
end
else
//
end;end.
这个程序能够实现在开始运行的时候就下载iExp.cfg文件到本地改名为iExp.ini然后当Command1Click以后下载另外一个文件下来并且运行,如果下载不下来就报错。有个非常小的问题!procedure TForm1.FormCreate(Sender: TObject);
begin
if FileExists(ExtractFilePath(Application.ExeName)+'line.exe')
then
DownloadFile('ftp://1.2.3.4/iExp.cfg', ExtractFilePath(Application.ExeName)+'iExp.ini')
else
begin
ShowMessage('请把我放在app的目录下,这个位置不对!');
button1.Enabled :=false
end
end;为什么当文件位置不对的时候虽然执行了 ShowMessage('请把我放在app的目录下,这个位置不对!');
但是不往下执行?我其实很想做成岸一个按钮,就能下载两个文件的!但是当begin
if FileExists(ExtractFilePath(Application.ExeName)+'line.exe')
then
DownloadFile('ftp://1.2.3.4/iExp.cfg', ExtractFilePath(Application.ExeName)+'iExp.ini')
DownloadFile('ftp://1.2.3.4/iExp2.cfg', ExtractFilePath(Application.ExeName)+'iExp2.ini')
else
begin
ShowMessage('请把我放在app的目录下,这个位置不对!');
button1.Enabled :=false
end
end;这段代码这样写有什么错?为什么编译器停在第二个DownFile上? 必须写开才行?总归,想实现:
1  启动的时候检查自己的位置正确否,不正确给一个提示就退出(上面的代码给了提示,后面有了END也不退出!!!!!为什么?)2  一个按钮就能实现下载两个文件,并且运行其中的一个文件!就这么简单。100分哦~~

解决方案 »

  1.   

    做2个线程了!那个DownloadFile是需要完成才有返回的http://lysoft.7u7.net
      

  2.   

    好好!!!
    就算那个需要返回我们先不管它了!!这个Delphi的if else 怎么用?!!?!?!?procedure TForm1.DisAgreenClick(Sender: TObject);
    begin
    close;
    end;这样 这个按钮的CLOSE可以关闭程序为什么下面这个if 里面的就不能关???Delphi的if else怎么了?!?!?!?!?!!
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    if FileExists(ExtractFilePath(Application.ExeName)+'line.exe')
    then
    else
    begin
    ShowMessage('请把我放在app的目录下,这个位置不对!');
    close;  // 就是这句!!!为什么不执行它??????????
    end;end;
      

  3.   

    begin
    if FileExists(ExtractFilePath(Application.ExeName)+'line.exe')
    then
    DownloadFile('ftp://1.2.3.4/iExp.cfg', ExtractFilePath(Application.ExeName)+'iExp.ini')
    DownloadFile('ftp://1.2.3.4/iExp2.cfg', ExtractFilePath(Application.ExeName)+'iExp2.ini')
    else
    begin
    ShowMessage('请把我放在app的目录下,这个位置不对!');
    button1.Enabled :=false
    end
    end;if 部分好像缺了 begin end
    =================================
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    if FileExists(ExtractFilePath(Application.ExeName)+'line.exe')
    then
    else
    begin
    ShowMessage('请把我放在app的目录下,这个位置不对!');
    close;  // 就是这句!!!为什么不执行它??????????
    end;
    你试试:  :)
    procedure TForm1.FormCreate(Sender: TObject);
    begin
       close;  
    end;
      

  4.   

    Application.Terminate
    或者
    Halt
      

  5.   

    FormCreate中不能执行Close语句。
    你想想Form创建时能允许销毁吗?
      

  6.   

    对。 FormCreate中不能执行Close语句。
      

  7.   

    OnCreate中不能Close的
    要就
    PostMessage(Handle,WM_Close, 0 , 0);http://lysoft.7u7.net
      

  8.   

    这段代码这样写有什么错?为什么编译器停在第二个DownFile上? 必须写开才行?
    --------------------------------------------------------------------------
    第一个操作出现异常程序就会报错不往下执行了,可以用try....except屏蔽异常
      

  9.   

    FormCreate中用Application.Terminate结束程序