Skip to content
Permalink
Browse files

use FormatString() when possible

  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Jul 12, 2019
1 parent 3b8004a commit 6d178823b6fa05fc66987d0b7a6df566f7475de7
@@ -894,7 +894,7 @@ procedure TDDDDaemon.ExecuteCommandLine(ForceRun: boolean);
B := pointer(GetNextLine(P,P));
if B=nil then
exit;
fn := format('%s%s.settings', [folder, GetNextItem(B, '=')]);
FormatString('%%.settings', [folder, GetNextItem(B, '=')], fn);
doc.InitJSONFromFile(fn, JSON_OPTIONS_FAST, true);
modified := false;
if doc.Count > 0 then
@@ -1842,7 +1842,7 @@ procedure TDDDMockedSocket.CheckRaiseException(Action: TDDDMockedSocketException
exit;
fExceptionActions := [];
if fExceptionMessage = '' then
fExceptionMessage := Format('Mocked Exception for %s', [ToText(Action)^]);
FormatString('Mocked Exception for %', [ToText(Action)^], fExceptionMessage);
if fExceptionClass = nil then
fExceptionClass := EDDDMockedSocket;
raise fExceptionClass.Create(fExceptionMessage);
@@ -2210,7 +2210,7 @@ function ECCAuthorize(aContent: TObject; aSecretDays: integer; const aSecretPass
privok, jsonok: boolean;
begin
with ExeVersion do
fileroot := SysUtils.LowerCase(format('%s@%s', [User, Host]));
fileroot := SysUtils.LowerCase(FormatString('%@%', [User, Host]));
if aSearchFolder = '' then
fileroot := ExeVersion.ProgramFilePath + fileroot else
fileroot := IncludeTrailingPathDelimiter(aSearchFolder) + fileroot;
@@ -279,7 +279,7 @@ function TDBFrame.NewCmdPopup(const c: string; NoCmdTrim: boolean): TMenuItem;
if cmd = '#log ' then
sub.Caption := sub.Caption + ' ' + res.Values[i].TimeStamp
else
sub.Caption := format('%s %s', [sub.Caption, KB(res.Values[i].Size)]);
sub.Caption := FormatString('% %', [sub.Caption, KB(res.Values[i].Size)]);
subpar.Add(sub);
end;
end
@@ -441,7 +441,7 @@ procedure TDBFrame.btnExecClick(Sender: TObject);
drwgrdResult.Options := drwgrdResult.Options - [goRowSelect];
drwgrdResult.Show;
mmoResult.OnGetLineAttr := mmoResult.JSONLineAttr;
mmoResult.Text := Format(#13#10' Returned %d row(s), as %s in %s',
mmoResult.Text := FormatString(#13#10' Returned % row(s), as % in %',
[table.RowCount, KB(fJson), execTime]);
end;
if Sender <> nil then begin
@@ -109,8 +109,8 @@ function AskForUserIfVoid(Definition: TDDDRestClientSettings): boolean;
begin
result := false;
if Definition.ORM.User = '' then
if TLoginForm.Login(Application.Mainform.Caption, Format('Credentials for %s',
[Definition.ORM.ServerName]), U, P, true, '') then begin
if TLoginForm.Login(Application.Mainform.Caption, FormatString(
'Credentials for %', [Definition.ORM.ServerName]), U, P, true, '') then begin
Definition.ORM.User := StringToUTF8(U);
Definition.ORM.PasswordPlain := StringToUTF8(P);
end
@@ -346,7 +346,7 @@ function TAdminControl.AddDBFrame(const aCaption, aDatabaseName: RawUTF8;
n := length(fDBFrame);
SetLength(fDBFrame, n + 1);
result := aClass.Create(self);
result.Name := format('DBFrame%s', [aCaption]);
result.Name := FormatString('DBFrame%', [aCaption]);
result.Parent := page;
result.Align := alClient;
result.Client := fClient;
@@ -444,7 +444,7 @@ procedure TAdminControl.SaveOrExport(Fmt: TAdminSaveOrExport;
end;
if PropNameValid(pointer(db.GridLastTableName)) then
name := db.GridLastTableName;
fDlgSave.FileName := SysUtils.Trim(Format('%s %s %s',
fDlgSave.FileName := SysUtils.Trim(FormatString('% % %',
[ContextName, name, NowToString(false)]));
if not fDlgSave.Execute then
exit;
@@ -487,7 +487,7 @@ procedure TAdminForm.FormCreate(Sender: TObject);
begin
DefaultFont.Name := 'Tahoma';
DefaultFont.Size := 9;
Caption := Format('%s %s', [ExeVersion.ProgramName, ExeVersion.Version.Detailed]);
Caption := FormatString('% %', [ExeVersion.ProgramName, ExeVersion.Version.Detailed]);
fFrame := TAdminControl.Create(self);
fFrame.Parent := self;
fFrame.Align := alClient;
@@ -497,7 +497,7 @@ procedure TAdminForm.FormCreate(Sender: TObject);
procedure TAdminForm.FormShow(Sender: TObject);
begin
fFrame.Show;
Caption := Format('%s - %s %s via %s', [ExeVersion.ProgramName,
Caption := FormatString('% - % % via %', [ExeVersion.ProgramName,
fFrame.State.daemon, fFrame.State.version, fFrame.fDefinition.ORM.ServerName]);
end;

@@ -102,9 +102,9 @@ begin
TaskEx.DialogIcon := tiQuestion;
TaskEx.OnButtonClicked := TCallBack.TaskDialogButtonClicked;
TaskEx.Execute;
ShowMessage(Format('User=%s Password=%s',[aUserName,aPassword]),
ShowMessage(FormatString('User=% Password=%',[aUserName,aPassword]),
not TLoginForm.Login('Title','Please login',aUserName,aPassWord,true,''));
ShowMessage(Format('User=%s Password=%s',[aUserName,aPassword]),
ShowMessage(FormatString('User=% Password=%',[aUserName,aPassword]),
not TLoginForm.Login('Title','Please login again',aUserName,aPassWord,true,''));
end;

if aErrorMessage='' then
result := true else begin
if invalidField>=0 then
aErrorMessage := Format('"%s": %s',
aErrorMessage := FormatString('"%": %',
[RecordProps.Fields.List[invalidField].GetNameDisplay,aErrorMessage]);
result := false;
end;
@@ -1622,7 +1622,7 @@ procedure SetCurrentPrinterAsDefault;
if Driver[0] = #0 then
if not GetDriverForPrinter(Device, Driver) then
exit; // oops !
DefaultPrinter := format('%s,%s,%s',[Device, Driver, Port]);
DefaultPrinter := FormatString('%,%,%',[Device, Driver, Port]);
WriteProfileString( 'windows', 'device', pointer(DefaultPrinter) );
Device := 'windows';
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, PtrInt(@Device));
@@ -1673,7 +1673,7 @@ function CurrentPrinterPaperSize: string;
end;
end;
if result = '' then
result := format('Custom (%d x %dmm)',[cx, cy]);
result := FormatString('Custom (% x %mm)',[cx, cy]);
end;
end;

@@ -1286,7 +1286,7 @@ function TSQLRestServerDB.EngineExecute(const aSQL: RawUTF8): boolean;
procedure TSQLRestServerDB.InternalInfo(var info: TDocVariantData);
begin
inherited InternalInfo(info);
info.AddValue('db', Format('%s %s', [ExtractFileName(DB.FileName), KB(DB.FileSize)]));
info.AddValue('db', FormatString('% %', [ExtractFileName(DB.FileName), KB(DB.FileSize)]));
end;

procedure TSQLRestServerDB.InternalStat(Ctxt: TSQLRestServerURIContext; W: TTextWriter);
@@ -1527,7 +1527,7 @@ procedure SynDaemonIntercept(log: TSynLog);

function RunUntilSigTerminatedPidFile: TFileName;
begin
result := format('%s.%s.pid', [ExeVersion.ProgramFilePath, ExeVersion.ProgramName]);
result := FormatString('%.%.pid', [ExeVersion.ProgramFilePath, ExeVersion.ProgramName]);
end;

function RunUntilSigTerminatedForKill(waitseconds: integer): boolean;
@@ -1719,7 +1719,7 @@ function TSynDaemonSettings.ServiceDescription: string;
if versionnumber <> '' then
result := result + ' ' + versionnumber;
if CompanyName <> '' then
result := format('%s - (c)%d %s', [result, BuildYear, CompanyName]);
result := FormatString('% - (c)% %', [result, BuildYear, CompanyName]);
end;
end;

@@ -3001,8 +3001,7 @@ procedure TSQLRibbon.CreateReport(aTable: TSQLRecordClass; aID: TID;
if (aID>0) and (Caption='') then
Caption := U2S(Client.MainFieldValue(aTable,aID,true));
Font.Size := 9;
AddPagesToFooterAt(
format('%s - %s %s',[sPageN,aTable.CaptionName,Caption]),LeftMargin);
AddPagesToFooterAt(FormatString('% - % %',[sPageN,aTable.CaptionName,Caption]),LeftMargin);
Font.Size := 10;
P := GetPage(aTable);
if (P<0) or (aID<=0) then
@@ -1386,7 +1386,7 @@ function i18nAddLanguageItems(MsgPath: TFileName; List: TStrings): integer;
continue;
if index=CurrentLanguage.Index then
result := List.Count; // current language selection
List.AddObject(format('%s (%s)',[LanguageName(index),LanguageAbr[index]]),
List.AddObject(FormatString('% (%)',[LanguageName(index),LanguageAbr[index]]),
pointer(index));
end;
end;
@@ -1613,7 +1613,7 @@ procedure TWebSocketProtocolRest.ProcessIncomingFrame(Sender: TWebSocketProcess;
end;
except
on E: Exception do
fLastError := Format('%s [%s]',[E.ClassName,E.Message]);
FormatString('% [%]',[E.ClassName,E.Message],fLastError);
end else
if (Sender.fIncoming.AnswerToIgnore>0) and (FrameData(request,'answer')<>nil) then begin
Sender.fIncoming.AnswerToIgnore(-1);
@@ -5714,7 +5714,7 @@ function TSynLogFileView.GetLineForMemo(aRow,aTop,aBottom: integer): string;
DateTimeToString(tim,TIME_FORMAT,elapsed);
result := tim+'.'+result;
end;
result := format('%d lines - time elapsed: %s',[aBottom-aTop+1,result]);
result := FormatString('% lines - time elapsed: %',[aBottom-aTop+1,result]);
end;
end;
end;
@@ -5727,8 +5727,8 @@ function TSynLogFileView.GetLineForClipboard(aRow: integer): string;
aRow := fSelected[aRow];
if cardinal(aRow)<cardinal(fCount) then begin
dt := EventDateTime(aRow);
result := Format('%s %s'#9'%s'#9,[DateToStr(dt),FormatDateTime(TIME_FORMAT,dt),
LogInfoCaption[EventLevel[aRow]]]);
FormatString('% %'#9'%'#9,[DateToStr(dt),FormatDateTime(TIME_FORMAT,dt),
LogInfoCaption[EventLevel[aRow]]],result);
if fThreads<>nil then
result := result+IntToString(cardinal(fThreads[aRow]))+#9;
result := result+EventString(aRow,' ');
@@ -2445,9 +2445,9 @@ procedure EnhancedTest;
for i := 0 to high(aStatus) do
if TOleDBBindStatus(aStatus[i])<>bsOK then begin
if aStatus[i]<=cardinal(high(TOleDBBindStatus)) then
s := Format('%s Status[%d]="%s"',[s,i,
s := FormatString('% Status[%]="%"',[s,i,
GetCaptionFromEnum(TypeInfo(TOleDBBindStatus),aStatus[i])]) else
s := Format('%s Status[%d]=%d',[s,i,aStatus[i]]);
s := FormatString('% Status[%]=%',[s,i,aStatus[i]]);

end;
if s<>'' then
@@ -2888,7 +2888,7 @@ function TOleDBMSSQLConnectionProperties.MSOnCustomError(Connection: TOleDBConne
if pwszProcedure<>nil then
tmp := UnicodeBufferToString(pwszProcedure) else
tmp := 'Error '+IntToStr(lNative);
Connection.fOleDBErrorMessage := Format('%s %s (line %d): %s',
Connection.fOleDBErrorMessage := FormatString('% % (line %): %',
[Connection.fOleDBErrorMessage,tmp,wLineNumber,msg]);
end;
finally
@@ -827,7 +827,7 @@ procedure TSynTestCase.NotifyTestSpeed(const ItemName: string;
FormatString('% % in % i.e. %/s, aver. %', [ItemCount,ItemName,Temp.Stop,
IntToThousandString(Temp.PerSec(ItemCount)),Temp.ByCount(ItemCount)], msg);
if SizeInBytes>0 then
msg := format('%s, %s/s',[msg,KB(Temp.PerSec(SizeInBytes))]);
msg := FormatString('%, %/s',[msg,KB(Temp.PerSec(SizeInBytes))]);
AddConsole(msg);
end;

@@ -1 +1 @@
'1.18.5265'
'1.18.5266'

3 comments on commit 6d17882

@edwinyzh

This comment has been minimized.

Copy link
Contributor

replied Jul 12, 2019

This commit will cause the following compiler error under xe4:

[dcc32 Error] dddInfraApps.pas(902): E2250 There is no overloaded version of 'FormatString' that can be called with these arguments

Note the 902 line number is only accurate when compiling the latest commit: 6917c05 but I believe it's this commit that caused the compiler error.

@synopse

This comment has been minimized.

Copy link
Owner

replied Jul 12, 2019

should be Fixed now - fixed Delphi compilation (FPC was fine with it)

@edwinyzh

This comment has been minimized.

Copy link
Contributor

replied Jul 12, 2019

I confirm it's fixed with this commit (100d8c5), thanks ab!

Please sign in to comment.
You can’t perform that action at this time.