* Fix bug #18672, using improved patch of Laco

git-svn-id: trunk@39470 -
This commit is contained in:
michael 2018-07-18 12:23:04 +00:00
parent 3acdf481c2
commit 270cf0ed06

View File

@ -1331,30 +1331,45 @@ end;
procedure TDataSet.SetName(const Value: TComponentName); procedure TDataSet.SetName(const Value: TComponentName);
function CheckName(const FieldName: string): string; function CheckName(const FieldName: string): string;
var i,j: integer;
begin var i,j: integer;
Result := FieldName;
i := 0; begin
j := 0; Result := FieldName;
while (i < Fields.Count) do begin i := 0;
if Result = Fields[i].FieldName then begin j := 0;
inc(j); // Check if fieldname exists.
Result := FieldName + IntToStr(j); while (i < Fields.Count) do
end else Inc(i); 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;
end;
var i: integer; var
nm: string; i: integer;
old: string; OldName, OldFieldName: string;
begin begin
if Self.Name = Value then Exit; if Self.Name = Value then Exit;
old := Self.Name; OldName := Self.Name;
inherited SetName(Value); inherited SetName(Value);
if (csDesigning in ComponentState) then if (csDesigning in ComponentState) then
for i := 0 to Fields.Count - 1 do begin for i := 0 to Fields.Count - 1 do begin
nm := old + Fields[i].FieldName; OldFieldName := OldName + Fields[i].FieldName;
if Copy(Fields[i].Name, 1, Length(nm)) = nm then if Copy(Fields[i].Name, 1, Length(OldFieldName)) = OldFieldName then
Fields[i].Name := CheckName(Value + Fields[i].FieldName); Fields[i].Name := CheckName(Value + Fields[i].FieldName);
end; end;
end; end;