Recent

Author Topic: "Error: Unit Not Found" when adding event in Object Inspector  (Read 4390 times)

DarkBlueMonkey

  • Newbie
  • Posts: 3
"Error: Unit Not Found" when adding event in Object Inspector
« on: August 21, 2023, 12:03:21 am »
Hi There, (Newbie here),

  I have a relatively simple Form, and I'm trying to add an event hook.  The form only has one Control, an OpenGLControl.  The moment I hit the ellipsis next to the event name (e.g. OnKeyPress) in the Form: Events tab in the Object Inspector, I instantly get

Codetools, errors: 1
unit1.pas(11,30) Error: unit not found: OpenGLContext

If I test it by deleting that unit from the uses clause, the error jumps to the error before that, uPSComponent.  If I remove that, I get the error that it can't find the unit  ExtCtrls... And so on and so forth until I get back to removing the uses for "Forms" at which point I get other errors because the main class is a Form, as you'd expect.  Here's my "uses" list that's added automagically by Laz...


uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
  uPSComponent, OpenGLContext, gl;   


Now, I can (sometimes) resolve the problem by reversing the uses of OpenGLContext and "gl" at the end there.  But it usually doesn't help.   If the code didn't compile I'd say there was a problem with my code... But it does compile, so I'm totally stumped.

Can anyone tell me why it's doing that... if only for my own sanity, it's been hindering me all evening till I just figured out the gl/OpenGLContext ordering.

Lazarus 2.2.0
Linux Mint 21.2
fpc 3.2.2+dfsg-9ubuntu1
everything else vanilla.


Many thanks in advance,

Nick
« Last Edit: August 21, 2023, 12:25:05 am by DarkBlueMonkey »

wp

  • Hero Member
  • *****
  • Posts: 12456
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #1 on: August 21, 2023, 01:07:02 am »
Has the package LazOpenGLControl been added to the requirements of the project? ("Project" > "Project Inspector" > see the tree nodes below "Required Packages"). Normally it should be added automatically when you drop the control on the form from the component palette. But who knows...

Since your project so far seems to be very simple you should create a new project and drop a TOpenGLControl on a new form. Try to compile. Does it work? Then repeat to assign an event handler - it should work.

What is uPSComponent? Are you sure that the package in which this unit is contained has no error and is properly installed?

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 559
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #2 on: August 21, 2023, 05:09:52 am »
Is there any possibility you can try your code on a windows box?
As I recall, I had a problem similar to this when using the rich text component from the online package manager.  Worked OK with windows, but behaved badly on linux.

cdbc

  • Hero Member
  • *****
  • Posts: 1643
    • http://www.cdbc.dk
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #3 on: August 21, 2023, 06:22:25 am »
Hi
Maybe... just maybe, it could be something as mondane, as case-sensitivity in linux, regarding filenames / unitnames?!?  %)
This sometimes creeps up on you, when you least expect it  :o
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

DarkBlueMonkey

  • Newbie
  • Posts: 3
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #4 on: August 22, 2023, 11:46:00 am »
@wp - yes LazOpenGLControl was added.     The program compiles and runs absolutely fine when I hit F9, and I've checked the l** files, and everything looks kosher.

@curt - sadly, not right now, I'm a linux-only person, but I do have a Windows VM tucked away somewhere, but it'll take me a while to get to it.

@cdbc - That's possible -   Lazarus auto-generated all the directories, and I've used the "Rescan" option as someone suggested elsewhere.    But the weird problem happens to me all the time.

In the end I went and hand-edited the hook into the lfm file and copied the function prototype from online.  The program compiles and runs just fine, and the new event hook is called correctly.   

However, if i try to use the Object Inspector, I simply can't add a new callback, I get the "Unit not found" error.    Does anyone else use Laz on Linux (Specifically Debian/Ubuntu/Mint)?

cdbc

  • Hero Member
  • *****
  • Posts: 1643
    • http://www.cdbc.dk
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #5 on: August 22, 2023, 03:41:34 pm »
Hi
I use FPC/Lazarus on more PCLinuxOS-kde/QT computers for years now, with only the occasional rebuild of Qt4Pas/Qt5Pas*) library, counting as errors, otherwise no errors  ;)
*) Mostly due to a rolling release and the distro updating the library with an older one  %) :P
<edit:> FPC = 3.2.2 & Laz = 2.2.6, both release versions. my own  libQt5Pas.so
Regards Benny
« Last Edit: August 22, 2023, 03:46:07 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

DarkBlueMonkey

  • Newbie
  • Posts: 3
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #6 on: August 22, 2023, 09:49:31 pm »
Ah ok..  That sounds like Mandrake-derived.   Good to know it works there.  I've got it on Mint, so I've just installed the standard apt packages from the Ubuntu archives... It's possible there may be a folder error or naming error, so looking for anyone that's running it on Ubuntu-derived Linuces :)

Interesting to hear about PCLinuxOS though... I've never heard of it before! Thanks!

cdbc

  • Hero Member
  • *****
  • Posts: 1643
    • http://www.cdbc.dk
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #7 on: August 23, 2023, 05:17:33 am »
Hi
Come to think of it, it's not the first time, I see something about Linux Mint and Lazarus, in this forum... Especially with regards to Ubuntu/Mint's way of working with the different packages of fpc/laz and the problems thereof. IRC, it can be a bit challenging to get them to work properly without installing from source etc... So, definitely, there are people here on the forum that knows about these troubles and how to get it all to play nice together, maybe @zeljko or @dbannon, they're both usually in the know, Linux-wise as well as pascal  ;)
Try searching this forum, for Linux Mint / Installation / packages.
I distro-hopped Mint once many years ago, and quite liked it, but the Mandrake derived PCLinuxOS won that race and I haven't looked back since  :D :-X
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Diverod

  • New member
  • *
  • Posts: 7
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #8 on: November 24, 2023, 12:39:41 am »
I'm new to Lazarus, Free Pascal and Ubuntu 22.04.

I have this issue often and I just save and exit Lazarus, restart Lazarus, go back and add the event again and it has always worked after that for an undermined amount of time.

Lazarus loads so quick and keeps track of my last position so well that I've not pursued trying to find out why it does this for me. I don't have enough experience to be of any real help on a resolution, so hope this might help some.
« Last Edit: November 24, 2023, 12:46:52 am by Diverod »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4541
  • I like bugs.
Re: "Error: Unit Not Found" when adding event in Object Inspector
« Reply #9 on: November 24, 2023, 10:35:22 am »
It does not sound like a Linux distro specific problem.
My guess is that you run "lazarus" binary instead of "startlazarus". It runs to original IDE version which does not have the newly installed packages.
You installed Lazarus into a write-protected directory, thus it must rebuild itself into your local configuration directory (usually ~/.lazarus).
Then "startlazarus" is clever enough to run the right binary.
See:
 https://wiki.freepascal.org/Unit_not_found_-_How_to_find_units
As you can see, the compiler and the IDE find units in a different way. Your code compiles and only the IDE has a problem.
The wiki page does not even mention running "lazarus" instead of "startlazarus" as a potential cause for problems. Please test it. Then if it helped, it can be added to the page.

I can also recommend getting Lazarus sources from GitLab into a writable directory and building it there ("make").
Then the "lazarus" binary can be started and rebuilt directly without worries about write-protection.
It has many benefits, like:
- You can "git pull" the latest bug fixes and updates any time.
- It prevents having duplicate compiler generated files when they are all compiled in one place.
- You can easily switch between Lazarus versions, eg. "git switch fixes_3_0", "git switch main". (Use the --pcp= parameter when running). This is especially useful now that Lazarus 3.0 release has not happened yet.
- It allows you to participate in Lazarus development which all happens in the "main" branch. Build the IDE with debug info, fix a bug, commit into your local Git branch, then generate a patch: "git format-patch main".

I myself use Lazarus built from sources under Manjaro Linux.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018