View Issue Details

IDProjectCategoryView StatusLast Update
0005590JEDI VCL00 JVCL Componentspublic2011-06-09 22:13
ReportercguserAssigned Tojfudickar 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionDaily / GIT 
Target VersionFixed in Version 
Summary0005590: TJvDBCustomSearchEdit.DoExit may cause AV
DescriptionOn JvDBSearchEdit.pas, procedure DoExit may cause an AV if DataSet has just been closed before component lost it's focus.
Additional InformationInstead of

procedure TJvDBCustomSearchEdit.DoExit;
begin
  inherited DoExit;
  // On replace le texte sur l'enregistrement en cours
  if Assigned(FDataLink.DataSet) then
    Text := FDataLink.DataSet.FieldByName(DataField).AsString;
end;

this will account for DataSet's active state:

procedure TJvDBCustomSearchEdit.DoExit;
begin
  inherited DoExit;
  // On replace le texte sur l'enregistrement en cours
  if Assigned(FDataLink.DataSet) and FDataLink.DataSet.Active then
    Text := FDataLink.DataSet.FieldByName(DataField).AsString;
end;

PS: JvDBSearchEdit.pas rev 12461
TagsNo tags attached.

Activities

obones

2011-06-07 18:03

administrator   ~0018640

Please provide the zipped sources of a sample application showing this

2011-06-07 18:30

 

TestJvDBSearchEdit.7z (3,905 bytes)

cguser

2011-06-07 18:32

reporter   ~0018643

Done! The gist of it, new form, on the onclick event of a TButton, put the following code:

  TClientDataSet *cds = new TClientDataSet(this);
  TField *i = new TIntegerField(cds);
  i->FieldName = "Field1";
  i->DataSet = cds;
  i->FieldKind = fkData;
  cds->CreateDataSet();
  cds->Open();

  TDataSource *ds = new TDataSource(this);
  ds->DataSet = cds;

  TJvDBSearchEdit *search = new TJvDBSearchEdit(this);
  search->Parent = this;
  search->DataSource = ds;
  search->DataField = "Field1";

  search->SetFocus();
  cds->Close();

  SelectNext(search, true, true); // AV: Moving focus to next Ctrl

obones

2011-06-08 16:23

administrator   ~0018691

Is this specific to C++Builder?

cguser

2011-06-08 17:24

reporter   ~0018698

Not that I'm aware of. The case as provided is a very simplified test code. On the real app, there was a TSpeedButton (focusless) that would commit data and close the dataset, before changing the active TabSheet (with a TJvDBSearchEdit on it) on a PageControl. When changing the active TabSheet, an AV was triggered on the TJvDBSearchEdit.DoExit because it's underlying dataset was no longer active.
It's simply not intuitive for components to give access violations just by losing focus as in:

if Assigned(FDataLink.DataSet) then
     Text := FDataLink.DataSet.FieldByName(DataField).AsString;

This is just begging for trouble because FDataLink.DataSet may not be active (yet/)anymore.

jfudickar

2011-06-09 22:13

developer   ~0018714

Done

Issue History

Date Modified Username Field Change
2011-06-01 15:40 cguser New Issue
2011-06-07 18:03 obones Note Added: 0018640
2011-06-07 18:03 obones Status new => feedback
2011-06-07 18:30 cguser File Added: TestJvDBSearchEdit.7z
2011-06-07 18:32 cguser Note Added: 0018643
2011-06-08 10:12 obones Status feedback => acknowledged
2011-06-08 16:23 obones Note Added: 0018691
2011-06-08 16:23 obones Status acknowledged => feedback
2011-06-08 17:24 cguser Note Added: 0018698
2011-06-08 17:44 obones Status feedback => acknowledged
2011-06-09 22:13 jfudickar Note Added: 0018714
2011-06-09 22:13 jfudickar Status acknowledged => resolved
2011-06-09 22:13 jfudickar Resolution open => fixed
2011-06-09 22:13 jfudickar Assigned To => jfudickar