请邦我看一个这一段代码有什么错误??(50分)

  • 主题发起人 主题发起人 Jebit
  • 开始时间 开始时间
J

Jebit

Unregistered / Unconfirmed
GUEST, unregistred user!
请邦我看一个这一段代码有什么错误??
当我运行下面的代码时,有时只会POST一次便停了,有时
会POST十多次,有时却不会停(正是我想要的)。
为会么???(有用到ICS)
unit Unit2;
interface
uses
Classes,HttpProt,stdctrls,sysutils,Unit1,windows;
type
TZJ = class(TThread)
procedure AddMessage;
private
FHttpPoster:THttpCli;
DataIn:TFileStream;
DataOut : TMemoryStream;
FAction:String;
FData:String;
FMemo:Tmemo;
FMessage:String;
procedure FHttpPosterDocbegin
(Sender: TObject);
procedure FHttpPosterDocEnd(Sender: TObject);
{ Private declarations }
protected
procedure Execute;
override;
public
constructor Create(CreateSuspended: Boolean;Action:String;Data:String;AOwer:TComponent;Memo:TMemo);
end;

implementation
{ TZJ }
procedure TZJ.FHttpPosterDocbegin
(Sender: TObject);
begin
try
DataIn:=TFileStream.Create('d:/12',fmCreate);
FHttpPoster.RcvdStream :=DataIn;
except
end;
end;

procedure TZJ.FHttpPosterDocEnd(Sender: TObject);
begin
if FHttpPoster.RcvdStream <> nil then
begin
FHttpPoster.RcvdStream.Free;
FHttpPoster.RcvdStream := nil;
end;
end;

procedure TZJ.Execute;
begin
Repeat
FMessage:='';
DataOut := TMemoryStream.Create;
DataOut.Write(FData[1], Length(FData));
DataOut.Seek(0, soFrombegin
ning);
FHttpPoster.SendStream := DataOut;
If Terminated then
Exit;
FHttpPoster.RcvdStream := nil;
try
FHttpPoster.Post;
except
FMessage:='Failed : '+IntToStr(FHttpPoster.StatusCode) + ' ' +FHttpPoster.ReasonPhrase;
Synchronize(AddMessage);
DataOut.free;
end;
if FMessage='' then
begin
Synchronize(AddMessage);
DataOut.Free;
end;
Until false;
end;

constructor TZJ.Create(CreateSuspended: Boolean;Action:String;Data:String;AOwer:TComponent;Memo:TMemo);
var TempPath,TempFile:Pchar;
begin
FAction:=Action;FData:=Data;FMemo:=Memo;
// GetTempPath(255,TempPath);
// GetTempFileName(TempPath,'',1,TempFile);
FHttpPoster:=THttpCli.Create(AOwer);
FHttpPoster.MultiThreaded:=False;
FHttpPoster.OnDocbegin
:=Self.FHttpPosterDocbegin
;
FHttpPoster.OnDocEnd:=Self.FHttpPosterDocend;
FHttpPoster.URL := FAction;

FreeOnTerminate:=true;
inherited Create(CreateSuspended);
end;

procedure TZJ.AddMessage;
begin
if FMessage='' then
Fmemo.Lines.LoadFromFile('d:/12')
else
FMemo.Lines.Add(FMessage);
end;

end.
 
可能是程序调用同步问题。
 
不好意思,我只会用creatthead()建线程,不知您在那儿开线程的?我怎么没找到c re a t t he a d?
 
经过这段时间的苦学,终于看动了。
 
多人接受答案了。
 
后退
顶部