summaryrefslogtreecommitdiff
path: root/packages/fcl-db/src/base/dataset.inc
diff options
context:
space:
mode:
authormichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2018-07-18 12:23:04 +0000
committermichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2018-07-18 12:23:04 +0000
commit1f05d9c5ae7535ee97a2b5feb216c71bddcb17e3 (patch)
tree647ae833e67a6a8d85e5d8ac585e16a7c761f143 /packages/fcl-db/src/base/dataset.inc
parent1c0b8663d738b422e42c553f61fbd4c829d0e265 (diff)
downloadfpc-1f05d9c5ae7535ee97a2b5feb216c71bddcb17e3.tar.gz
* Fix bug 18672, using improved patch of Laco
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@39470 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-db/src/base/dataset.inc')
-rw-r--r--packages/fcl-db/src/base/dataset.inc51
1 files changed, 33 insertions, 18 deletions
diff --git a/packages/fcl-db/src/base/dataset.inc b/packages/fcl-db/src/base/dataset.inc
index e4c0daa7cd..819b3484e8 100644
--- a/packages/fcl-db/src/base/dataset.inc
+++ b/packages/fcl-db/src/base/dataset.inc
@@ -1331,30 +1331,45 @@ end;
procedure TDataSet.SetName(const Value: TComponentName);
-function CheckName(const FieldName: string): string;
-var i,j: integer;
-begin
- Result := FieldName;
- i := 0;
- j := 0;
- while (i < Fields.Count) do begin
- if Result = Fields[i].FieldName then begin
- inc(j);
- Result := FieldName + IntToStr(j);
- end else Inc(i);
+ function CheckName(const FieldName: string): string;
+
+ var i,j: integer;
+
+ begin
+ Result := FieldName;
+ i := 0;
+ j := 0;
+ // Check if fieldname exists.
+ while (i < Fields.Count) do
+ if Not SameText(Result,Fields[i].Name) then
+ inc(i)
+ else
+ begin
+ inc(j);
+ Result := FieldName + IntToStr(j);
+ i := 0;
+ end;
+ // Check if component with the same name exists.
+ if Assigned(Owner) then
+ While Owner.FindComponent(Result)<>Nil do
+ begin
+ Inc(J);
+ Result := FieldName + IntToStr(j);
+ end;
end;
-end;
-var i: integer;
- nm: string;
- old: string;
+
+var
+ i: integer;
+ OldName, OldFieldName: string;
+
begin
if Self.Name = Value then Exit;
- old := Self.Name;
+ OldName := Self.Name;
inherited SetName(Value);
if (csDesigning in ComponentState) then
for i := 0 to Fields.Count - 1 do begin
- nm := old + Fields[i].FieldName;
- if Copy(Fields[i].Name, 1, Length(nm)) = nm then
+ OldFieldName := OldName + Fields[i].FieldName;
+ if Copy(Fields[i].Name, 1, Length(OldFieldName)) = OldFieldName then
Fields[i].Name := CheckName(Value + Fields[i].FieldName);
end;
end;