From 54d8f2bdb13c91637766e605b6254fdc32220c3e Mon Sep 17 00:00:00 2001 From: mattias Date: Sun, 2 Apr 2023 20:16:14 +0200 Subject: [PATCH] IDE: moved CTSafeFormat to avoid nameclash with fpc 3.3.1 SafeFormat --- components/codetools/fileprocs.pas | 19 +++++++++++++++++++ components/pas2js/pjsdsgnoptions.pas | 8 ++++---- components/pas2js/pjsdsgnoptsframe.pas | 5 +++-- components/pas2js/strpas2jsdesign.pp | 20 -------------------- ide/initialsetupproc.pas | 24 ++---------------------- 5 files changed, 28 insertions(+), 48 deletions(-) diff --git a/components/codetools/fileprocs.pas b/components/codetools/fileprocs.pas index 45b946d57a..6b9f1c2360 100644 --- a/components/codetools/fileprocs.pas +++ b/components/codetools/fileprocs.pas @@ -144,6 +144,7 @@ function CfgStrToDate(const s: string; out Date: TDateTime; const aFormat: strin procedure CTIncreaseChangeStamp(var ChangeStamp: integer); inline; procedure CTIncreaseChangeStamp64(var ChangeStamp: int64); inline; +function CTSafeFormat(const Fmt: String; const Args: Array of const): String; // on exception use SimpleFormat function SimpleFormat(const Fmt: String; const Args: Array of const): String; // misc @@ -268,6 +269,24 @@ begin LazFileCache.LUIncreaseChangeStamp64(ChangeStamp); end; +function CTSafeFormat(const Fmt: String; const Args: array of const): String; +begin + // try with translated resourcestring + try + Result:=Format(Fmt,Args); + exit; + except + on E: Exception do + debugln(['ERROR: SafeFormat: ',E.Message]); + end; + // translation didn't work + // ToDo: find out how to get the resourcestring default value + //ResetResourceTables; + + // use a safe fallback + Result:=SimpleFormat(Fmt,Args); +end; + function SimpleFormat(const Fmt: String; const Args: array of const): String; var Used: array of boolean; diff --git a/components/pas2js/pjsdsgnoptions.pas b/components/pas2js/pjsdsgnoptions.pas index 8f6708de42..84bbc69fb5 100644 --- a/components/pas2js/pjsdsgnoptions.pas +++ b/components/pas2js/pjsdsgnoptions.pas @@ -14,7 +14,7 @@ uses // LazUtils LazFileCache, LazConfigStorage, LazFileUtils, FileUtil, // Codetools - DefineTemplates, + DefineTemplates, FileProcs, // IdeIntf MacroIntf, BaseIDEIntf; @@ -158,15 +158,15 @@ begin exit(false); end; if not FileExistsCached(Filename) then begin - Msg:=SafeFormat(pjsdFileNotFound, [Filename]); + Msg:=CTSafeFormat(pjsdFileNotFound, [Filename]); exit(false); end; if not DirPathExistsCached(ExtractFilePath(Filename)) then begin - Msg:=SafeFormat(pjsdDirectoryNotFound, [ExtractFilePath(Filename)]); + Msg:=CTSafeFormat(pjsdDirectoryNotFound, [ExtractFilePath(Filename)]); exit(false); end; if not FileIsExecutable(Filename) then begin - Msg:=SafeFormat(pjsdFileNotExecutable, [Filename]); + Msg:=CTSafeFormat(pjsdFileNotExecutable, [Filename]); exit(false); end; ShortFile:=ExtractFileNameOnly(Filename); diff --git a/components/pas2js/pjsdsgnoptsframe.pas b/components/pas2js/pjsdsgnoptsframe.pas index ceee8b6c02..b5b7d32d9b 100644 --- a/components/pas2js/pjsdsgnoptsframe.pas +++ b/components/pas2js/pjsdsgnoptsframe.pas @@ -18,7 +18,8 @@ uses // IdeIntf IDEOptionsIntf, IDEOptEditorIntf, IDEUtils, IDEDialogs, // Pas2Js - PJSDsgnOptions, strpas2jsdesign, PJSController, SimpleWebSrvOptionsFrame; + PJSDsgnOptions, strpas2jsdesign, PJSController, SimpleWebSrvOptionsFrame, + FileProcs; Type { TPas2jsOptionsFrame } @@ -204,7 +205,7 @@ begin FDialog := ADialog; DefPas2jsExe:=GetStandardPas2jsExe; - Pas2jsPathLabel.Caption:=SafeFormat(pjsdPathOfXMacroPas2js, ['pas2js'+GetExeExt]); + Pas2jsPathLabel.Caption:=CTSafeFormat(pjsdPathOfXMacroPas2js, ['pas2js'+GetExeExt]); Pas2jsPathLabel.Hint:=Format( pjsdYouCanUseIDEMacrosLikeMakeExeWithoutAFullPathIsSea, [DefPas2jsExe]); Pas2jsPathBrowseButton.Hint:=pjsdBrowse; diff --git a/components/pas2js/strpas2jsdesign.pp b/components/pas2js/strpas2jsdesign.pp index 8498106c97..ee2ffbbf48 100644 --- a/components/pas2js/strpas2jsdesign.pp +++ b/components/pas2js/strpas2jsdesign.pp @@ -128,27 +128,7 @@ Resourcestring pjsRefreshAllClassesFromHTML = 'Refresh all classes from HTML source'; rsHTTPRequestFailed = 'HTML request to service URL %s failed: %s'; -function SafeFormat(const Fmt: String; const Args: Array of const): String; - implementation -function SafeFormat(const Fmt: String; const Args: array of const): String; -begin - // try with translated resourcestring - try - Result:=Format(Fmt,Args); - exit; - except - on E: Exception do - debugln(['ERROR: SafeFormat: ',E.Message]); - end; - // translation didn't work - // ToDo: find out how to get the resourcestring default value - //ResetResourceTables; - - // use a safe fallback - Result:=SimpleFormat(Fmt,Args); -end; - end. diff --git a/ide/initialsetupproc.pas b/ide/initialsetupproc.pas index 25a7fe8ace..d191ce7145 100644 --- a/ide/initialsetupproc.pas +++ b/ide/initialsetupproc.pas @@ -134,8 +134,6 @@ function GetValueFromPrimaryConfig(OptionFilename, Path: string): string; function GetValueFromSecondaryConfig(OptionFilename, Path: string): string; function GetValueFromIDEConfig(OptionFilename, Path: string): string; -function SafeFormat(const Fmt: String; const Args: Array of const): String; - implementation function CheckLazarusDirectoryQuality(ADirectory: string; @@ -389,7 +387,7 @@ begin i:=CfgCache.IndexOfUsedCfgFile; if i<0 then begin - Note:=SafeFormat(lisCompilerCfgIsMissing,['fpc.cfg']); + Note:=CTSafeFormat(lisCompilerCfgIsMissing,['fpc.cfg']); exit; end; if not CfgCache.HasPPUs then @@ -649,7 +647,7 @@ begin i:=CfgCache.IndexOfUsedCfgFile; if i<0 then begin - Note:=SafeFormat(lisCompilerCfgIsMissing,['pas2js.cfg']); + Note:=CTSafeFormat(lisCompilerCfgIsMissing,['pas2js.cfg']); exit; end; //if not CheckPas('classes') then exit; @@ -1072,24 +1070,6 @@ begin end; end; -function SafeFormat(const Fmt: String; const Args: array of const): String; -begin - // try with translated resourcestring - try - Result:=Format(Fmt,Args); - exit; - except - on E: Exception do - debugln(['ERROR: SafeFormat: ',E.Message]); - end; - // translation didn't work - // ToDo: find out how to get the resourcestring default value - //ResetResourceTables; - - // use a safe fallback - Result:=SimpleFormat(Fmt,Args); -end; - { TSDFileInfoList } function TSDFileInfoList.AddNewItem(aFilename, aCaption: string): TSDFileInfo;