3
336764
Unregistered / Unconfirmed
GUEST, unregistred user!
请问:在Upload中,FTP.connect之后打开文件对话窗就无法跳出,[blue]如果把打开文件放前边,就能[/blue],请问为什么???下
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
IdFTP, ComCtrls;
type
TDemo1Thread = class(TThread)
private
Uspeed : Integer;
FTP: TIdFTP;
protected
procedure Execute;
override;
public
procedure Upload;
end;
type
TForm1 = class(TForm)
Button1: TButton;
FTP: TIdFTP;
OpenDialog: TOpenDialog;
IdAntiFreeze1: TIdAntiFreeze;
ListBox: TListBox;
ProgressBar: TProgressBar;
StatusBar: TStatusBar;
procedure FTPWorkEnd(ASender: TObject;
AWorkMode: TWorkMode);
procedure FTPWork(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCount: Integer);
procedure FTPWorkbegin
(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCountMax: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
t : TDemo1Thread;
implementation
{$R *.dfm}
procedure TDemo1Thread.Execute;
begin
Synchronize(Upload);
end;
[red]procedure TDemo1Thread.Upload;
begin
Form1.Caption := '请选择要上传的文件';
if FTP.Connected then
begin
Form1.StatusBar.SimpleText := '已经成功连接到服务器...';
if Form1.OpenDialog.Execute then
begin
FTP.Put(Form1.OpenDialog.FileName, ExtractFileName(Form1.OpenDialog.FileName));
end;
end
else
begin
Form1.StatusBar.SimpleText := '正在连接到服务器...';
FTP.Host := 'localhost';
[green]//已经有FTP SERVER 启动[/green]
FTP.Username := 'upload';
FTP.Password := 'upload';
try
FTP.Connect;
except
showMessage('连接到服务器出错。');
end;
Form1.StatusBar.SimpleText := '成功连接,请选择文件上传。';
if Form1.OpenDialog.Execute then
begin
FTP.Put(Form1.OpenDialog.FileName, ExtractFileName(Form1.OpenDialog.FileName));
end;
end;
end;
[/red]
procedure TForm1.Button1Click(Sender: TObject);
begin
t := TDemo1Thread.Create( false );
end;
[brown]procedure TForm1.FTPWorkbegin
(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCountMax: Integer);
begin
ProgressBar.Max := AWorkCountMax;
ProgressBar.Position := 0;
ProgressBar.Visible := true;
end;
procedure TForm1.FTPWork(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCount: Integer);
begin
ProgressBar.Position := AWorkCount;
ListBox.Items.AddObject('正在传送数据', Pointer(clBlack));
ListBox.ItemIndex := ListBox.Items.Count-1;
end;
procedure TForm1.FTPWorkEnd(ASender: TObject;
AWorkMode: TWorkMode);
begin
ProgressBar.Position := ProgressBar.Max;
end;
[/brown]
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase,
IdFTP, ComCtrls;
type
TDemo1Thread = class(TThread)
private
Uspeed : Integer;
FTP: TIdFTP;
protected
procedure Execute;
override;
public
procedure Upload;
end;
type
TForm1 = class(TForm)
Button1: TButton;
FTP: TIdFTP;
OpenDialog: TOpenDialog;
IdAntiFreeze1: TIdAntiFreeze;
ListBox: TListBox;
ProgressBar: TProgressBar;
StatusBar: TStatusBar;
procedure FTPWorkEnd(ASender: TObject;
AWorkMode: TWorkMode);
procedure FTPWork(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCount: Integer);
procedure FTPWorkbegin
(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCountMax: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
t : TDemo1Thread;
implementation
{$R *.dfm}
procedure TDemo1Thread.Execute;
begin
Synchronize(Upload);
end;
[red]procedure TDemo1Thread.Upload;
begin
Form1.Caption := '请选择要上传的文件';
if FTP.Connected then
begin
Form1.StatusBar.SimpleText := '已经成功连接到服务器...';
if Form1.OpenDialog.Execute then
begin
FTP.Put(Form1.OpenDialog.FileName, ExtractFileName(Form1.OpenDialog.FileName));
end;
end
else
begin
Form1.StatusBar.SimpleText := '正在连接到服务器...';
FTP.Host := 'localhost';
[green]//已经有FTP SERVER 启动[/green]
FTP.Username := 'upload';
FTP.Password := 'upload';
try
FTP.Connect;
except
showMessage('连接到服务器出错。');
end;
Form1.StatusBar.SimpleText := '成功连接,请选择文件上传。';
if Form1.OpenDialog.Execute then
begin
FTP.Put(Form1.OpenDialog.FileName, ExtractFileName(Form1.OpenDialog.FileName));
end;
end;
end;
[/red]
procedure TForm1.Button1Click(Sender: TObject);
begin
t := TDemo1Thread.Create( false );
end;
[brown]procedure TForm1.FTPWorkbegin
(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCountMax: Integer);
begin
ProgressBar.Max := AWorkCountMax;
ProgressBar.Position := 0;
ProgressBar.Visible := true;
end;
procedure TForm1.FTPWork(ASender: TObject;
AWorkMode: TWorkMode;
AWorkCount: Integer);
begin
ProgressBar.Position := AWorkCount;
ListBox.Items.AddObject('正在传送数据', Pointer(clBlack));
ListBox.ItemIndex := ListBox.Items.Count-1;
end;
procedure TForm1.FTPWorkEnd(ASender: TObject;
AWorkMode: TWorkMode);
begin
ProgressBar.Position := ProgressBar.Max;
end;
[/brown]
end.