Handling of the Cardinal types in format string for Logging

Issue #40 resolved
Former user created an issue

Hi, Stefan!

I have the following issue: If I call Logging.LogMessage('%d', [X]) where X is of type Cardinal then I get empty string because of the reason described in the code below. Should i just explicitly cast it to Integer? That looks a bit weird.. So Logging.LogMessage('%d', [Integer(X)]) works fine. Int64 is not supported as well.

ZB.

program Project1;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  DSharp.Logging,
  DSharp.Logging.Console;

procedure TestOK(AValue: Integer = 1);
begin
  Logging.LogMessage('%d', [AValue]);
end;

procedure TestFail(AValue: Cardinal = 1);
begin
  Logging.LogMessage('%d', [AValue]);
end;

begin
  TestOK(1); //INFO: 1

  { The TValue is tkInt64 which is not supported by DSharp.Core.Reflection.TValueHelper.ToVarRec }

  TestFail(1); //INFO:

  Readln;
end.

Comments (3)

  1. Former user Account Deleted

    Also if there are tow params like [1, X] then the text is ToVarRecs returns the 1 as the value for the second parameter (because the value is left in the stack and result is not assigned). TValueHelper.ToVarRec: TVarRec -> the return value might be undefined there (will be just the value from the stack :) ).

  2. Former user Account Deleted

    Adding this solves the issue:

    tkInt64:
      begin
        Result.VType := vtInt64;
        Result.VInt64 := GetReferenceToRawData;
      end;
    

    And in Berlin at least there is a method TValue.AsVarRec (which already does that in System.Rtti) so maybe it makes sense to use on base of IFDEF?

  3. Log in to comment