LoadFromStream (C++)

From RAD Studio Code Examples
Jump to: navigation, search


This example requires TListBox, TMemo, TRichEdit, and TButton controls placed on the form. The list box should contain one or more items. When the form becomes visible, click the button--the contents of the list box will be transferred to a stream and then to the rich edit control.


#include <memory>       //For STL auto_ptr class

void __fastcall TForm1::Button1Click(TObject *Sender)
  std::auto_ptr<TMemoryStream> pms(new TMemoryStream());
  ListBox1->Items->SaveToStream(pms.get()); // Write list box contents to the
                                            // stream.
  pms->Position = 0;                  // Reset to the beginning of the stream.
  RichEdit1->Lines->LoadFromStream(pms.get()); // Load stream contents into rich
										                 // edit control.