Here is a new feature for PwrDev..
It's now able to compile code like VB.NET or CSharp on demand fully in memory.
Also the assembly (dll) created remains in memory and PwrDev can use this assembly to create object instances from class inside this assembly.
See this topic which also provides an executable to test this feature:
--
This is a simple example of the PB code, note that ordinary PowerBASIC variants and dispatches are used.
No registering of any assembly is required to become a dispatch object (ActiveX).
It's now able to compile code like VB.NET or CSharp on demand fully in memory.
Also the assembly (dll) created remains in memory and PwrDev can use this assembly to create object instances from class inside this assembly.
See this topic which also provides an executable to test this feature:
--
This is a simple example of the PB code, note that ordinary PowerBASIC variants and dispatches are used.
No registering of any assembly is required to become a dispatch object (ActiveX).
Code:
[color=#0000FF]Local[/color] v [color=#0000FF]As[/color] [color=#0000FF]Variant[/color] [color=#0000FF]Local[/color] oAssembly [color=#0000FF]As[/color] [color=#0000FF]Dispatch[/color] [color=#0000FF]Local[/color] vClass1 [color=#0000FF]As[/color] [color=#0000FF]Variant[/color] [color=#0000FF]Local[/color] oClass1 [color=#0000FF]As[/color] [color=#0000FF]Dispatch[/color] [color=#0000FF]Local[/color] sCode [color=#0000FF]As[/color] [color=#0000FF]String[/color] [color=#0000FF]Local[/color] sError [color=#0000FF]As[/color] [color=#0000FF]String[/color] [color=#007F00]'-----------------------------------------------------------------------[/color] [color=#007F00]' Step 1, compile the CSharp code into an assembly.[/color] [color=#007F00]'-----------------------------------------------------------------------[/color] sCode = [color=#0000FF]VD_GetText[/color]( [color=#0000FF]nCbHndl[/color], [color=#7F007F]%ID_FORM1_TXTCSHARP[/color] ) [color=#007F00]' Note that multiple libraries need to be CrLf separated.[/color] [color=#0000FF]VD_CLR_AssemblyCompiler_CompileCSharp[/color]( sCode, "System.Data.dll", oAssembly, sError ) [color=#007F00]' Test if an assembly was created.[/color] [color=#0000FF]If[/color] [color=#0000FF]IsFalse[/color]( [color=#0000FF]IsObject[/color]( oAssembly ) ) [color=#0000FF]Then[/color] [color=#0000FF]MsgBox[/color] sError, [color=#7F007F]%MB_TASKMODAL[/color], VD_App.Title: [color=#0000FF]Exit[/color] [color=#0000FF]Function[/color] [color=#007F00]'-----------------------------------------------------------------------[/color] [color=#007F00]' Step 2, create a specific class found in the assembly.[/color] [color=#007F00]'-----------------------------------------------------------------------[/color] v = "Class1" [color=#0000FF]Object[/color] [color=#0000FF]Call[/color] oAssembly.CreateInstance( v ) [color=#0000FF]To[/color] vClass1 [color=#007F00]' Move the class1 object in the variant into a dispatch object.[/color] oClass1 = vClass1: vClass1 = [color=#0000FF]Empty[/color] [color=#007F00]' Unload the assembly, you may keep it alive if there are more classes to use.[/color] [color=#0000FF]Set[/color] oAssembly = [color=#0000FF]Nothing[/color] [color=#007F00]'-----------------------------------------------------------------------[/color] [color=#007F00]' Step 3, call a function in the class.[/color] [color=#007F00]'-----------------------------------------------------------------------[/color] [color=#0000FF]Object[/color] [color=#0000FF]Call[/color] oClass1.GetDateTime() [color=#0000FF]To[/color] v [color=#0000FF]MsgBox[/color] "Result: " & [color=#0000FF]Variant$[/color]( v ), [color=#7F007F]%MB_TASKMODAL[/color], [color=#0000FF]VD_App.Title[/color] [color=#007F00]' Unload the class[/color] [color=#0000FF]Set[/color] oClass1 = [color=#0000FF]Nothing[/color]
Comment