Converter: Respect the "use same dfm" setting properly + clean RenameResourceDirectives code

git-svn-id: trunk@30510 -
This commit is contained in:
juha 2011-04-30 13:33:25 +00:00
parent 6befebb2f4
commit e002cb4bc6

View File

@ -79,8 +79,6 @@ type
fHasFormFile: boolean; fHasFormFile: boolean;
fLowerCaseRes: boolean; fLowerCaseRes: boolean;
fAddUnitEvent: TAddUnitEvent; fAddUnitEvent: TAddUnitEvent;
fDfmDirectiveStart: integer;
fDfmDirectiveEnd: integer;
// Delphi Function names to replace with FCL/LCL functions. // Delphi Function names to replace with FCL/LCL functions.
fDefinedProcNames: TStringList; fDefinedProcNames: TStringList;
// List of TFuncReplacement. // List of TFuncReplacement.
@ -254,12 +252,8 @@ var
ParamPos, ACleanPos: Integer; ParamPos, ACleanPos: Integer;
Key, LowKey, NewKey: String; Key, LowKey, NewKey: String;
s: string; s: string;
AlreadyIsLfm: Boolean;
begin begin
Result:=false; Result:=false;
AlreadyIsLfm:=false;
fDfmDirectiveStart:=-1;
fDfmDirectiveEnd:=-1;
ACleanPos:=1; ACleanPos:=1;
// find $R directive // find $R directive
with fCTLink.CodeTool do with fCTLink.CodeTool do
@ -277,38 +271,34 @@ begin
if (LowKey='dfm') or (LowKey='xfm') then begin if (LowKey='dfm') or (LowKey='xfm') then begin
if fCTLink.Settings.SupportDelphi then begin if fCTLink.Settings.SupportDelphi then begin
// Use the same dfm file. Lowercase existing key. // Use the same dfm file. Lowercase existing key.
if fCTLink.Settings.SameDfmFile and (Key<>LowKey) then if fCTLink.Settings.SameDfmFile then begin
if Key<>LowKey then
NewKey:=LowKey; NewKey:=LowKey;
// Later IFDEF will be added so that Delphi can still use .dfm.
fDfmDirectiveStart:=ACleanPos;
fDfmDirectiveEnd:=ParamPos+6;
end end
else // Change .dfm to .lfm. else begin
NewKey:='lfm';
end
// If there already is .lfm, prevent adding IFDEF for .dfm / .lfm.
else if LowKey='lfm' then
AlreadyIsLfm:=true
// lowercase {$R *.RES} to {$R *.res}
else if (Key='RES') and fLowerCaseRes then
NewKey:=LowKey;
// Now change code.
if NewKey<>'' then
if not fCTLink.SrcCache.Replace(gtNone,gtNone,ParamPos+2,ParamPos+5,NewKey) then exit;
end;
ACleanPos:=FindCommentEnd(Src, ACleanPos, Scanner.NestedComments);
until false;
// if there is already .lfm file, don't add IFDEF for .dfm / .lfm.
if fCTLink.Settings.SupportDelphi and (fDfmDirectiveStart<>-1)
and not AlreadyIsLfm then begin
// Add IFDEF for .lfm and .dfm allowing Delphi to use .dfm. // Add IFDEF for .lfm and .dfm allowing Delphi to use .dfm.
s:='{$IFNDEF FPC}'+LineEnding+ s:='{$IFNDEF FPC}'+LineEnding+
' {$R *.dfm}'+LineEnding+ ' {$R *.dfm}'+LineEnding+
'{$ELSE}'+LineEnding+ '{$ELSE}'+LineEnding+
' {$R *.lfm}'+LineEnding+ ' {$R *.lfm}'+LineEnding+
'{$ENDIF}'; '{$ENDIF}';
Result:=fCTLink.SrcCache.Replace(gtNone,gtNone,fDfmDirectiveStart,fDfmDirectiveEnd,s); Result:=fCTLink.SrcCache.Replace(gtNone,gtNone,ACleanPos,ParamPos+6,s);
end; end;
end
else // Change .dfm to .lfm.
NewKey:='lfm';
end
// lowercase {$R *.RES} to {$R *.res}
else if (Key='RES') and fLowerCaseRes then
NewKey:=LowKey;
// Change a single resource name.
if NewKey<>'' then begin
if not fCTLink.SrcCache.Replace(gtNone,gtNone,ParamPos+2,ParamPos+5,NewKey) then
exit;
end;
end;
ACleanPos:=FindCommentEnd(Src, ACleanPos, Scanner.NestedComments);
until false;
Result:=true; Result:=true;
end; end;