Freeing TLOBLocator

I have a program with a form that I'm opening and closing several times. I am using a TLOBLocator to read BLOB data and display it in a memo field. I thought that it would be a good idea to free the TLOBLocator upon finishing my reading of the data but when I reentered the form I received an Access Violation the first time that I executed any of the methods for the TOracleQuery Object that the TLOBLocator was referencing. Is it necessary to manually free the TLOBLocator and if so, then how and where?
I've included the procedure where I'm referencing the TLOBLocator.

Thanks,
t.paul

Procedure TfrmDetails.SetDtlQuery(strDocID, strSectID : string);
var
LOB: TLOBLocator;
k: integer;
blobchar: pchar;
begin
qryDtl.Close;
qryDtl.SetVariable('DOCID',strDocID);
qryDtl.SetVariable('SECTID',strSectID);
qryDtl.Execute;
memDetail.Lines.Clear;
while not qryDtl.Eof do begin
LOB := qryDtl.LOBField('xrawdata');
k := LOB.Size;
GetMem(blobchar,k);
LOB.Read(blobchar^,k);
memDetail.Lines.Append(copy(blobchar,1,k));
FreeMem(blobchar);
qryDtl.Next;
end;
// LOB.Free;
frmDetails.showmodal;
end;
 
You should not free the TLOBLocator instance that is returned by the LOBField function. This is only necessary if you explicitly create one with TLOBLocator.Create. The TOracleQuery owns the LOBLocator and will free it when the next record is fetched or when it is closed. That's why you get the access violation: the TOracleQuery tries to free an instance that is already freed in your code.

------------------
Marco Kalter
Allround Automations
 
Back
Top