Board index » delphi » Don't know how to use TStream.

Don't know how to use TStream.

i found the methods
    SaveToStream(Stream: TStream);
    LoadToStream(Stream: TStream);
are quite often existing in many classes such as TOLEcontainer, TBitmap,
......

but i can't use it directly, or even I don't know how can i use TStream
class,
could anybody give me an example for that?
thanks :)

 

Re:Don't know how to use TStream.


Quote
On Thu, 17 Feb 2000 17:49:58 +0800, "Phaat" <ph...@geocities.com> wrote:
>i found the methods
>    SaveToStream(Stream: TStream);
>    LoadToStream(Stream: TStream);
>are quite often existing in many classes such as TOLEcontainer, TBitmap,
>......

>but i can't use it directly, or even I don't know how can i use TStream
>class,
>could anybody give me an example for that?

You do not want to use TStream: it is an abstract, base class used as the
basis for descendent classes that implement the actual functionality.
Depending on what you are doing, you would want to use a TStream class
descendent like TMemoryStream, TFileStream, or TBlobStream.

To use any of these, though, you must first instantiate on object of that
class. Do this by calling the constructor for the class (the Create
method), storing the return value into an approapriately typed variable.
That variable then contains the instantiated object. After that you can
access its properties and call its methods.

  var
    MS: TMemoryStream;
  begin
    MS := TMemoryStream.Create;
    try
      Memo1.Lines.SaveToStream(MS);
      MS.Seek(0, soFromBeginning);
      Memo2.Lines.LoadFromStream(MS);
    finally
      if Assigned(MS) then MS.Free;
    end;
  end;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx

Other Threads