zmsql: Fix debug-mode master-detail bug reported in http://forum.lazarus.freepascal.org/index.php/topic,39556.0.html

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6121 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2018-01-09 09:50:28 +00:00
parent dc884b4470
commit 9b6ff70a30

View File

@ -340,6 +340,7 @@ type
implementation implementation
uses uses
Variants,
ZMReferentialKey; ZMReferentialKey;
const const
@ -1801,41 +1802,48 @@ end;
procedure TZMQueryDataSet.DoFilterRecord({var} out Acceptable: Boolean); procedure TZMQueryDataSet.DoFilterRecord({var} out Acceptable: Boolean);
var var
i, vCount:Integer; i, vCount:Integer;
vField: TField; namDetail, namMaster: String;
DetailField, MasterField: TField;
begin begin
//inherited behavior //inherited behavior
inherited DoFilterRecord(Acceptable); inherited DoFilterRecord(Acceptable);
//New behavior //New behavior
if not Acceptable then exit; if not Acceptable then exit;
//Filter detail dataset if all conditions are met. //Filter detail dataset if all conditions are met.
if ((FBulkInsert=False) if (not FBulkInsert)
and (DisableMasterDetailFiltration=False) and (not DisableMasterDetailFiltration)
and (Assigned(MasterFields)) and (Assigned(MasterFields))
and (Assigned(MasterSource)) and (Assigned(MasterSource))
and (FMasterDetailFiltration{=True}) and (FMasterDetailFiltration)
and (Active) and (Active)
and (MasterSource.DataSet.Active)) then begin and (MasterSource.DataSet.Active) then
begin
vCount:=0; vCount:=0;
Filtered:=True; //Ensure dataset is filtered Filtered:=True; //Ensure dataset is filtered
for i:=0 to MasterFields.Count-1 do begin for i:=0 to MasterFields.Count-1 do begin
try //try
//If Name=Value (Detail field=Master field) pair is provided namDetail := MasterFields.Names[i];
If ((FieldByName(MasterFields.Names[i]).Value=MasterSource.DataSet.FieldByName(MasterFields.ValueFromIndex[i]).Value) if namDetail <> '' then begin
or (FieldByName(MasterFields.Names[i]).AsString=MasterSource.DataSet.FieldByName(MasterFields.ValueFromIndex[i]).AsString)) // if Name=Value (Detail field=Master field) pair is provided...
then Inc(vCount); namMaster := MasterFields.ValueFromIndex[i];
except end else begin
//If Name=Value (Detail field=Master field) pair is not provided // if single name is provided for both detail and master field
If ((FieldByName(MasterFields[i]).Value=MasterSource.DataSet.FieldByName(MasterFields[i]).Value) namMaster := FMasterFields[i];
or (FieldByName(MasterFields[i]).AsString=MasterSource.DataSet.FieldByName(MasterFields[i]).AsString)) namDetail := namMaster;
then Inc(vCount); end;
end; DetailField := FieldByName(namDetail);
MasterField := MasterSource.Dataset.FieldByName(namMaster);
if VarSameValue(Detailfield.Value, Masterfield.Value) then
inc(vCount);
end; end;
if vCount=MasterFields.Count then Acceptable:=True Acceptable := (vCount=MasterFields.Count);
else Acceptable:=False;
//Refresh slave datasets //Refresh slave datasets
if not ControlsDisabled then //// edgarrod71@gmail.com if not ControlsDisabled then //// edgarrod71@gmail.com
DoAfterScroll; DoAfterScroll;
end; end;
end; end;