Results 1 to 3 of 3

Thread: Delphi plugin example for Simba.[example]

  1. #1
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    661
    Mentioned
    35 Post(s)
    Quoted
    102 Post(s)

    Default Delphi plugin example for Simba.[example]

    Hey all. Well, today I tried to write the plugin for Simba on the unicode version of Delphi Experiment was succesful finished, but when you write on Delphi(2010 ->XE5) for Lazarus, you must have to remember: string type in Lazarus = ansistring in the unicode version of Delphi. For Delphi 7, string = string in Lazarus.

    Plugin example code in Delphi XE3:

    Simba Code:
    library Plugin;

    { Important note about DLL memory management: ShareMem must be the
      first unit in your library's USES clause AND your project's (select
      Project-View Source) USES clause if your DLL exports any procedures or
      functions that pass strings as parameters or function results. This
      applies to all strings passed to and from your DLL--even those that
      are nested in records and classes. ShareMem is the interface unit to
      the BORLNDMM.DLL shared memory manager, which must be deployed along
      with your DLL. To avoid using BORLNDMM.DLL, pass string information
      using PChar or ShortString parameters. }


    uses
      System.SysUtils,
      System.Classes,
      math;

      var
      OldMemoryManager: TMemoryManager;
      memisset: Boolean = False;

    {$R *.res}

     type T3DIntegerArray = array [0..0] of array[0..0] of array [0..0] of integer;

    function HelloPlugin(s: AnsiString): AnsiString; Cdecl;
    begin
      result := s;
    end;

    function GetPluginABIVersion: Integer; Cdecl;export;
    begin
      Result := 2;
    end;

    procedure SetPluginMemManager(MemMgr : TMemoryManager); Cdecl;export;
    begin
      if memisset then
        exit;
      GetMemoryManager(OldMemoryManager);
      SetMemoryManager(MemMgr);
      memisset := true;
    end;

    procedure OnDetach; Cdecl; export;
    begin
      SetMemoryManager(OldMemoryManager);
    end;

    function GetTypeCount(): Integer; Cdecl; export;
    begin
      Result := 1;
    end;

    function GetTypeInfo(x: Integer; var sType, sTypeDef: PAnsiChar): integer; Cdecl;export;
    begin
      case x of
        0: begin
            StrPCopy(sType, 'T3DIntegerArray');
            StrPCopy(sTypeDef, 'array of array of array of integer;');
           end;

        else
          x := -1;
      end;

      Result := x;
    end;

    function GetFunctionCount(): Integer; Cdecl; export;
    begin
      Result := 1;
    end;

    function GetFunctionInfo(x: Integer; var ProcAddr: Pointer; var ProcDef: PAnsiChar): Integer;Cdecl; export;
    begin
      case x of
        0:
          begin
            ProcAddr := @HelloPlugin;
            StrPCopy(ProcDef, 'function HelloPlugin(s: String): String;');
          end;

        else
          x := -1;
      end;

      Result := x;
    end;

    exports GetPluginABIVersion;
    exports SetPluginMemManager;
    exports GetTypeCount;
    exports GetTypeInfo;
    exports GetFunctionCount;
    exports GetFunctionInfo;
    exports OnDetach;

    begin
    end.

    Test script code:
    Simba Code:
    program new;
    {$loadlib plugin.dll}
    begin
     WriteLn(HelloPlugin('I am Delphi-Plugin!'));
    end.

    Output:

    Simba Code:
    Compiled successfully in 15 ms.
    I am Delphi-Plugin!
    Successfully executed.

    Compiled version of the test plugin you may find in attachment.

    Cheers,
    Cynic.
    Attached Files Attached Files
    Per aspera ad Astra!
    ----------------------------------------
    Slow and steady wins the race.

  2. #2
    Join Date
    May 2007
    Location
    England/Liverpool
    Posts
    1,004
    Mentioned
    9 Post(s)
    Quoted
    106 Post(s)

    Default

    hehe not working under lape try again duplicated T3DIntegerArray

    edit: Good job tho updated version on rick's http://villavu.com/forum/showthread.php?t=58815 which was just for the pascal interpreter.
    Last edited by Mark; 09-11-2013 at 09:31 AM.

  3. #3
    Join Date
    May 2012
    Location
    Moscow, Russia
    Posts
    661
    Mentioned
    35 Post(s)
    Quoted
    102 Post(s)

    Default

    Lol, just test it in PS
    Per aspera ad Astra!
    ----------------------------------------
    Slow and steady wins the race.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •