Post method always fails after changing the DataSet used as the ListSource for a TDBLookupCombo
Original Reporter info from Mantis: TWhyman
-
Reporter name: Tony Whyman
Original Reporter info from Mantis: TWhyman
- Reporter name: Tony Whyman
Description:
To reproduce this problem, set up a simple program using a TDBLookupCombo, after a first use of the control, change the dataset referenced by the TDBCombox's ListSource TDataSource, to a DataSet that is compatible with the previous one, (i.e.has the same fieldnames) and dispose of the old one. The result will be an access violation in TDBLookup.
This problem arose when changing the datasource from one data module to another.
Additional information:
On investigation, the reason for this problem seemed to be that the change of dataset did not result in a corresponding change to the FListField maintained by the TDBLookup object. Hence it was still referencing the old dataset.
The fix appears to be a simple change to TDBLookup.ActiveChange to set FListField to nil when the dataset is not active.
procedure TDBLookup.ActiveChange(Sender: TObject);
begin
if (csDestroying in ComponentState) then
Exit;
if FListLink.Active and not FListLinkTmpSetActive then
Initialize(FControlLink, FControlItems)
else
if not FListLink.Active then
FListField := nil
end;
Mantis conversion info:
- Mantis ID: 19168
- Version: 0.9.30
- Target version: 0.99.0