0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
El Diablo
  • 168
  • 1
  • 12

1 Answers1

1

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
El Diablo
  • 168
  • 1
  • 12
  • 2
    I would use `Log.d('%s%s', [ExtraStr, Str])` instead, and get rid of `CombineStrings`. You should also [file a bug report](https://quality.embarcadero.com) about the single-argument version of `Log.d()` misbehaving. It should not be formatting anything. – Remy Lebeau Jan 02 '19 at 00:07
  • 2
    @Remy, ElDiablo: `Log.d(Msg)` seems to call `Log.d(Msg, []);`. That is a mistake, indeed. It should be the other way around. Or it could call `Log.d('%s', [Msg]);`. That would be fine. – Rudy Velthuis Jan 02 '19 at 07:48
  • Was just notified that my report was a duplicate of https://quality.embarcadero.com/browse/RSP-20021 and that this is resolved in Delphi 10.3 Rio. – Rudy Velthuis Jan 02 '19 at 15:46