[patch_done] Bug in Master/Detail Mechanisms
Posted: 04.02.2011, 13:40
unit ZAbstractRODataset;
...
TZDataLink = class(TDataLink)
...
is not correct for MD Relations, since it breaks Delphi Code for
enumerating Detaildatasets. Try dataset.getdetaildatasets(tlist) and
the answer is 0 Detaildatasets.
Bug is fixed with
...
TZDataLink = class(TMasterDataLink)
...
and
...
constructor TZDataLink.Create(ADataset: TZAbstractRODataset);
begin
inherited Create(ADataset);
FDataset := ADataset;
end;
...
Missing features:
doonnewrecord is incomplete for serversided MD Relations
The following code do the trick
...
procedure TZAbstractRODataset.DoOnNewRecord;
...
begin
if MasterLink.Active and (MasterLink.Fields.Count > 0) then begin
...
end else begin
if DataLink.Active and (DataLink.dataset.Fields.Count > 0) then begin
p1 := 1; p2 := 1;
while (P1 <= Length(LinkedFields)) and (p2 <= Length(MasterFields))
do begin
DetailField := FieldByName(ExtractFieldName(LinkedFields, P1));
MasterField := DataLink.DataSet.FieldByName
(ExtractFieldName(MasterFields, P2));
DetailField.Assign(MasterField);
end;
end;
end;
end;
...
With linkedfields=Lfield1;lfield2,lfield3...
and MasterFields=Mfield1;mfield2;Mfield3...
the content of the Masterfield is copied into the corresponding
likedfield.
Cascading delete
With a working getdetailrecordsets the following code seems to work
...
procedure TZAbstractDataset.InternalDelete;
var
RowNo: Integer;
RowBuffer: PZRowBuffer;
i: Integer;
Detailsets: TList;
ds: TZAbstractDataset;
begin
Detailsets := TList.create;
getdetaildatasets(Detailsets);
for i := 0 to Detailsets.Count - 1 do begin
ds := TZAbstractDataset(Detailsets);
with ds do begin
if not Active then Open;
first;
while not Eof do begin
Delete;
end;
end;
end;
Detailsets.Free;
...
end;
...
Hope this additions are usefull
Karl Scheurer
...
TZDataLink = class(TDataLink)
...
is not correct for MD Relations, since it breaks Delphi Code for
enumerating Detaildatasets. Try dataset.getdetaildatasets(tlist) and
the answer is 0 Detaildatasets.
Bug is fixed with
...
TZDataLink = class(TMasterDataLink)
...
and
...
constructor TZDataLink.Create(ADataset: TZAbstractRODataset);
begin
inherited Create(ADataset);
FDataset := ADataset;
end;
...
Missing features:
doonnewrecord is incomplete for serversided MD Relations
The following code do the trick
...
procedure TZAbstractRODataset.DoOnNewRecord;
...
begin
if MasterLink.Active and (MasterLink.Fields.Count > 0) then begin
...
end else begin
if DataLink.Active and (DataLink.dataset.Fields.Count > 0) then begin
p1 := 1; p2 := 1;
while (P1 <= Length(LinkedFields)) and (p2 <= Length(MasterFields))
do begin
DetailField := FieldByName(ExtractFieldName(LinkedFields, P1));
MasterField := DataLink.DataSet.FieldByName
(ExtractFieldName(MasterFields, P2));
DetailField.Assign(MasterField);
end;
end;
end;
end;
...
With linkedfields=Lfield1;lfield2,lfield3...
and MasterFields=Mfield1;mfield2;Mfield3...
the content of the Masterfield is copied into the corresponding
likedfield.
Cascading delete
With a working getdetailrecordsets the following code seems to work
...
procedure TZAbstractDataset.InternalDelete;
var
RowNo: Integer;
RowBuffer: PZRowBuffer;
i: Integer;
Detailsets: TList;
ds: TZAbstractDataset;
begin
Detailsets := TList.create;
getdetaildatasets(Detailsets);
for i := 0 to Detailsets.Count - 1 do begin
ds := TZAbstractDataset(Detailsets);
with ds do begin
if not Active then Open;
first;
while not Eof do begin
Delete;
end;
end;
end;
Detailsets.Free;
...
end;
...
Hope this additions are usefull
Karl Scheurer