当前位置 : 主页 > 编程语言 > delphi >

delphi – 为什么在使用TStream类时会出现“抽象错误”?

来源:互联网 收集:自由互联 发布时间:2021-06-23
当我尝试运行以下简单的代码序列时,我收到了Abstract Error错误消息: type TForm1 = class(TForm) Image1: TImage; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Publi
当我尝试运行以下简单的代码序列时,我收到了Abstract Error错误消息:

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;

我需要提取TBitmap的流以供以后处理……我做错了什么?

TStream class是一个抽象类,是所有流的基础.

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.

您可能希望使用TMemoryStream或TFileStream,顾名思义,它将流内容存储在内存或系统文件中.

procedure TForm1.Button1Click(Sender: TObject);
var
  ImageStream: TMemoryStream;
begin
  ImageStream := TMemoryStream.Create;
  try
    Image1.Picture.Bitmap.SaveToStream(ImageStream);
    ...
  finally
    ImageStream.Free;
  end;
end;
网友评论