diff --git a/converter/missingpropertiesdlg.pas b/converter/missingpropertiesdlg.pas index 8bf3536a10..ba3d3b5052 100644 --- a/converter/missingpropertiesdlg.pas +++ b/converter/missingpropertiesdlg.pas @@ -490,8 +490,10 @@ begin if ClassUnitInfo<>nil then NeededUnitName:=ClassUnitInfo.Unit_Name; end; - if NeededUnitName<>'' then - fUsedUnitsTool.AddUnitIfNeeded(NeededUnitName); + if NeededUnitName<>'' then begin + fUsedUnitsTool.AddUnitImmediately(NeededUnitName); + Result:=mrRetry; // Caller must check LFM validity again + end; end; end; @@ -520,28 +522,29 @@ begin finally ConvTool.Free; end; - LoopCount:=0; + LoopCount:=0; // Prevent possible eternal loops with a counter repeat - if not fLFMTree.ParseIfNeeded then exit; + repeat + if not fLFMTree.ParseIfNeeded then exit; + if CodeToolBoss.CheckLFM(fPascalBuffer, fLFMBuffer, fLFMTree, + fRootMustBeClassInUnit, fRootMustBeClassInIntf, fObjectsMustExist) then + Result:=mrOk + else // Rename/remove properties and types interactively. + Result:=ShowConvertLFMWizard; // Can return mrRetry. + Inc(LoopCount); // Increment counter in inner loop + until Result in [mrOK, mrCancel]; + + // Check for missing object types and add units as needed. + if not fLFMTree.ParseIfNeeded then + Exit(mrCancel); if CodeToolBoss.CheckLFM(fPascalBuffer, fLFMBuffer, fLFMTree, fRootMustBeClassInUnit, fRootMustBeClassInIntf, fObjectsMustExist) then Result:=mrOk - else // Rename/remove properties and types interactively. - Result:=ShowConvertLFMWizard; // Can return mrRetry. - Inc(LoopCount); - until (Result in [mrOK, mrCancel]) or (LoopCount=20); - - // Check for missing object types and add units as needed. - if not fLFMTree.ParseIfNeeded then - Exit(mrCancel); - if CodeToolBoss.CheckLFM(fPascalBuffer, fLFMBuffer, fLFMTree, - fRootMustBeClassInUnit, fRootMustBeClassInIntf, fObjectsMustExist) then - Result:=mrOk - else begin - Result:=FindAndFixMissingComponentClasses; - if Result = mrCancel then // Returns mrCancel when nothing was done. - Result := mrOK; - end; + else begin + Result:=FindAndFixMissingComponentClasses; // Can return mrRetry. + end; + Inc(LoopCount); // Increment also in outer loop + until (Result in [mrOK, mrAbort]) or (LoopCount=30); // Fix top offsets of some components in visual containers if (Result=mrOK) and (fSettings.CoordOffsMode=rsEnabled) then begin diff --git a/converter/usedunits.pas b/converter/usedunits.pas index f4a20f2709..6042eff59f 100644 --- a/converter/usedunits.pas +++ b/converter/usedunits.pas @@ -128,6 +128,7 @@ type function ConvertUsed: TModalResult; function Remove(aUnit: string): TModalResult; procedure MoveMissingToComment(aAllCommentedUnits: TStrings); + function AddUnitImmediately(aUnitName: string): Boolean; procedure AddUnitIfNeeded(aUnitName: string); function AddThreadSupport: TModalResult; public @@ -689,6 +690,15 @@ begin fImplUsedUnits.fMissingUnits.Clear; end; +function TUsedUnitsTool.AddUnitImmediately(aUnitName: string): Boolean; +begin + with fCTLink, fMainUsedUnits do begin + Result:=CodeTool.AddUnitToSpecificUsesSection(fUsesSection, aUnitName, '', SrcCache); + if not Result then exit; + Result:=SrcCache.Apply; + end; +end; + procedure TUsedUnitsTool.AddUnitIfNeeded(aUnitName: string); // Return True if the rename (target) value contains aUnitName. diff --git a/ide/checklfmdlg.pas b/ide/checklfmdlg.pas index a69aa2b542..a2b8b78e07 100644 --- a/ide/checklfmdlg.pas +++ b/ide/checklfmdlg.pas @@ -396,12 +396,15 @@ begin if not CheckUnit then exit; if CodeToolBoss.CheckLFM(fPascalBuffer,fLFMBuffer,fLFMTree, fRootMustBeClassInUnit,fRootMustBeClassInIntf,fObjectsMustExist) - then begin - Result:=mrOk; - exit; - end; + then + exit(mrOk); Result:=FindAndFixMissingComponentClasses; - if Result in [mrAbort,mrOk] then exit; + if Result=mrAbort then exit; + // check LFM again + if CodeToolBoss.CheckLFM(fPascalBuffer,fLFMBuffer,fLFMTree, + fRootMustBeClassInUnit,fRootMustBeClassInIntf,fObjectsMustExist) + then + exit(mrOk); WriteLFMErrors; Result:=ShowRepairLFMWizard; end; @@ -463,7 +466,7 @@ var RegComp: TRegisteredComponent; i: Integer; begin - Result:=mrCancel; + Result:=mrOK; MissingObjectTypes:=TStringList.Create; try // collect all missing object types @@ -496,15 +499,6 @@ begin // add units for the missing object types with registered component classes Result:=PackageEditingInterface.AddUnitDependenciesForComponentClasses( fPascalBuffer.Filename, aMissingTypes); - if Result<>mrOk then exit; - // check LFM again - if CodeToolBoss.CheckLFM(fPascalBuffer,fLFMBuffer,fLFMTree, - fRootMustBeClassInUnit,fRootMustBeClassInIntf,fObjectsMustExist) - then begin - Result:=mrOk; - end else begin - Result:=mrCancel; - end; end; function TLFMChecker.CheckUnit: boolean;