[fpc-pascal] Generated names in specialized classes are weird in Free Pascal

silvioprog silvioprog at gmail.com
Tue Dec 23 15:52:33 CET 2014


Hello,

Recently I've made a class to generate error log for codes in Delphi and
Free Pascal. It works capturing the class name where the problem occurred,
adding the date/time concatenated with the error message. It's working
perfectly in Delphi.

The problem is in Free Pascal and in your approach to save the name of
specialized classes. They are very weird names and a little intuitive. For
example:

TFoo$1$crcB96581A6

Assuming the small code below is my log generator, see the output generated
by Delphi code:

program Project1;

{$APPTYPE CONSOLE}

uses
  System.SysUtils;

type
  TTest = class(TObject)
  end;

  TFoo<T> = class(TObject)
  public
    class procedure Log(AClass: System.TClass);
  end;

  TBar1 = TFoo<TTest>; // short declaration

  TBar2 = class(TFoo<TTest>) // full declaration
  end;

  class procedure TFoo<T>.Log(AClass: System.TClass);
  begin
    System.WriteLn('[', System.SysUtils.FormatDateTime('hh:nn:ss.zzz',
      System.SysUtils.Now), ']: ', AClass.ClassName);
  end;

begin
  TFoo<TTest>.Log(TBar1);
  TFoo<TTest>.Log(TBar2.ClassParent);
  System.ReadLn;
end.

Output:

[06:27:08.545]: TFoo<Project1.TTest>
[06:27:08.546]: TFoo<Project1.TTest>

Now, see the same output for a Free Pascal code:

program Project1;

{$mode delphi}

uses
  SysUtils;

type
  TTest = class(TObject)
  end;

  TFoo<T> = class(TObject)
  public
    class procedure Log(AClass: System.TClass);
  end;

  TBar1 = TFoo<TTest>; // short declaration

  TBar2 = class(TFoo<TTest>) // full declaration
  end;

  class procedure TFoo<T>.Log(AClass: System.TClass);
  begin
    System.WriteLn('[', SysUtils.FormatDateTime('hh:nn:ss.zzz',
      SysUtils.Now), ']: ', AClass.ClassName);
  end;

begin
  TFoo<TTest>.Log(TBar1);
  TFoo<TTest>.Log(TBar2.ClassParent);
  System.ReadLn;
end.

Output:

[06:27:08.545]: TFoo$1$crcB96581A6
[06:27:08.545]: TFoo$1$crcB96581A6

It is very weird this generated class names. The Free Pascal will continue
to use these weird names or there are plans to improve this in future
versions? With names like that is almost impossible to create automated
error logs structures with Free Pascal.

Thank you!

-- 
Silvio Cl├ęcio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20141223/340b0856/attachment.html>


More information about the fpc-pascal mailing list