Y
yuqiu0527
Unregistered / Unconfirmed
GUEST, unregistred user!
我用IdTCPClient 进行 文件传输var cmd,tmpfn,msg,targetname,localdir,com:string; lsize:int64; fs:tfilestream; filenamechar; sign,i:integer; ldir:stringarray; lSavePath,Savedir:String; try with athread.Connection do begin cmd:=trim(readln); if cmd='TRANSFILE'then begin GetMem(filename,255); zeromemory(filename,255); tmpfn:=readln; Move(tmpfn[1],filename^,length(tmpfn)); sendmessage(ufrmSendFiles.Handle,WM_USER+100,integer(filename),0); writeln('BEGIN'); lsize:=strtointdef(readln,0); if lsize=0 then begin disconnect; exit; end; fs:=TFileStream.Create(filename,fmcreate); readstream(fs,lsize); fs.Free; end; if cmd='TRANSDIR'then //接收文件夹信号 begin if selectdirectory('保存文件夹','我的电脑',Savedir)=true then begin if trim(copy(Savedir,length(Savedir),1))<>'/' then Savedir:=Savedir+'/'; GetMem(localroot,255); zeromemory(localroot,255); move(Savedir[1],localroot^,length(Savedir)); writeln('TRUE'); end else writeln('FALSE'); end; if cmd='START'then begin msg:=readln(); //接收文件名 ldir:=split(msg,'/'); localdir:=strpas(localroot); for i:=0 to high(ldir)-1 do begin localdir:=localdir+ldir+'/'; if not directoryexists(localdir) then createdir(localdir); //创建接收到的文件夹下边的文件夹 end; targetname:=strpas(localroot)+msg; //本地文件名 writeln('BEGIN'); //发送开始信号 lsize:=strtointdef(readln,0); //接收文件大小 if lsize=0 then begin disconnect; exit; end; fs:=TFileStream.Create(targetname,fmcreate); readstream(fs,lsize); fs.Free; end; // end; except /// end;end;/@为什么 只能传 文本文件 word与图片传完后打不开 请赐教