Converter: fix unit conversion in different situations. Issue #24527

git-svn-id: trunk@41736 -
This commit is contained in:
juha 2013-06-16 23:42:46 +00:00
parent d4936c7bdc
commit 23ca7bd6a5
3 changed files with 16 additions and 15 deletions

View File

@ -674,8 +674,6 @@ begin
LfmFixer.RootMustBeClassInUnit:=true; LfmFixer.RootMustBeClassInUnit:=true;
LfmFixer.RootMustBeClassInIntf:=true; LfmFixer.RootMustBeClassInIntf:=true;
LfmFixer.ObjectsMustExist:=true; LfmFixer.ObjectsMustExist:=true;
// Package dependencies will be there only for projects and packages.
LfmFixer.TryAddingUsedUnits:=fOwnerConverter is TConvertDelphiProjPack;
if LfmFixer.ConvertAndRepair<>mrOK then begin if LfmFixer.ConvertAndRepair<>mrOK then begin
LazarusIDE.DoJumpToCompilerMessage(-1,true); LazarusIDE.DoJumpToCompilerMessage(-1,true);
fOwnerConverter.fErrorMsg:='Problems when repairing form file ' fOwnerConverter.fErrorMsg:='Problems when repairing form file '

View File

@ -73,7 +73,6 @@ type
fCTLink: TCodeToolLink; fCTLink: TCodeToolLink;
fSettings: TConvertSettings; fSettings: TConvertSettings;
fUsedUnitsTool: TUsedUnitsTool; fUsedUnitsTool: TUsedUnitsTool;
fTryAddingUsedUnits: Boolean;
// List of property values which need to be adjusted. // List of property values which need to be adjusted.
fHasMissingProperties: Boolean; // LFM file has unknown properties. fHasMissingProperties: Boolean; // LFM file has unknown properties.
fHasMissingObjectTypes: Boolean; // LFM file has unknown object types. fHasMissingObjectTypes: Boolean; // LFM file has unknown object types.
@ -97,7 +96,6 @@ type
public public
property Settings: TConvertSettings read fSettings write fSettings; property Settings: TConvertSettings read fSettings write fSettings;
property UsedUnitsTool: TUsedUnitsTool read fUsedUnitsTool write fUsedUnitsTool; property UsedUnitsTool: TUsedUnitsTool read fUsedUnitsTool write fUsedUnitsTool;
property TryAddingUsedUnits: Boolean read fTryAddingUsedUnits write fTryAddingUsedUnits;
end; end;
@ -473,13 +471,12 @@ var
RegComp: TRegisteredComponent; RegComp: TRegisteredComponent;
ClassUnitInfo: TUnitInfo; ClassUnitInfo: TUnitInfo;
i: Integer; i: Integer;
CompClassName, NeededUnitName: String; NeededUnitName: String;
begin begin
Result:=mrOK; Result:=mrOK;
if not Assigned(fUsedUnitsTool) then Exit; if not Assigned(fUsedUnitsTool) then Exit;
for i := 0 to aMissingTypes.Count-1 do begin for i := 0 to aMissingTypes.Count-1 do begin
CompClassName := aMissingTypes[i]; RegComp:=IDEComponentPalette.FindComponent(aMissingTypes[i]);
RegComp:=IDEComponentPalette.FindComponent(CompClassName);
NeededUnitName:=''; NeededUnitName:='';
if (RegComp<>nil) then begin if (RegComp<>nil) then begin
if RegComp.ComponentClass<>nil then begin if RegComp.ComponentClass<>nil then begin
@ -488,13 +485,13 @@ begin
NeededUnitName:=RegComp.GetUnitName; NeededUnitName:=RegComp.GetUnitName;
end; end;
end else begin end else begin
ClassUnitInfo:=Project1.UnitWithComponentClassName(CompClassName); ClassUnitInfo:=Project1.UnitWithComponentClassName(aMissingTypes[i]);
if ClassUnitInfo<>nil then if ClassUnitInfo<>nil then
NeededUnitName:=ClassUnitInfo.Unit_Name; NeededUnitName:=ClassUnitInfo.Unit_Name;
end; end;
if NeededUnitName<>'' then begin if NeededUnitName<>'' then begin
fUsedUnitsTool.AddUnitImmediately(NeededUnitName); if fUsedUnitsTool.AddUnitImmediately(NeededUnitName) then
Result:=mrRetry; // Caller must check LFM validity again Result:=mrRetry; // Caller must check LFM validity again
end; end;
end; end;
end; end;
@ -544,7 +541,6 @@ begin
Exit(mrCancel); Exit(mrCancel);
if CodeToolBoss.CheckLFM(fPascalBuffer, fLFMBuffer, fLFMTree, if CodeToolBoss.CheckLFM(fPascalBuffer, fLFMBuffer, fLFMTree,
fRootMustBeClassInUnit, fRootMustBeClassInIntf, fObjectsMustExist) fRootMustBeClassInUnit, fRootMustBeClassInIntf, fObjectsMustExist)
or not fTryAddingUsedUnits
then then
Result:=mrOk Result:=mrOk
else begin else begin

View File

@ -690,11 +690,18 @@ begin
end; end;
function TUsedUnitsTool.AddUnitImmediately(aUnitName: string): Boolean; function TUsedUnitsTool.AddUnitImmediately(aUnitName: string): Boolean;
// Add a unit to uses section and apply the change at once.
// Returns True if the unit was actually added (did not exist yet).
var
x: Integer;
begin begin
with fCTLink, fMainUsedUnits do begin Result:=not ( fMainUsedUnits.fExistingUnits.Find(aUnitName, x)
Result:=CodeTool.AddUnitToSpecificUsesSection(fUsesSection, aUnitName, '', SrcCache); or fImplUsedUnits.fExistingUnits.Find(aUnitName, x) );
if not Result then exit; if Result then begin
Result:=SrcCache.Apply; Result:=fCTLink.CodeTool.AddUnitToSpecificUsesSection(
fMainUsedUnits.fUsesSection, aUnitName, '', fCTLink.SrcCache);
if Result then
Result:=fCTLink.SrcCache.Apply;
end; end;
end; end;