Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "Abstract Error" when working with TStream class?

Tags:

delphi

When I try to run the following simple code sequence, I'm getting the Abstract Error error message:

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure TForm1.Button1Click(Sender: TObject);
var
  ImageStream: TStream;
begin
  ImageStream := TStream.Create;
  Image1.Picture.Bitmap.SaveToStream(ImageStream);
  ...
end;

I need to extract the stream of an TBitmap for later processing... What am I doing wrong ?

like image 506
user1769184 Avatar asked Feb 01 '13 17:02

user1769184


1 Answers

The TStream class is an abstract class, and the foundation of all the streams.

TStream is the base class type for stream objects that can read from or write to various kinds of storage media, such as disk files, dynamic memory, and so on.

Use specialized stream objects to read from, write to, or copy information stored in a particular medium.

You may want to use the TMemoryStream or TFileStream, which, as the name implies, store the stream content in memory or a system file.

procedure TForm1.Button1Click(Sender: TObject);
var
  ImageStream: TMemoryStream;
begin
  ImageStream := TMemoryStream.Create;
  try
    Image1.Picture.Bitmap.SaveToStream(ImageStream);
    ...
  finally
    ImageStream.Free;
  end;
end;
like image 171
jachguate Avatar answered Oct 11 '22 17:10

jachguate