delphi TMemoryStream 和TStringStream 转换

 1 procedure TFormTestRichText.btn1Click(Sender: TObject);
 2 begin
 3   //cxrchdt1.Lines.SaveToFile('d:\test.txt');
 4   mStream := TMemoryStream.Create;
 5   cxrchdt1.Lines.SaveToStream(mStream);
 6   ShowMessage(IntToStr(mStream.Size));
 7 end;
 8 
 9 procedure TFormTestRichText.btn2Click(Sender: TObject);
10 var
11   c: Char;
12   s1, s2: string;
13   vMemoryStream: TMemoryStream;
14 begin
15  //cxrchdt1.Lines.LoadFromFile('d:\test.txt');
16   cxrchdt1.Lines.LoadFromStream(mStream);
17 
18   s1 := '';
19   mStream.Position := 0;                       {指针到开始}
20   while mStream.Position < mStream.Size do          {循环读出}
21   begin
22     mStream.Read(c, 1);                         {每读出一个字节, 指针会自动移到新的位置}
23     s1 := s1 + c + '';                   {用文本记录}
24    // s2 := s2 + IntToHex(Byte(c),2) + ' '; {用两位数的十六进制记录}
25   end;
26 
27   vMemoryStream := TStringStream.create(s1);
28   cxrchdt1.Lines.LoadFromStream(vMemoryStream);
29 end;

 

posted @ 2017-09-22 09:51  夏天的西瓜君  阅读(1002)  评论(0编辑  收藏  举报