Subject Re: [IBO] OnCalculateField: writing to calculated field of type blob throws AV
Author Helen Borrie
Markus,

At 10:36 PM 5/03/2009, you wrote:
>Hi all,
>
>I have a TIB_Query with SQL
>select * from rdb$database
>
>Then I declared a calculated field like this:
>blob_calc blob sub_type 0
>
>procedure TForm1.IB_Query1CalculateField(Sender: TIB_Statement; ARow: TIB_Row;
> AField: TIB_Column);
>begin
> if SameText(AField.FieldName, 'blob_calc') then
> AField.Assign(TStringStream.Create('abc')); // <- AV here
>end;
>
>When I open the query I get an AV in ClearBlobNodeData.
>
>Callstack follows:
>
>IB_Session.pas | | ClearBlobNodeData
>IB_Session.pas | | ClearBlobNodeData
>IB_Components.pas | TIB_BlobStream | Initialize
>IB_Components.pas | TIB_BlobStream | Initialize
>IB_Components.pas | TIB_BlobStream | Create
>IB_Components.pas | TIB_BlobStream | CreateForColumn
>IB_Components.pas | TIB_BlobStream | CreateForColumn
>IB_Components.pas | TIB_Statement | CreateBlobStream
>IB_Components.pas | TIB_Statement | CreateBlobStream
>IB_Components.pas | TIB_ColumnBlob | LoadFromStream
>IB_Components.pas | TIB_ColumnBlob | LoadFromStream
>IB_Components.pas | TIB_ColumnBlob | Assign
>Unit1.pas | TForm1 | IB_Query1CalculateField
>
>Using IBO 4.8.7 and D2007.
>
>Question is: Is this a known limitation or am I doing something wrong here?

It seems that your AV might be not to do with the blobnode at all, but come from calling Create on an undeclared stream object.

See how this goes for you:

procedure TForm1.IB_Query1CalculateField(Sender: TIB_Statement;
ARow: TIB_Row; AField: TIB_Column);

var
instream: TStringStream;
begin
with ARow do
if AField.NoCaseFieldName = 'blob_calc' then
begin
instream := TStringStream.Create('abc');
with AField as TIB_ColumnBlob do
try
Assign (instream);
if not (ByName('RDB$DESCRIPTION')).isNull then
Assign(ByName('RDB$DESCRIPTION'));
finally
instream.Free;
end;
end;
end;

Also, notice that for OnCalculateField you should refer to the Row object explicitly, to ensure that each row processed starts with everything fresh and free. (select * from rdb$database isn't exactly the ideal "set" to work with, though, since it can only be one row!!)

Helen