Converter: Add unit name required by a replaced function call to uses section.

git-svn-id: trunk@28971 -
This commit is contained in:
juha 2011-01-12 12:45:02 +00:00
parent f4ecc0e4f7
commit b1cd52fbed
4 changed files with 21 additions and 0 deletions

View File

@ -81,6 +81,7 @@ type
fCTLink: TCodeToolLink;
fHasFormFile: boolean;
fLowerCaseRes: boolean;
fAddUnitEvent: TAddUnitEvent;
fDfmDirectiveStart: integer;
fDfmDirectiveEnd: integer;
// Delphi Function names to replace with FCL/LCL functions.
@ -105,6 +106,7 @@ type
public
property HasFormFile: boolean read fHasFormFile write fHasFormFile;
property LowerCaseRes: boolean read fLowerCaseRes write fLowerCaseRes;
property AddUnitEvent: TAddUnitEvent read fAddUnitEvent write fAddUnitEvent;
end;
@ -510,6 +512,9 @@ begin
FuncInfo.StartPos, FuncInfo.EndPos, NewFunc) then exit;
IDEMessagesWindow.AddMsg('Replaced call '+s, '', -1);
IDEMessagesWindow.AddMsg(' with '+NewFunc, '', -1);
// Add the required unit name to uses section if needed.
if Assigned(AddUnitEvent) and (FuncInfo.UnitName<>'') then
AddUnitEvent(FuncInfo.UnitName);
end;
end;
finally

View File

@ -635,6 +635,7 @@ begin
try
ConvTool.LowerCaseRes:=FileExistsUTF8(ChangeFileExt(fLazUnitFilename, '.res'));
ConvTool.HasFormFile:=DfmFilename<>'';
ConvTool.AddUnitEvent:=@fUsedUnitsTool.AddUnitIfNeeded;
Result:=ConvTool.Convert;
if Result<>mrOk then exit;
finally

View File

@ -9,6 +9,8 @@ uses
type
TAddUnitEvent = procedure(AUnitName: string) of object;
{ TopOffset }
// Used when fixing top coordinates of controls inside a visual container.

View File

@ -123,6 +123,7 @@ type
function Prepare: TModalResult;
function Convert: TModalResult;
procedure MoveMissingToComment(AAllCommentedUnits: TStrings);
procedure AddUnitIfNeeded(AUnitName: string);
public
property MainUsedUnits: TUsedUnits read fMainUsedUnits;
property ImplUsedUnits: TUsedUnits read fImplUsedUnits;
@ -598,6 +599,18 @@ begin
fImplUsedUnits.MissingUnits.Clear;
end;
procedure TUsedUnitsTool.AddUnitIfNeeded(AUnitName: string);
var
i: Integer;
begin
if not ( fMainUsedUnits.fExistingUnits.Find(AUnitName, i) or
fImplUsedUnits.fExistingUnits.Find(AUnitName, i) or
fMainUsedUnits.fUnitsToAddForLCL.Find(AUnitName, i) ) then begin
fMainUsedUnits.fUnitsToAddForLCL.Add(AUnitName);
IDEMessagesWindow.AddMsg('Added unit '+AUnitName+ ' to uses section', '', -1);
end;
end;
function TUsedUnitsTool.GetMissingUnitCount: integer;
begin
Result:=fMainUsedUnits.MissingUnits.Count+fImplUsedUnits.MissingUnits.Count;