6
6713828
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> Windows, SysUtils, Variants, Classes, Graphics, Forms,<br> Controls, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Edit1: TEdit;<br> Button1: TButton;<br> Edit2: TEdit;<br> Label1: TLabel;<br> Label2: TLabel;<br> Label3: TLabel;<br> Label4: TLabel;<br> Label5: TLabel;<br> Label6: TLabel;<br> Label7: TLabel;<br> Label8: TLabel;<br> Label9: TLabel;<br> Label10: TLabel;<br> Label11: TLabel;<br> Label12: TLabel;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>Var<br> stream1,stream2:TMemoryStream;<br> buffer:array of char;<br> FG_Size,YF_Size,Size:Int64;<br> I:Integer;<br> a:Bool;<br>begin<br>stream1:=TMemoryStream.Create;<br>stream2:=TMemoryStream.Create;<br>I:=0;<br>a:=True;<br>stream1.LoadFromFile(Edit1.Text);<br>Size:=stream1.Size;<br>Label2.Caption:=Inttostr(Size);<br>FG_Size:=20000;//每次传输数据字节<br>YF_Size:=0;//已发送字节<br>//计算发送次数<br>If (Size Mod FG_Size)<>0 Then<br>Begin<br>Label10.Caption:=Inttostr(Size Div FG_Size+1);<br>End<br>Else<br>Begin<br>Label10.Caption:=Inttostr(Size Div FG_Size);<br>End;<br>//开始发送<br>While YF_Size<>Size Do<br>Begin<br>//检查最后一次是否不足20000bys<br>If (Size-YF_Size)<FG_Size Then<br>Begin<br>FG_Size:=Size Mod FG_Size;<br>Label4.Caption:=Inttostr(FG_Size);<br>End;<br>//开始读取数据<br>Inc(I);<br>If a Then<br>Begin<br>setlength(buffer,FG_Size);<br>stream1.SetSize(FG_Size);<br>//stream2.SetSize(stream1.Size);<br>a:=false;<br>End;<br>try<br>Stream1.Position:=YF_Size;<br>//stream1.readBuffer(buffer,FG_Size);<br>YF_Size:=YF_Size+FG_Size;<br>//写入文件数据<br>Stream2.Position:=YF_Size;<br>finally<br>end;<br>//stream2.WriteBuffer(buffer,FG_Size);<br>Sleep(10);<br>Label4.Caption:=Inttostr(FG_Size);<br>Label6.Caption:=Inttostr(YF_Size);<br>Label8.Caption:=Inttostr(Size-YF_Size);<br>Label12.Caption:=Inttostr(Strtoint(label10.Caption)-I);<br>Application.ProcessMessages;<br>End;<br>stream2.SaveToFile(Edit2.Text);<br>stream1.Free;<br>stream2.Free;<br>end;<br><br>end.<br><br>全部代码,各位大哥大侠们,谁能给我一个例子啊?<br>我在网上找了很多资料,就是没有关于这个的资料。<br>还有TFileStream文件流,能用在网络传输中吗?<br>我这个目的是做UDP文件发送的一个,我写的一个简单的测试读写例子<br>但是执行的时候报错。在读或写的时候报错<br>大哥大侠们,谁能给我一份例子啊???/<br>或则把代码贴出来也好啊!!![][][?][?][?][?][?]