Menu

Here is a working Delphi plug-in

2007-03-13
2012-11-14
  • Nobody/Anonymous

    I have read a few messages on here from people who have had difficulty in getting plug-ins working in Delphi.

    Here is a working example.

    It is only a template, but it works for me.  I think I had a working version with Scintilla, but can't find it right now.

    library DllEntry;
    uses
       SysUtils,
       Windows,
       Dialogs,
       Classes;

    type

       NppData = record
          _nppHandle : HWND;
          _scintillaMainHandle : HWND;
          _scintillaSecondHandle : HWND;
       end;

       TProc = procedure; cdecl;

       FuncItem = record
          _itemName:array[0..63] of char;
          _pFunc : TProc;
          _cmdID : integer;
          _init2Check : integer;
          _PShKey : pointer;
       end;

    var
       LocalNppData : NppData;
       FI : array[0..1] of FuncItem;

    procedure MyProc; cdecl;
    begin
       ShowMessage('MyProc');
    end;

    procedure DLLEntryPoint(dwReason: DWord);
    begin
       case dwReason of
          DLL_PROCESS_ATTACH:
          begin
           //ShowMessage('Attaching to process');
           FillChar(FI[0],sizeof(FuncItem),0);
           FI[0]._pFunc := MyProc;
           strcopy(FI[0]._itemName,'MyProc');
           FI[0]._init2Check := 0;
           FI[0]._PShKey := nil;
           FillChar(FI[1],sizeof(FuncItem),0);
           FI[1]._pFunc := MyProc;
           strcopy(FI[1]._itemName,'MyProc2');
           FI[1]._init2Check := 1;
           FI[1]._PShKey := nil;
          end;
          DLL_PROCESS_DETACH: begin end;
          DLL_THREAD_ATTACH: MessageBeep(0);
          DLL_THREAD_DETACH: MessageBeep(0);
       end;
    end;

    procedure setInfo(NotePadPlusData : NppData);cdecl;      // Needs struct nppdata
    begin
       ShowMessage('setInfo');
       LocalNppData := NotePadPlusData;
    end;

    function getName:PChar; cdecl;
    begin
       ShowMessage('getName');
       Result := 'My Test Plug-in';
    end;

    function getFuncsArray(var nFuncs:integer):Pointer;cdecl;
    begin
      ShowMessage('getFuncsArray');
      nFuncs := 2;
      Result := @FI;
    end;

    procedure beNotified; cdecl;
    begin
    end;

    function messageProc(p1,p2:integer;p3:pointer): integer; cdecl;
    begin
       Result := 0;
    end;

    exports
       setInfo,
       getName,
       getFuncsArray,
       beNotified,
       messageProc;
    begin
       { First, assign the procedure to the DLLProc variable }
       DllProc := @DLLEntryPoint;
       { Now invoke the procedure to reflect that the DLL is attaching to the
       process }
       DLLEntryPoint(DLL_PROCESS_ATTACH);
    end.

     
    • Nobody/Anonymous

      Hi, This is John Starkie, who posted the original code.  I've now developed a Delphi plug-in that uses Scintilla, based on what I posted earlier.  The earlier plug-in worked, but could only do a ShowMessage.

      Shall I email it to Don again?

      The plug-in hides all unmarked text, so for example, if you're looking at a big file you can find and mark the bits you're interested in (using NPP), then hide the rest of the text.

      It does work, with some reservations.

      The first reservation is that you can't hide the first line of a file.  This appears to be a Scintilla issue, as I tried hard coding 'hide lines 0 to 2' and it still didn't hide line 0.

      The second reservation is that I would like to be able to view marked text and then copy that only.  When selecting and copying, the hidden text becomes unhidden.

      These both sound like Scintilla issues.  I would imagine the first is a bug.  I could imagine there being a reasonable explanation for the second reservation.

      I developed this plug-in because I couldn't find a way to hide marked text.  Have I just not looked in the right places?

       
    • Nobody/Anonymous

      beNotified has to get changed to:

      procedure beNotified(Notification: PSCNotification); cdecl;

       
      • Don HO

        Don HO - 2007-06-17

        I suppose it's under the GPL license?
        If so, could you send the whole project files to :
        don . h @ free . fr
        in order that it can be published on Notepad++ page?

        Don

         
        • Damjan Cvetko

          Damjan Cvetko - 2007-06-19

          Hi.. I also have a working (not so nice) Delphi API for N++. I'm in the process of publishing the project I'm working on on the Plugins project page...
          I did use this code as a basis tho q:)

          If you are interested...

          Re,
          -Zobo

           
    • Nobody/Anonymous

      Don, I have emailed the project files to you, although all that really needs to be done is to take the source above and compile it.

      I haven't made the change suggested above, as the compile will fail.  I need a type declaration for PSCNotification, and don't have the NPP sources to hand (I'm in Bangladesh right now working for a client.  The sources are in the UK and I have a slow internet connection here).

      If you can help, I'll look at it.

      Cheers

       
      • Nobody/Anonymous

        You can find (an older version) of the scintilla header here: http://www.pnotepad.org/scintilla/
        In this package you find a file named SciSupport which contains the types and constants for scintilla (also PSCNotification).
        And after the comments in the file, that file was autogenerated by a python script. Maybe in the scintilla source, but I haven't realy take a look after it.