RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TStream.Position Property

Indicates the current offset into the stream for reading and writing.

Pascal
property Position: Int64;
C++
__property Int64 Position;

Use Position to obtain the current position of the stream. This is the number of bytes from the beginning of the streamed data.  

C++ Examples: 

 

/*
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 on the button and the contents of the list box will be
transferred to a stream and then to the rich edit control.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TMemoryStream* pms = new TMemoryStream();
  ListBox1->Items->SaveToStream(pms); // write list box contents to the
                                      // stream.
  pms->Position = 0;                  // reset to the beginning of the stream.
  RichEdit1->Lines->LoadFromStream(pms); // load stream contents into rich
                                         // edit control.
  delete pms;
}

 

Delphi Examples: 

{
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 on the button and the contents of the list box will be
transferred to a stream and then to the rich edit control.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  TempStream : TMemoryStream;
begin
  TempStream := TMemoryStream.Create;
  ListBox1.Items.SaveToStream(TempStream);  // write list box contents to the
                                            // stream
  TempStream.Position := 0;      // reset to the beginning of the stream
  RichEdit1.Lines.LoadFromStream( TempStream); // load stream contents into rich 
                                               // edit control
  TempStream.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox1.Items.Add('Apples');
  ListBox1.Items.Add('Oranges');
  ListBox1.Items.Add('Pears');
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!