type
TMyTransfer = class(TThread)
private
{ Private declarations }
myfilename:string;
sophead:AuthHeader;
MyProgreSsbar:TProgreSsbar ;
websrv:wsDataExchangeSoap;
myAry:TByteDynArray;
fs:Tfilestream;
len,cS,yS,n:longint;
biztype:string;
receiver:string;
b:boolean;
protected
procedure Execute; override;
procedure myload();
procedure updatepbar();
public
constructor Create(CreateSuspended: Boolean;filename:string;ProgreSsbar:TProgreSsbar; Mysophead:AuthHeader;
mywebsrv:wsDataExchangeSoap;mybiztype:string;myreceiver:string
;
end;
implementation
const TransCount=10250;
constructor TMyTransfer.Create(CreateSuspended: Boolean;filename:string;ProgreSsbar:TProgreSsbar;Mysophead:AuthHeader;
mywebsrv:wsDataExchangeSoap;mybiztype:string;myreceiver:string
;
begin
inherited Create(CreateSuspended);
fs:=tfilestream.Create(filename,fmopenread);//创建文件流
len:=fs.Size;//获取文件流长度
cs:=trunc(len/TransCount);
ys:=len mod TransCount;
n:=0;
MyProgreSsbar:=ProgreSsbar;
websrv:= mywebsrv ;
sophead:=Mysophead ;
ProgreSsbar.Min:=0 ;
ProgreSsbar.Max:=cs;
biztype:= mybiztype;
receiver:=myreceiver;
myfilename:=filename;
end;
procedure TMyTransfer.myload();
begin
CoInitializeEx(NIL,2);
n:=n+1;
if n>cs then
begin
setlength(myAry,ys);
fs.Readbuffer(myAry[0],ys);//将字节数组读入文件流
(websrv as isoapheaders).send(sophead);
fs.Position;
b:=websrv.UploadFile(receiver,biztype,myAry);
fs.Free ;//销毁文件流
Terminate;
end
else
begin
setlength(myAry,TransCount);//设置字节数组长度
fs.Readbuffer(myAry[0],TransCount);
(websrv as isoapheaders).send(sophead);
b:= websrv.UploadFile(receiver,biztype,myAry);
end;
//CoUninitialize();
end;
procedure TMyTransfer.Execute;
begin
{ Place thread code here }
try
while not Terminated do
myload;
except
{ do something with exceptions }
end;
end;
end.