S
shyj
Unregistered / Unconfirmed
GUEST, unregistred user!
问题提出的原因:
SakMail组件的Pop以及SMTP示例中,进行收发信时存在问题。
procedure TForm1.CntClick(Sender: TObject);
begin
SakPOP1.Host := EditHost.text;
SakPOP1.UserId := EditUserId.text;
SakPOP1.UserPasswd := EditPasswd.text;
Application.ProcessMessages;
SakPOP1.connect;
//////////////////////////////////////////////////////////////
//进行Socket连接时,程序不能响应其他消息如Form移动等,
//加上 Application.ProcessMessages也不行
/////////////////////////////////////////////////////////////
...
...
end;
问题要求:进行Socket连接时,程序能响应其他消息如Form移动等
我的方法是使用线程。代码如下:
type
ThreadPop = class(TThread)
private
...
procedure FGetNewMail();
protected
procedure Execute; override;
published
constructor CreateIt(PriorityLevel: cardinal; ProgBar : TProgressBar; SakMsgList1:
TSakMsgList;SakPOP1: TSakPOP;shost:string;suserid:string;spassword :string);
destructor Destroy; override;
end;
procedure ThreadPop.Execute;
begin
while (Terminated = false) do
Synchronize(FGetNewMail);
end;
constructor ThreadPop.CreateIt(PriorityLevel: cardinal; ProgBar : TProgressBar;
SakMsgList1: TSakMsgList;SakPOP1: TSakPOP;shost:string;suserid:string;spassword :string);
begin
inherited Create(true); // Create thread suspended
Priority := TThreadPriority(PriorityLevel); // Set Priority Level
FreeOnTerminate := true; // Thread Free Itself when terminated
FSakMsgList1:= SakMsgList1;
FSakPOP1:= SakPOP1;
FHost:=shost;
FUserID:=suserid;
FPassword:=spassword;
Suspended := false; // Continue the thread
end;
procedure ThreadPop.FGetNewMail();
begin
FSakPOP1.Host := FHost;
FSakPOP1.UserId := FUserID;
FSakPOP1.UserPasswd := FPassword;
FSakPOP1.connect;
//???????????????? 这时倒是可以进行其他操作了,可是不进行Socket连接了。
if FSakPOP1.POPError then
begin
MessageDlg( 'Connect failed. Maybe the server is down or not responding.',
mtError, [mbOk], 0);
exit;
end;
if not FSakPOP1.login then
begin
ShowMessage('Unauthorized access...');
exit;
end;
FSakPOP1.Init;
showMessage( 'You have ' + intToStr( FSakPOP1.NewMsgsCount) + ' new msg(s) of ' +
intToStr( FSakPOP1.MsgsCount));
FsakPOP1.retrieveAllMessages( FSakMsgList1);
FSakPOP1.quit;
end;
请教各位,如何在线程中利用SakMail类似组件进行Pop3取信,
同时如何在线程中响应SakPop或其他VCL组件的各种事件。出分300,
求成功的例子或解决问题的思路.如果太长可以发到shyjun@china.com
SakMail组件的Pop以及SMTP示例中,进行收发信时存在问题。
procedure TForm1.CntClick(Sender: TObject);
begin
SakPOP1.Host := EditHost.text;
SakPOP1.UserId := EditUserId.text;
SakPOP1.UserPasswd := EditPasswd.text;
Application.ProcessMessages;
SakPOP1.connect;
//////////////////////////////////////////////////////////////
//进行Socket连接时,程序不能响应其他消息如Form移动等,
//加上 Application.ProcessMessages也不行
/////////////////////////////////////////////////////////////
...
...
end;
问题要求:进行Socket连接时,程序能响应其他消息如Form移动等
我的方法是使用线程。代码如下:
type
ThreadPop = class(TThread)
private
...
procedure FGetNewMail();
protected
procedure Execute; override;
published
constructor CreateIt(PriorityLevel: cardinal; ProgBar : TProgressBar; SakMsgList1:
TSakMsgList;SakPOP1: TSakPOP;shost:string;suserid:string;spassword :string);
destructor Destroy; override;
end;
procedure ThreadPop.Execute;
begin
while (Terminated = false) do
Synchronize(FGetNewMail);
end;
constructor ThreadPop.CreateIt(PriorityLevel: cardinal; ProgBar : TProgressBar;
SakMsgList1: TSakMsgList;SakPOP1: TSakPOP;shost:string;suserid:string;spassword :string);
begin
inherited Create(true); // Create thread suspended
Priority := TThreadPriority(PriorityLevel); // Set Priority Level
FreeOnTerminate := true; // Thread Free Itself when terminated
FSakMsgList1:= SakMsgList1;
FSakPOP1:= SakPOP1;
FHost:=shost;
FUserID:=suserid;
FPassword:=spassword;
Suspended := false; // Continue the thread
end;
procedure ThreadPop.FGetNewMail();
begin
FSakPOP1.Host := FHost;
FSakPOP1.UserId := FUserID;
FSakPOP1.UserPasswd := FPassword;
FSakPOP1.connect;
//???????????????? 这时倒是可以进行其他操作了,可是不进行Socket连接了。
if FSakPOP1.POPError then
begin
MessageDlg( 'Connect failed. Maybe the server is down or not responding.',
mtError, [mbOk], 0);
exit;
end;
if not FSakPOP1.login then
begin
ShowMessage('Unauthorized access...');
exit;
end;
FSakPOP1.Init;
showMessage( 'You have ' + intToStr( FSakPOP1.NewMsgsCount) + ' new msg(s) of ' +
intToStr( FSakPOP1.MsgsCount));
FsakPOP1.retrieveAllMessages( FSakMsgList1);
FSakPOP1.quit;
end;
请教各位,如何在线程中利用SakMail类似组件进行Pop3取信,
同时如何在线程中响应SakPop或其他VCL组件的各种事件。出分300,
求成功的例子或解决问题的思路.如果太长可以发到shyjun@china.com