痞
痞子无情
Unregistered / Unconfirmed
GUEST, unregistred user!
unit MainDo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdFTP;
type
TupThread = class(TThread)
private
procedure Upload;
protected
procedure Execute; override;
end;
type
TForm1 = class(TForm)
FTP: TIdFTP;
OpenDialog1: TOpenDialog;
ProgressBar1: TProgressBar;
StatusBar1: TStatusBar;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
GroupBox2: TGroupBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
procedure FTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure FTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure Button3Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
FTP.Host := edit1.Text ;
FTP.Username := edit2.Text ;
FTP.Password := edit3.Text ;
FTP.Connect;
if FTP.Connected then
begin
StatusBar1.SimpleText := '成功连接到服务器,请选择一个文件开始上传...';
Button1.Enabled := false;
Button2.Enabled := true;
end
else
begin
StatusBar1.SimpleText := '连接到服务器失败,请稍后重试...';
Button1.Enabled := true;
Button2.Enabled := false;
end;
end;
procedure TupThread.Execute;
begin
Upload;
end;
procedure TupThread.Upload;
begin
if Form1.FTP.Connected then
begin
if Form1.OpenDialog1.Execute then
begin
Form1.FTP.Put(Form1.OpenDialog1.FileName, ExtractFileName(Form1.OpenDialog1.FileName)) ;
form1.Button2.Enabled := false ;
end
else
showmessage('出现未知错误,请重新启动程序。');
end
else
begin
showmessage('尚未连接到服务器,请先连接。');
Form1.Button1.Enabled := true;
Form1.Button2.Enabled := false;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
T:TThread;
begin
StatusBar1.SimpleText := '选择文件';
T:=TupThread.Create(false);
end;
procedure TForm1.FTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
ProgressBar1.Position := AWorkCount;
StatusBar1.SimpleText := '正在上传中......';
end;
procedure TForm1.FTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
ProgressBar1.Max := AWorkCountMax;
ProgressBar1.Position := 0;
StatusBar1.SimpleText := '开始上传';
end;
procedure TForm1.FTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Position := ProgressBar1.Max;
StatusBar1.SimpleText := '成功上传!';
showmessage ('上传完功!') ; //此处不正常,不能正常运行此语句
form1.Button2.Enabled := true ; //此处不正常,不能正常运行此语句
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Application.Terminate ;
end;
end.
////
{
FTPWorkEnd 这个过程有不能正常运行的语句,请大家在我解决一下,谢谢.
}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdFTP;
type
TupThread = class(TThread)
private
procedure Upload;
protected
procedure Execute; override;
end;
type
TForm1 = class(TForm)
FTP: TIdFTP;
OpenDialog1: TOpenDialog;
ProgressBar1: TProgressBar;
StatusBar1: TStatusBar;
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
GroupBox2: TGroupBox;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
procedure FTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure FTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure Button3Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
FTP.Host := edit1.Text ;
FTP.Username := edit2.Text ;
FTP.Password := edit3.Text ;
FTP.Connect;
if FTP.Connected then
begin
StatusBar1.SimpleText := '成功连接到服务器,请选择一个文件开始上传...';
Button1.Enabled := false;
Button2.Enabled := true;
end
else
begin
StatusBar1.SimpleText := '连接到服务器失败,请稍后重试...';
Button1.Enabled := true;
Button2.Enabled := false;
end;
end;
procedure TupThread.Execute;
begin
Upload;
end;
procedure TupThread.Upload;
begin
if Form1.FTP.Connected then
begin
if Form1.OpenDialog1.Execute then
begin
Form1.FTP.Put(Form1.OpenDialog1.FileName, ExtractFileName(Form1.OpenDialog1.FileName)) ;
form1.Button2.Enabled := false ;
end
else
showmessage('出现未知错误,请重新启动程序。');
end
else
begin
showmessage('尚未连接到服务器,请先连接。');
Form1.Button1.Enabled := true;
Form1.Button2.Enabled := false;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
T:TThread;
begin
StatusBar1.SimpleText := '选择文件';
T:=TupThread.Create(false);
end;
procedure TForm1.FTPWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
ProgressBar1.Position := AWorkCount;
StatusBar1.SimpleText := '正在上传中......';
end;
procedure TForm1.FTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
ProgressBar1.Max := AWorkCountMax;
ProgressBar1.Position := 0;
StatusBar1.SimpleText := '开始上传';
end;
procedure TForm1.FTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Position := ProgressBar1.Max;
StatusBar1.SimpleText := '成功上传!';
showmessage ('上传完功!') ; //此处不正常,不能正常运行此语句
form1.Button2.Enabled := true ; //此处不正常,不能正常运行此语句
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Application.Terminate ;
end;
end.
////
{
FTPWorkEnd 这个过程有不能正常运行的语句,请大家在我解决一下,谢谢.
}