Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Database/Data Aware Controls/TDBLookupComboBox    [ Add a report in this area ]  
Report #:  80350   Status: Open
Race Condition in TDBLookupComboBox
Project:  Delphi Build #:  3593
Version:    14.0 Submitted By:   Mason Wheeler
Report Type:  Basic functionality failure Date Reported:  12/14/2009 9:33:23 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   274022
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
If the source dataset for a TDBLookupComboBox is populated before the lookup dataset, and the control is allowed to update itself (i.e. there is no DisableControls in effect), the following occurs:

TDBLookupControl.DataLinkRecordChanged is called. It calls TDBLookupControl.SetKeyValue, which looks like this:

procedure TDBLookupControl.SetKeyValue(const Value: Variant);
begin
  if not VarEquals(FKeyValue, Value) then
  begin
    FKeyValue := Value;
    KeyValueChanged;
  end;
end;

KeyValueChangd is virtual. TDBLookupComboBox's version looks like this:

procedure TDBLookupComboBox.KeyValueChanged;
begin
  if FLookupMode then
  begin
    FText := FDataField.DisplayText;
    FAlignment := FDataField.Alignment;
  end else
  if ListActive and LocateKey then
  begin
    FText := FListField.DisplayText;
    FAlignment := FListField.Alignment;
  end else
  begin
    FText := '';
    FAlignment := taLeftJustify;
  end;
  Invalidate;
end;

If FLookupMode is false, then LocateKey will be called, which checks FListLink.DataSet.Locate(FKeyFieldName, FKeyValue, []).  TDataset.Locate attempts to perform the actual lookup in the lookup dataset.  Since the lookup dataset has not been populated yet, Locate returns false, and the text property is left blank.  But, since FKeyValue was set back in SetKeyValue, subsequent calls will not call Locate again, and the control will remain blank until the user changes it manually.


This issue has been around since D2007 at least.
Steps to Reproduce:
See attached example.
Workarounds
Ensure that the lookup dataset is always populated before the source dataset, or that DisableControls is in force on the source dataset until *both* datasets have been populated.
Attachment
80350.zip
Comments

None

Server Response from: ETNACODE01