[JSCodeGen] Retrieve Class from String (Class Name)

Issue #251 new
Toky Olivier Razanakotonarivo created an issue

Hello,

Is it possibile please to retrieve a class from its class name?

I explain:

type 
  TMyClass = class

  end;
  TMyClassClass = class of TMyClass;

var cls: TMyClassClass;

cls := FindClass("TMyClass")

var c:= cls.Create();

Thank you so much.

Comments (2)

  1. Toky Olivier Razanakotonarivo reporter

    I can do like this

    type 
      TMyClass = class
    
      end;
      TMyClassClass = class of TMyClass;
    
    var cls: TMyClassClass;
    
    cls := FindClass("TMyClass")
    
    var c:= cls.Create();
    
    function FindClass(ClassName: String);
    begin
      asm @result = eval(@ClassName); end;
    end;
    

    It works but when the code is compiled with obfucation and minimization options, TMyClass name is changed to another shorter name like “T0” so eval(“TMyClass”) will not work.

  2. Toky Olivier Razanakotonarivo reporter

    Unless ther is an option {$ NoObfuscate} that I can put after class declaration so that class name is leaved as is.

  3. Log in to comment