How call static method from .NET DLL from Delphi using jedi/jcl

138 Views Asked by At

i do not want create a tlb, update the references, etc, so i am load .net dll in runtime, i can call and use class and methods non static like that:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Host: TJclClrHost;
      Obj: OleVariant;
      result: string
    begin
        Host := TJclClrHost.Create('v4.0.30319');
        Host.Start();
        Obj := Host.DefaultAppDomain
            .CreateInstance('DLLNAME',
            'NAMESPACE.INSIDE.CLASS.THAT.I.WANT')
            .UnWrap();
    
         result:=  Obj4.<MethodName>(Parameters...);

....

end;

and that work wonders for non static methods....static methods i cant figure how do that using JEDI/jcl

how i call a static class/method from delphi using jed/jcl or if there is another way to do that in runtime fell free to tell me, I just do not want have to make references, generate tlbs etc, just put the dll in the folder and use.

exemple of static class in the dll .net:

using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;

namespace DLLSTATIC.SOMESUBNAME
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("DLLSTATIC.SOMESUBNAME.staticclass")]
    public static class staticclass
    {
        [ComVisible(true)]
        public static string test123(string param)
        {
                return "test1234";
        }
  }
}

ps. i am declaring com visible but i will not use this dll as COM

1

There are 1 best solutions below

0
KngStr On

I don't like the com and tlb.

You can also call .net dll at runtime by using DDNRuntime(Delphi .NET Framework/.NET Core Runtime)

https://github.com/ying32/DDNRuntime-examples

It can help you call .net fuctions easily

Just like

function CreateMainForm(): DNForm;
var
  LButton: DNButton;
  LR: DNRectangle;
  //LEdit: DNTextBox;
begin
  LR := TDNScreen.DNClass.PrimaryScreen.Bounds;

  Result := TDNForm.Create;
  Result.Text := 'Delphi .NET Runtime';

  LButton := TDNButton.Create;
  LButton.Text := 'Hello';
  LButton.add_Click(TEventClass.OnButtonClick);
  LButton.Location := TDNPoint.DNClass.init(100, 100);
  Result.Controls.Add(LButton);

  //Result.StartPosition := DNFormStartPosition.Manual;
  Result.StartPosition := DNFormStartPosition.CenterScreen;
  //Result.Location :=  TDNPoint.DNClass.init((LR.Width - Result.Width) div 2, (LR.Height - Result.Height) div 2);
end;