Next OTA question: Is there a way to get the name of the method the cursor is in? I saw some plugins (like Castalia) showing that in some toolbars - or is that done by some custom pas parser?

Comments

  1. Don't know the answer, but I do know that CnPack does it, so you could plow through their source code.

    ReplyDelete
  2. There's no OTAPI way to do it - you need to parse the source. Castalia has its own parser (which is open source); for Bookmarks I wrote my own lightweight one; CnPack has their own too I think. David G Hoyle has some sample code to select an entire method, which parses very simply just looking for procedures in the implementation section: http://www.davidghoyle.co.uk/WordPress/?p=341

    ReplyDelete
  3. CnPack also has a toolbar that shows a similar thing (and since that it open source, it might be worth getting the source and have a look - https://code.google.com/p/cnpack/source/browse/trunk/cnwizards/Source/Utils/CnPasCodeParser.pas).

    I think both of them use a custom parser to work out where the cursor is.

    There is Castalia-Delphi-Parser (https://github.com/jacobthurman/Castalia-Delphi-Parser) but I believe our resident Simon Stuart has updated with his Monkey Mixer (https://github.com/LaKraven/MonkeyMixer), in the Source/Common directory

    ReplyDelete
  4. Simon Stuart https://github.com/RomanYankovsky/DelphiAST - How could I have forgotten that one?? 

    Need more coffee (and sleep)... :-D

    ReplyDelete
  5. IOTAModuleRegions and a little bit parsing do the job for me - see TLiveBlameEditorPanel.ChangeLineEvent

    ReplyDelete
  6. Uwe Schuster I saw that and was going to suggest it but it depends on which version of Delphi needs supporting...

    ReplyDelete

Post a Comment