From b6a4657b66b23e23c65caa9667f514443bfa8fcd Mon Sep 17 00:00:00 2001 From: blikblum Date: Mon, 24 Mar 2014 12:34:52 +0000 Subject: [PATCH] lcl: Reset TFieldDataLink when a key field changes. Issue #25876 git-svn-id: trunk@44505 - --- lcl/dbctrls.pp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lcl/dbctrls.pp b/lcl/dbctrls.pp index 9348701c77..c5fac6f22c 100644 --- a/lcl/dbctrls.pp +++ b/lcl/dbctrls.pp @@ -52,6 +52,7 @@ Type FEditing: Boolean; IsModified: Boolean; function FieldCanModify: boolean; + function IsKeyField(aField: TField): Boolean; function GetCanModify: Boolean; // set current field procedure SetFieldName(const Value: string); @@ -1379,6 +1380,25 @@ begin result := FField.CanModify; end; +function TFieldDataLink.IsKeyField(aField: TField): Boolean; +var + KeyFieldName, KeyFields: String; + StrPos: Integer; +begin + KeyFields := FField.KeyFields; + StrPos := 1; + while StrPos <= Length(KeyFields) do + begin + KeyFieldName := ExtractFieldName(KeyFields, StrPos); + if SameText(aField.FieldName, KeyFieldName) then + begin + Result := True; + Exit; + end; + end; + Result := False; +end; + {TFieldDataLink Private Methods} { If the field exists and can be modified, then @@ -1529,7 +1549,8 @@ end; } procedure TFieldDataLink.RecordChanged(aField: TField); begin - if (aField = nil) or (aField = FField) then + if (aField = nil) or (aField = FField) or + ((FField <> nil) and (FField.FieldKind = fkLookup) and IsKeyField(aField)) then Reset; end;