More important, than a good English explanation (which you did) is an example that reproduces the issue.
For example a zipped copy of the project folder, that I can unpack, open in Lazarus, and see it happen here.
There are a few thinks you can check.
<project_dir> => the folder that contains the *.lpi file
1)
When you get the issue, you should know the name of the unit that you changed.
E.g. you changed "unit MyMainForm" in MyMainForm.ppu.
Then:
- Check if there are any MyMainForm.o or MyMainForm.ppu files
=> You should have exactly ONE of each. And they should be in <project_dir>/lib/x86_64/* (or i386 or similar)
=> If there are any other MyMainForm.o or MyMainForm.ppu then that is bad
=> They should both have the current date/time
If you made changes to a Form (add/change components), then check that <project_dir>/lib/x86_64/MyMainForm.lfm is up to date.
Also make sure, that your unit name is not used elsewhere. For example, you cannot have a unit called "graphics" because that already exists.
2)
Are the source files *ALL* in <project_dir>?
Do you have some sources forms in other folders? Such as <project_dir>/some_folder? Or even outside <project_dir> like c:\my_other_sources?
Yes that should work. But who knows, maybe there is an issue?
Do you have code like
unit MyUnit;
uses OtherUnit in '..\foo\other.pas'
3)
Do you have include files {$I ....}
I am not sure how well detection of changes in include files work....
4) Do you have circular unit references?
MyUnit1 uses MyUnit2, and MyUnit2 uses MyUnit1? => Circles can be bigger, including more units.
Menu View > "Unit dependencies" then change to tab "Project and packages" => Does the lower graph (with your units) have any red lines?