Icon View Incident Report

Minor Minor
Reported By: Yusuf Zorlu
Reported On: 10/11/2019
For: Version 2.31 Build 8
# 4761 Closing a TEDBDataSet Instance During the BeforeOpen Event Handler Causes Invalid Pointer Exception

The following code causes an "Invalid Pointer" exception when it shouldn't.

procedure TForm1.Button1Click(Sender: TObject);
begin
    tpos3.SQL.Text:='select a_pos, a_ag, a_ff from positionen';
    tpos3.open;
    application.processmessages;
    showmessage('test 1, now change sql and reopen with lesser fields');

    tpos3.close;
    tpos3.sql.text:='select a_pos from positionen';
    tpos3.open;
end;

procedure TForm1.tPos3BeforeOpen(DataSet: TDataSet);
var
    i, imax:integer;
begin
    dataset.fields.Clear;
    dataset.FieldDefs.Clear;
    //while DataSet.fieldcount>0 do DataSet.fields[0].free;
    dataset.fielddefs.updated:=false;

    try
        if dataset.fielddefs.updated=false then DataSet.FieldDefs.Update;
    except
        on e:Exception do begin
            showmessage(e.message);
        end;
    end;

    imax:=DataSet.fielddefs.count;
    for i:=0 to imax-1 do begin
        if dataset.findfield(dataset.fielddefs[i].Name)=nil then begin
            DataSet.fielddefs[i].createfield(DataSet);
        end;
    end;
end;



Comments Comments and Workarounds
When freeing a record buffer via the TEDBDataSet FreeRecordBuffer method, the buffer wasn't getting nil-ed out, and this was interacting with the attempt to update the field definitions *while* the dataset was being opened, which caused the dataset to be closed. The workaround would be to use a TEDBQuery.AfterPrepare event handler instead to handle create custom fields after the query has been prepared, but before it has been opened.


Resolution Resolution
Fixed Problem on 10/14/2019 in version 2.31 build 9


Products Affected Products Affected
ElevateDB LCL Standard with Source
ElevateDB VCL Client-Server
ElevateDB VCL Client-Server with Source
ElevateDB VCL Standard
ElevateDB VCL Standard with Source
ElevateDB VCL Trial

Image