D2010 TStream abstract error

Posted on 2010-01-05
Last Modified: 2013-11-23
Is there an undocumented change to the TStream mechanism in D2010?
For some reason, any operation on a TStream aside from free and create gives an abstract error.  any operations such as savetostream(theStream), copyfrom, copyto, readbuffer, read, writebuffer, write.. etc..
TMemoryStream,TFileStream and TStringStream work fine.

This problem is only in D2010 and even code which was working till D2009. even in the simplest form:
  //ms.load operation
  ms.position :=0;
  ms.savetostream(sm,sizeof(ms));    //fails  <<---- THIS SHOULD ALWAYS WORK!!
  //..OR sm.CopyFrom(ms,sizeof(ms));  //fails;;
Question by:controlr
    LVL 14

    Accepted Solution

    >>sm : TStream
    TStream is a base class and should not be use directly. You should be using one of its descendants instead. My guess is that while this may have worked in the older version of the compiler Delphi finally decided to enforce what it has been saying in the help files for quite some time now.

    From the help file:
    TStream is an abstract or, in C++ terminology, pure virtual class. It should not be instantiated; it relies on abstract or pure virtual methods that must be overridden in descendant classes. Descendant stream objects, such as memory and file streams used for component streaming, are created automatically by the global functions ReadComponentRes and WriteComponentRes. For streaming other kinds of information, choose a descendant class according to the specific data and storage needs. These include
    TFileStream (for working with files)
    TStringStream (for manipulating in-memory strings)
    TMemoryStream (for working with a memory buffer)
    TBlobStream (for working with BLOB fields)  
    TWinSocketStream (for reading and writing over a socket connection)  
    TOleStream (for using a COM interface to read and write)  

    Author Closing Comment

    it was so obvious.. as i had a problem on server side and thought it was a delphi error.  thanks.
    LVL 36

    Expert Comment

    by:Geert Gruwez
    >>ms.savetostream(sm,sizeof(ms));    //fails  <<---- THIS SHOULD ALWAYS WORK!!
    The lowest class which has this procedure is a TCustomMemoryStream in D2010
    The TStream doesn't even have this procedure

    it's even like that in D7

    check the Classes unit

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now