加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 09:18:27 所属栏目:大数据 来源:网络整理
导读:当我尝试运行以下简单的代码序列时,我收到了Abstract Error错误消息: type TForm1 = class(TForm) Image1: TImage; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;pro
当我尝试运行以下简单的代码序列时,我收到了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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读