Announcement

Collapse
No announcement yet.

PwrDev - Use .NET as scriptengine

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PwrDev - Use .NET as scriptengine

    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).
    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]
    Last edited by Edwin Knoppert; 27 Mar 2008, 05:36 PM.
    hellobasic

  • #2
    That certainly raises the bar. :goldcup:

    Edwin, you have a vision for a top notch extension (beyond just a GUI designer) for PowerBASIC. It's nice to see the use of PowerBASIC in areas not ventured before.


    John

    Comment


    • #3
      Edwin,

      You should really consider to offer a trial version that would help people take their decision, without it, it is like shooting in the dark.

      And while speaking of that, i would strongly urge third party who have already a trial version, to make sure it works on VISTA !!!

      Last edited by Patrice Terrier; 30 Mar 2008, 12:01 PM.
      Patrice Terrier
      www.zapsolution.com
      www.objreader.com
      Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

      Comment


      • #4
        No demo, Vista=Yes

        Thanks... hmm thinking... in a few months the price may go up.
        The last months i have implemented so much (i yet have to describe in the help..) + i have strong ideas to extend PwrDev with .NET assemblies/code.

        .NET is here to stay and the abilities are awesome.
        Combining PowerBASIC code with .NET is no problem, as you can see above.
        Write a simple wrapper class, compile it to an assembly and treat it as a static link library since PwrDev handles loading assemblies from memory fine.
        (No execution from a tempfile or sort of)

        SOAP
        GDIPLUS
        HTTP
        ADO.NET (OleDB/T-SQL etc)
        MDA and other encryptions

        Etc etc..
        hellobasic

        Comment


        • #5
          Edwin,

          Your a great programmer and visonary. I can't say the same for your marketing skills but that's okay if all your into this for is a new motor bike once in awhile.

          I see a great fit if you and PowerBASIC were to work together. They need a .NET solution and you seem to be well on your way. I think this would be a win/win/win for everyone. (you, PB and the customer base)

          Both products start with Power (pwr) so that has to be a good sign.

          Anyways, I hope you and Bob at least talk about it.

          John

          Comment


          • #6
            Just out of curiousity Edwin, I gather you're using the ICodeCompiler interface and then setting the ComVisible attribute so that PB sees it as a COM object?
            Mike Stefanik
            sockettools.com

            Comment


            • #7
              Originally posted by Mike Stefanik View Post
              Just out of curiousity Edwin, I gather you're using the ICodeCompiler interface and then setting the ComVisible attribute so that PB sees it as a COM object?
              Not at all.. (i don't recognize me using the ICodeCompiler interface, ComVisible attribute is not required)

              Implementing .net (without all kinds of com hassle) is actually very easy.
              It's just waiting for someone figuring it out as well.

              I suspect people like Jose may come up with it some day soon.
              Just a matter of time.
              At this time it's a commercial part of PwrDev.

              Good luck.
              Last edited by Edwin Knoppert; 1 Apr 2008, 04:55 AM.
              hellobasic

              Comment


              • #8
                Stupid error in sentence corrected.
                hellobasic

                Comment

                Working...
                X