IdFtp线程中上传,有些关于界面方面的问题,附全部代码,请朋友们来帮我看看(20分)

  • 主题发起人 主题发起人 痞子无情
  • 开始时间 开始时间

痞子无情

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 这个过程有不能正常运行的语句,请大家在我解决一下,谢谢.
}
 
procedure TForm1.FTPWorkEnd();
 
顶呀,来者,全是偶的朋友.....多谢谢了.
 
没有条件测试,只能看一下。
估计是 没有使用同步的缘故。
 
有用到VCL,必须用synchronize(Upload)
 
有用到VCL,必须用synchronize(Upload)
这句要如何用呢?
 
有用到VCL,必须用synchronize(Upload)
这句要如何用呢?

哪位朋友帮我。
 
不会是没有人喜欢我吧?不会是没有人喜欢我吧?
 
的确没人喜欢你.用不了每句话都说几次

把这个
procedure TupThread.Execute;
begin
Upload;
end;

改成
procedure TupThread.Execute;
begin
synchronize(Upload);
end;

upLoad 里最好不要用ShowMessage
 
QSmile 你的说法也没有能解决问题

这是我现在解决的:
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
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 Button3Click(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);
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 TForm1.Button2Click(Sender: TObject);
var
T:TThread;
begin
StatusBar1.SimpleText := '选择文件';
T:=TupThread.Create(false);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Application.Terminate ;
end;

procedure TupThread.Execute;
begin
if Form1.FTP.Connected then
begin
if Form1.OpenDialog1.Execute then
begin
form1.Button2.Enabled := false ;
Form1.FTP.Put(Form1.OpenDialog1.FileName, ExtractFileName(Form1.OpenDialog1.FileName)) ;
end
else
showmessage('出现未知错误,请重新启动程序。');
end
else
begin
showmessage('尚未连接到服务器,请先连接。');
Form1.Button1.Enabled := true;
Form1.Button2.Enabled := false;
end;
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 := '成功上传!';
form1.Button2.Enabled := true ;
//showmessage ('成功上传!') ;
end;

end.

按妞已经正常,只是showmessage ('成功上传!') ; 这句无法正常运行,且退出后出错.
还请大家解决这个问题.
 
后退
顶部