[英]TStream warning in delphi
I have the following code snippet 我有以下代码片段
Procedure TFrm.Retrieve(mystring : string);
var
bs : TStream;
...
begin
...
bs:=nil;
//bs:= TStream.create;
try
bs := CreateBlobStream(FieldByName('Picture'), bmRead);
finally
bs.Free;
end;
...
end;
I have a problem understanding the initialisation of bs
variable. 我在理解bs
变量的初始化时遇到问题。
If I dont initialize it , a but obvious warning i get. 如果我不初始化它,我会得到一个明显的警告。
Variable 'bs' might not have been initialized.
Now if I do it as the commented part ie 现在,如果我将其作为评论部分,即
bs:= TStream.create;
I get the following warning. 我收到以下警告。
Constructing instance of 'TStream' containing abstract method 'TStream.Read'
Constructing instance of 'TStream' containing abstract method 'TStream.Write'
and finally it works totally fine if I use 最后如果我使用它完全可以正常工作
bs:=nil;
Am I Doing it correct by assigning it to Nil
? 我将其分配给Nil
是否正确?
Any views appreciated. 任何意见表示赞赏。
TStream
is abstract so you shouldn't instantiate it (calling an abstract method causes a runtime error). TStream
是抽象的,因此您不应实例化它(调用抽象方法会导致运行时错误)。 Instead, you should instantiate a non-abstract descendant. 相反,您应该实例化一个非抽象的后代。 When you're done you should Free
the instance. 完成后,您应该Free
实例。
For example: 例如:
var
Stream: TStream;
begin
try
Stream := CreateBlobStream(FieldByName('Picture'), bmRead);
try
// ...
finally
Stream.Free;
end;
except
// handle exceptions
end;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.