我做了一个局域网文件传送软件, 我在服务器端用以下程序分解: const packetlen=2048; type tpacket=array[1..packetlen] of char; var Form1: TForm1; packets: array of tpacket; implementation
{$R *.dfm} procedure tform1.readintobuffer(s:string); var i,j:integer; infile :file; begin assignfile(infile,s); reset(infile,1); i:=filesize(infile) div packetlen; setlength(packets,i+1); for i:=0 to length(packets)-2 do blockread(infile,packets[i],packetlen); i:=length(packets)-1; j:=filesize(infile) mod packetlen; blockread(infile,packets[i],j); edit1.Tag:=filesize(infile); closefile(infile); end;
我在客户端用以下程序合并: procedure tform1.combinepacket; var outfile :file; i,j:integer; begin assignfile(outfile,edit2.Text); rewrite(outfile,1); for i:=0 to length(packets)-2 do blockwrite(outfile,packets[i],packetlen); i:=length(packets)-1; j:=edit2.tag mod packetlen; blockwrite(outfile,packets[i],j); closefile(outfile); end;