1 procedure TFormTestRichText.btn1Click(Sender: TObject); 2 begin 3 //cxrchdt1.Lines.SaveToFile('d: est.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: est.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;