Converter: fix unit conversion in different situations. Issue

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.RootMustBeClassInIntf:=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
LazarusIDE.DoJumpToCompilerMessage(-1,true);
fOwnerConverter.fErrorMsg:='Problems when repairing form file '

View File

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

View File

@ -690,11 +690,18 @@ begin
end;
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
with fCTLink, fMainUsedUnits do begin
Result:=CodeTool.AddUnitToSpecificUsesSection(fUsesSection, aUnitName, '', SrcCache);
if not Result then exit;
Result:=SrcCache.Apply;
Result:=not ( fMainUsedUnits.fExistingUnits.Find(aUnitName, x)
or fImplUsedUnits.fExistingUnits.Find(aUnitName, x) );
if Result then begin
Result:=fCTLink.CodeTool.AddUnitToSpecificUsesSection(
fMainUsedUnits.fUsesSection, aUnitName, '', fCTLink.SrcCache);
if Result then
Result:=fCTLink.SrcCache.Apply;
end;
end;