大家来看看!内存流TMemoryStream!(200分)

  • 主题发起人 主题发起人 6713828
  • 开始时间 开始时间
6

6713828

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;<br><br>interface<br><br>uses<br> &nbsp;Windows, SysUtils, Variants, Classes, Graphics, Forms,<br> &nbsp;Controls, StdCtrls;<br><br>type<br> &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp;Edit1: TEdit;<br> &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp;Edit2: TEdit;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;Label2: TLabel;<br> &nbsp; &nbsp;Label3: TLabel;<br> &nbsp; &nbsp;Label4: TLabel;<br> &nbsp; &nbsp;Label5: TLabel;<br> &nbsp; &nbsp;Label6: TLabel;<br> &nbsp; &nbsp;Label7: TLabel;<br> &nbsp; &nbsp;Label8: TLabel;<br> &nbsp; &nbsp;Label9: TLabel;<br> &nbsp; &nbsp;Label10: TLabel;<br> &nbsp; &nbsp;Label11: TLabel;<br> &nbsp; &nbsp;Label12: TLabel;<br> &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp;private<br> &nbsp; &nbsp;{ Private declarations }<br> &nbsp;public<br> &nbsp; &nbsp;{ Public declarations }<br> &nbsp;end;<br><br>var<br> &nbsp;Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>Var<br> &nbsp;stream1,stream2:TMemoryStream;<br> &nbsp;buffer:array of char;<br> &nbsp;FG_Size,YF_Size,Size:Int64;<br> &nbsp;I:Integer;<br> &nbsp;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)&lt;&gt;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&lt;&gt;Size Do<br>Begin<br>//检查最后一次是否不足20000bys<br>If (Size-YF_Size)&lt;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>或则把代码贴出来也好啊!!![:(][:(][?][?][?][?][?]
 
网中戏天天来顶.向你学习.
 
变量在线程内执行就没有错误了
 
OK,搞顶
 
后退
顶部