gpt4 book ai didi

delphi - 为什么我在使用 TStream 类时收到 "Abstract Error"?

转载 作者:行者123 更新时间:2023-12-03 15:11:24 28 4
gpt4 key购买 nike

当我尝试运行以下简单代码序列时,收到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.

您可能想使用TMemoryStreamTFileStream ,顾名思义,它将流内容存储在内存或系统文件中。

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

关于delphi - 为什么我在使用 TStream 类时收到 "Abstract Error"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14651780/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com