Recent

Author Topic: LazarusIDE variable of LazIDEIntf is null  (Read 1047 times)

Frogfather

  • Jr. Member
  • **
  • Posts: 55
LazarusIDE variable of LazIDEIntf is null
« on: November 19, 2019, 06:59:37 pm »
Hi,
I need to get a list of units in the current project and have copied the example in the wiki https://wiki.freepascal.org/Extending_the_IDE. However, when examined with the debugger the LazarusIDE variable is null. The code in the LazIDEIntf says this will be set by the IDE but it doesn't look like it has been. I've tried restarting/rebuilding the IDE. Any suggestions welcome!

JohnC

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: LazarusIDE variable of LazIDEIntf is null
« Reply #1 on: November 19, 2019, 08:49:07 pm »
If you search the components folder you will see it is used by a lot of packages (including codetools). So it does work.

I can only guess, maybe you are running before the IDE had a chance to initialize it?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: LazarusIDE variable of LazIDEIntf is null
« Reply #2 on: November 19, 2019, 09:08:11 pm »
Hi!

What do you want to achieve? This is not quite clear.

In the page "Extending the IDE" is a small chapter "All used units of project". Copy that procedure and replace "debugln" by "showMessage".

Winni

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: LazarusIDE variable of LazIDEIntf is null
« Reply #3 on: November 19, 2019, 09:29:22 pm »
Oh, by the way: you must install your code into the IDE.

If you write a normal project and use the package the LazarusIDE  is nil. That is normal.

Once you added your package to the IDE, then in that package you can use LazarusIDE.
To debug the code, you must debug the entire IDE.
- Open ide/lazarus.lpi as project.
- If needed compile via tools menu. You must do that every time you made changes to your code. F9 will NOT recompile the IDE
  (no need to restart the IDE [1] / you can turn that off under "configure build ide" in Tools menu)
- Run the code in the debugger by using F9

Make a backup of your Lazarus.exe
In case it no longer starts with your code installed.



[1]
Normally building the IDE ends with "linking lazarus.exe"

At least on windows it is possible (though rare), that if the IDE crashed in the debugger, it locks the lazarus.exe. Then it will do "linking lazarus.new.exe".
In that case you still debug the old lazarus, without the latest changes to your code.
You can try to fix this by "run > reset debugger" and rebuild again.
You can check in the install folder if the lazarus.exe is new (look at the date). Also there should be no lazarus.new.exe (but there will be lazarus.old.exe)
« Last Edit: November 19, 2019, 09:35:22 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: LazarusIDE variable of LazIDEIntf is null
« Reply #4 on: November 19, 2019, 09:41:54 pm »
I need to get a list of units in the current project
You do know the project inspector?

Or if you need more: View > Unit dependencies
(which even has a graph / MAYBE: check the box "All package units" before going to the graph)
« Last Edit: November 19, 2019, 09:44:52 pm by Martin_fr »

Frogfather

  • Jr. Member
  • **
  • Posts: 55
Re: LazarusIDE variable of LazIDEIntf is null
« Reply #5 on: November 20, 2019, 02:21:14 pm »
Hi Martin, thanks for the quick reply.

I'm writing a little utility to autocreate getters and setters for a class - much as Intellij/Eclipse does.

At the moment this works fine using an Opendialog to select the required unit, but I spotted the article on extending the IDE and thought that might be a better approach. Of course you're correct - my utility is stand-alone which is why LazarusIDE is null. Thanks for the input!

Btw - If there's already a utility to automate getters and setters and I've just missed it then please point me at it and we can pretend this thread never happened  :-[

Cheers
John

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: LazarusIDE variable of LazIDEIntf is null
« Reply #6 on: November 20, 2019, 02:26:12 pm »

Btw - If there's already a utility to automate getters and setters and I've just missed it then please point me at it and we can pretend this thread never happened  :-[


Write this within the class body:

Code: Pascal  [Select][+][-]
  1. property ExampleProperty: Integer;

Press Ctrl+Shift+C

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: LazarusIDE variable of LazIDEIntf is null
« Reply #7 on: November 20, 2019, 03:09:22 pm »
Btw - If there's already a utility to automate getters and setters and I've just missed it then please point me at it and we can pretend this thread never happened  :-[

Depends what you need...

As posted by Zoran: Codetools. Which has lots of other completions too. https://wiki.lazarus.freepascal.org/Lazarus_IDE_Tools#Properties

Or Code-Templates (you can create your own).
In trunk (Laz 2.1) I just added: https://bugs.freepascal.org/view.php?id=27625
Code Templates also can use macros to read from the editor....

Of course if you have already some input that you need to reformat, then you may need a custom extension. You can write an IDE package.
Or you can write a PascalScript editor macro https://wiki.lazarus.freepascal.org/Editor_Macros_PascalScript


 

TinyPortal © 2005-2018