unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdHTTP, StdCtrls;type
  TForm1 = class(TForm)
    edt1: TEdit;
    edt2: TEdit;
    btn1: TButton;
    idhtp1: TIdHTTP;
    procedure FormCreate(Sender: TObject);
    procedure Down(url,save:string);
    procedure btn1Click(Sender: TObject);  private
    { Private declarations }
  public
    { Public declarations }  end;var
  Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
var
url,save:string;
begin
url:=edt1.Text;
save:=edt2.Text;
BeginThread(nil,0,@Form1.Down(url,save),nil,0,nil)
end;procedure TForm1.Down(url,save:string);
var
MyStream:TMemoryStream;
begin
MyStream:=TMemoryStream.Create;
idhtp1.Get(url,MyStream);
MyStream.SaveToFile(save);
MyStream.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
edt1.Text:='http://down.sandai.net/mini/ThunderMiniInstall.exe';
edt2.Text:='D:\test.exe';
end;end.报错信息:
Compiling Project1.dproj (Debug configuration)
[DCC Error] Unit1.pas(39): E2036 Variable required
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
Failed

解决方案 »

  1.   

    试试:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
      IdHTTP, StdCtrls;type
      TForm1 = class(TForm)
      edt1: TEdit;
      edt2: TEdit;
      btn1: TButton;
      idhtp1: TIdHTTP;
      procedure FormCreate(Sender: TObject);
      procedure btn1Click(Sender: TObject);
      private
      { Private declarations }
      public
      { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}function Down(p: pointer): boolean; stdcall;
    var
      MyStream:TMemoryStream;
    begin
      MyStream:=TMemoryStream.Create;
      Form1.idhtp1.Get(edt1.Text,MyStream);
      MyStream.SaveToFile(Form1.edt2.Text);
      MyStream.Free;
      Result:= true;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      edt1.Text:='http://down.sandai.net/mini/ThunderMiniInstall.exe';
      edt2.Text:='D:\test.exe';
    end;procedure TForm1.btn1Click(Sender: TObject);
    begin
      BeginThread(nil,0,@Down,nil,0,nil)
    end;end.
      

  2.   

    BeginThread的第三个参数指向的函数只能带一个指针参数,且调用BeginThread时第三个参数只能是函数指针,此时不能BeginThread(nil,0,@Form1.Down(url,save),nil,0,nil),只能BeginThread(nil,0,@函数名,参数指针,nil,0,nil)