Converter: Remove invalid properties also after replacing a component type. Issue #24527

git-svn-id: trunk@41619 -
This commit is contained in:
juha 2013-06-09 10:05:20 +00:00
parent e06985f2bd
commit 01807a29cd
3 changed files with 42 additions and 35 deletions

View File

@ -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

View File

@ -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.

View File

@ -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;