Search code examples
delphiformatargumentsfiremonkeydelphi-10.2-tokyo

Delphi 10.2 How do I get Log.d to ignore % in the HTML source code?


How do I get Log.d to ignore % in the HTML source code? Or tell Log.d not to format the code?

The HTML code I send to my program:

<input type="hidden" name="Mode" value="Search%20Statutes" />

The procedure I created:

procedure ThtmlParser.DebugText(ExtraStr, Str: string);
var
  CombineStrings: string;
begin
  CombineStrings := ExtraStr + Str;
  Log.d(CombineStrings);
  if Assigned(FOnDebug) then
  begin
     FOnDebug(CombineStrings);
  end;
end;

How I use it:

Target := '<input type="hidden" name="Mode" value="Search%20Statutes" />'
DebugText('Target: ', Target);

The error I'm getting:

First chance exception at $756C1812. Exception class EConvertError with message 'No argument for format 'Target: <input type="hidden" na''. Process htmlParserExample.exe (5168)

What I think is happening, that Log.d thinks the % in the HTML code is for formating when it is not.


Solution

  • Since Delphi is "looking for a format", I gave it a format to follow.

    I am not sure why Delphi's developing team would create a class procedure d(const Msg: string); overload; inline; and not let us use it? That is what got me confused. So instead, I used this instead:

    class procedure d(const Fmt: string; const Args: array of const); overload;
    

    Here is my new procedure that fixes my issue:

    procedure ThtmlParser.DebugText(ExtraStr, Str: string);
    var
      CombineStrings: string;
    begin
      CombineStrings := ExtraStr + Str;
      Log.d('%s',[CombineStrings]);
      if Assigned(FOnDebug) then
      begin
         FOnDebug(CombineStrings);
      end;
    end;