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.
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 i.e.
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
?
Any views appreciated.
bs
variable will be still uninitialized at line 12. Since Delphi compiler provides no means for initialization of local variable such flow will cause an exception. So, you decision to initialize to nil is perfect. – OnTheFly