Converter: there was an extra cycle with LFM replace loop. Fixed.

git-svn-id: trunk@26127 -
This commit is contained in:
juha 2010-06-15 09:31:20 +00:00
parent 47e48c80c5
commit e15d883f82
2 changed files with 18 additions and 14 deletions

View File

@ -68,8 +68,8 @@ type
TLFMFixer = class(TLFMChecker) TLFMFixer = class(TLFMChecker)
private private
fSettings: TConvertSettings; fSettings: TConvertSettings;
// There are also unknown object types, not just properties. fHasMissingProperties: Boolean; // LFM file has unknown properties.
fHasMissingObjectTypes: Boolean; fHasMissingObjectTypes: Boolean; // LFM file has unknown object types.
// References to controls in UI: // References to controls in UI:
fPropReplaceGrid: TStringGrid; fPropReplaceGrid: TStringGrid;
fTypeReplaceGrid: TStringGrid; fTypeReplaceGrid: TStringGrid;
@ -236,6 +236,7 @@ constructor TLFMFixer.Create(APascalBuffer, ALFMBuffer: TCodeBuffer;
const AOnOutput: TOnAddFilteredLine); const AOnOutput: TOnAddFilteredLine);
begin begin
inherited Create(APascalBuffer, ALFMBuffer, AOnOutput); inherited Create(APascalBuffer, ALFMBuffer, AOnOutput);
fHasMissingProperties:=false;
fHasMissingObjectTypes:=false; fHasMissingObjectTypes:=false;
end; end;
@ -322,8 +323,9 @@ var
PropUpdater: TGridUpdater; PropUpdater: TGridUpdater;
TypeUpdater: TGridUpdater; TypeUpdater: TGridUpdater;
CurError: TLFMError; CurError: TLFMError;
OldIdent: string; OldIdent, NewIdent: string;
begin begin
fHasMissingProperties:=false;
fHasMissingObjectTypes:=false; fHasMissingObjectTypes:=false;
// ReplaceTypes is used for properties just in case it will provide some. // ReplaceTypes is used for properties just in case it will provide some.
PropUpdater:=TGridUpdater.Create(fSettings.ReplaceTypes, fPropReplaceGrid); PropUpdater:=TGridUpdater.Create(fSettings.ReplaceTypes, fPropReplaceGrid);
@ -334,12 +336,14 @@ begin
while CurError<>nil do begin while CurError<>nil do begin
if CurError.IsMissingObjectType then begin if CurError.IsMissingObjectType then begin
OldIdent:=(CurError.Node as TLFMObjectNode).TypeName; OldIdent:=(CurError.Node as TLFMObjectNode).TypeName;
TypeUpdater.AddUnique(OldIdent); // Add a unique type only once. NewIdent:=TypeUpdater.AddUnique(OldIdent); // Add each type only once.
if NewIdent<>'' then
fHasMissingObjectTypes:=true; fHasMissingObjectTypes:=true;
end end
else begin else begin
OldIdent:=CurError.Node.GetIdentifier; OldIdent:=CurError.Node.GetIdentifier;
PropUpdater.AddUnique(OldIdent); // Add a unique property only once. PropUpdater.AddUnique(OldIdent); // Add each property only once.
fHasMissingProperties:=true;
end; end;
CurError:=CurError.NextError; CurError:=CurError.NextError;
end; end;
@ -369,7 +373,8 @@ begin
fPropReplaceGrid:=FixLFMDialog.PropReplaceGrid; fPropReplaceGrid:=FixLFMDialog.PropReplaceGrid;
fTypeReplaceGrid:=FixLFMDialog.TypeReplaceGrid; fTypeReplaceGrid:=FixLFMDialog.TypeReplaceGrid;
LoadLFM; LoadLFM;
if fSettings.AutoRemoveProperties and not fHasMissingObjectTypes then if (fSettings.AutoRemoveProperties or not fHasMissingProperties)
and not fHasMissingObjectTypes then
Result:=ReplaceAndRemoveAll Result:=ReplaceAndRemoveAll
else begin else begin
// Cursor is earlier set to HourGlass. Show normal cursor while in dialog. // Cursor is earlier set to HourGlass. Show normal cursor while in dialog.

View File

@ -33,7 +33,7 @@ type
public public
constructor Create(AStringsMap: TStringToStringTree; AGrid: TStringGrid); constructor Create(AStringsMap: TStringToStringTree; AGrid: TStringGrid);
destructor Destroy; override; destructor Destroy; override;
procedure AddUnique(AOldIdent: string); function AddUnique(AOldIdent: string): string;
end; end;
{ TReplaceNamesForm } { TReplaceNamesForm }
@ -201,19 +201,18 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TGridUpdater.AddUnique(AOldIdent: string); function TGridUpdater.AddUnique(AOldIdent: string): string;
// Add a new Delphi -> Lazarus mapping to the grid. // Add a new Delphi -> Lazarus mapping to the grid.
var // Returns the replacement string.
NewIdent: string;
begin begin
// Add only one instance of each property name.
if fSeenNames.IndexOf(AOldIdent)<0 then begin if fSeenNames.IndexOf(AOldIdent)<0 then begin
// Add only one instance of each name.
fSeenNames.Append(AOldIdent); fSeenNames.Append(AOldIdent);
FindReplacement(AOldIdent, NewIdent); FindReplacement(AOldIdent, Result);
if fGrid.RowCount<GridEndInd+1 then if fGrid.RowCount<GridEndInd+1 then
fGrid.RowCount:=GridEndInd+1; fGrid.RowCount:=GridEndInd+1;
fGrid.Cells[0,GridEndInd]:=AOldIdent; fGrid.Cells[0,GridEndInd]:=AOldIdent;
fGrid.Cells[1,GridEndInd]:=NewIdent; fGrid.Cells[1,GridEndInd]:=Result;
Inc(GridEndInd); Inc(GridEndInd);
end; end;
end; end;