Recent

Author Topic: [Solved] Codetools:cannot find unit  (Read 2021 times)

Peter H

  • Sr. Member
  • ****
  • Posts: 272
[Solved] Codetools:cannot find unit
« on: January 23, 2021, 05:35:01 am »
Hello,

Edit:
The problem vanished, when I opened another project and tried to find the same units, it worked.
Then I re-opened my recent project again and now the problem is vanished.

I recompiled the ide some hours before the problem appeared (installed OPM) without closing the project. Maybe this was the reason?
End Edit.

I have a project that compiles and runs without problem.

However, if I search for declarations then on some variables it does not find them and diplays an error instead in the messagelist:
 
Code: [Select]
Compile Project, OS: win32, CPU: i386, Target: PathManager.exe: Success, Warnings: 1, Hints: 11
  [ .... snip ]
Codetools, Errors: 1
main.pas(8,22) Error: unit not found: FileUtil

Also the tooltips for the affected variables and units are missing.
So far I found, it cannot find units in the lcl, but will find units in the rtl. (maybe this is an accidental observation, I did not test all units)
I checked, the source and ppu files exist.

How to fix this?
I use:
Lazarus 2.1.0 r64410 FPC 3.3.1 x86_64-win64-win32/win64
« Last Edit: January 24, 2021, 04:00:03 pm by Peter H »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Codetools:cannot find unit
« Reply #1 on: January 23, 2021, 03:54:13 pm »
The problem vanished, when I opened another project and tried to find the same units, it worked.
Then I re-opened my recent project again and now the problem is vanished.
Did it vanish for good without coming back?

Quote
I recompiled the ide some hours before the problem appeared (installed OPM) without closing the project. Maybe this was the reason?
I recently optimized the DefineTemplates code which could cause such problems but I don't see them here.
Sometimes mysterious problems go away by doing a clean build of Lazarus IDE.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Codetools:cannot find unit
« Reply #2 on: January 23, 2021, 06:03:28 pm »
I tried a lot of stuff before I posted here. Dont remember all details.  ;D
I definitely tried 32 bit and 64 bit compilation.
I did clean builds before, refreshed the codetools in code explorer, this all did not solve or change the problem.
So far I remember I did even restart lazarus (without selecting another project) and the problem persisted.
Finally closing the project, choosing another project and then reopening the old project helped.
If it happens again and is persistent I can zip the project folder and post it for examination. But I dont hope it happens again.
For now it is ok.

Possibly the problem was caused by installing a package into the IDE while the project was open. I will not do this again unless you explicitely wish it.  ;)
Maybe it is better to make this impossible,
Some months ago I accidently installed a package into codetyphon while debugging, this lead to an unrecoverable problem.
(Since I have trunk and fpcupdeluxe running I do not use typhon anymore, dont need it anymore)
« Last Edit: January 23, 2021, 06:35:05 pm by Peter H »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Codetools:cannot find unit
« Reply #3 on: January 23, 2021, 06:57:14 pm »
There is always a project open in Lazarus. Session info is stored in it.
When a component package is installed, all editor files are saved and the IDE rebuilt.
Your problem remains a mystery.  Please tell if it happens again.

Can you rebuild Lazarus while debugging? That sounds like a bug.
« Last Edit: January 23, 2021, 06:59:49 pm by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Codetools:cannot find unit
« Reply #4 on: January 23, 2021, 07:10:41 pm »
Can you rebuild Lazarus while debugging? That sounds like a bug.

I did not try it in Lazarus - I make mistakes, but normally not twice  :D-

Yes I overlooked, it is not possible to close a project without opening another one. But it is possible to switch to an almost empty dummy project (create a new throw away console project)
I am currently evaluating and playing around with other (C++) IDE's too, sometimes I get confused.  :-[
I am retired from job and in lockdown I have too much time.  8)
« Last Edit: January 23, 2021, 07:20:18 pm by Peter H »

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Codetools:cannot find unit
« Reply #5 on: January 23, 2021, 08:15:40 pm »
I tried to reproduce the problem - with immediate success unfortunately.
The problem is persistent, restarting Lazarus does not fix it.
Only opening another project fixes it.
The problem happened after de-installing onlinepackagemanager. I believe it happens always if a package is installed or removed, but did not test this. Last time it happened after installing onlinepackagemanager.

I attached an image to illustrate the problem and the exported project.
And an image to show what the program looks, when it runs but it is not required to run it to reproduce the problem
Lazarus version is: Lazarus 2.1.0 r64410 FPC 3.3.1 x86_64-win64-win32/win64

Creating a new "Simple program" project and then reopening the pathmanager project fixes the problem
BTW, to reproduce the problem, it is NOT necessary to run or debug the compiled project. The program reads and writes Environment variables and is safe to use in my opinion if you dont switch to "admin" mode while in debugger, but I cannot give warranties
« Last Edit: January 23, 2021, 10:00:37 pm by Peter H »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Codetools:cannot find unit
« Reply #6 on: January 23, 2021, 09:19:06 pm »
After installing or removing a package, do you restart Lazarus or does the problem occur when you don't restart?
I will test this myself tomorrow.

You have too much time? Ok good, there are some 2000 open bug reports for Lazarus. Patches are welcome.   :)
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Codetools:cannot find unit
« Reply #7 on: January 23, 2021, 09:28:19 pm »
The problem occurs after installation or removal of a package without restart.
After restart it persists.

I must admit, I am not a professional programmer and programmed only LabView in my latest job, but not fulltime, only occasional.
30 years ago I worked as a programmer for 4 years, Mainly Z80 and H8 Assembler and C for embedded projects and Turbo Pascal for the user interfaces on the DOS PC and I managed to burn Turbo Pascal generated EXEs into ROM together with a small faked DOS ;-) I have never done GUI software professionally,

So my skills are close to the bare metal and otherwise limited and aged.  :-[
Apart from some unsatisfying lessons in ALGOL68 almost 50 years ago, I have no formal education in programming. 8)

However, if there are bug reports that I can solve then I am happy to do so. I am much more talented to find bugs, much of my work was product testing (hardware)  and repair  in my last job (which I did for about 25 years).
« Last Edit: January 24, 2021, 03:53:34 pm by Peter H »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: Codetools:cannot find unit
« Reply #8 on: January 24, 2021, 02:45:41 pm »
Yes, I think you found a bug.
Please test with Lazarus trunk r64417.
I could not reproduce with your project but I saw similar temporary problems.
The CodeToolBoss.DefineTree.ClearCache calls I didn't understand and eliminated too many of them. Now I restored most.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Peter H

  • Sr. Member
  • ****
  • Posts: 272
Re: Codetools:cannot find unit
« Reply #9 on: January 24, 2021, 03:43:27 pm »
Yes, thank you! The problem is gone now. :)
I tested twice, I removed OPM and re-installed it.

Because you mentioned it in an earlier posting: It is possible to install or remove a package, while a debugging session is active.
Of course I did not do this, but I tried if I could do it.
Possibly the whole "package" menu should be disabled while debugging, because if an unexpieriended user (like me) does this by accident, it will lead to an unrecoverable and persistent problem, that is not easy to solve without fresh installation.
« Last Edit: January 24, 2021, 05:02:45 pm by Peter H »

 

TinyPortal © 2005-2018