Recent

Author Topic: Huge problem with open files?  (Read 3316 times)

Madoc

  • Jr. Member
  • **
  • Posts: 52
Huge problem with open files?
« on: November 24, 2023, 12:38:55 pm »
So, I just started trying to port a very large Delphi project to Lazarus, it's my first time really using it, and I'm running into some very serious problems with file versions and open files in general. I don't know if there's some way to modify this behaviour, but these are the issues I'm having:

1) For some reason it's sometimes opening unit files in the editor that are in a different folder from the project, instead of the ones in the project folder.

2) If I overwrite a unit file, and try to compile, Lazarus will somehow open the previous version of the file which no longer exists.

3) If I delete or rename a file, Lazarus will just re-create it, including all of its previous contents.

4) Closing a file in the editor doesn't actually seem to close it. If I save all it will save files that are no longer open, with whatever contents were in the editor last.

5) When I opened a file with the same name as one in the project from another folder for reference, then closed it and later saved all, it overwrote my other file with the contents of its own copy. This actually lost me lots of code.


It seems to me that the basic problem is that Lazarus keeps memory copies of recently opened files and will even overwrite those files once they have been "closed". Worse still, it gets confused about file locations, and loads and saves files in different locations with contents of other similarly named files.

This seems extremely problematic to me, and I'm now terrified that my code will be modified in unexpected ways or lost. Even just the ability to close a file therefore discarding any changes seems very important.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8086
Re: Huge problem with open files?
« Reply #1 on: November 24, 2023, 12:56:18 pm »
What you're describing is totally crazy. I'm reluctant to get involved since I'm not an "IDE innards" specialist, but I feel that somebody needs to jump in fast before you conclude that Lazarus is unusable.

There is definitely no in-memory caching. What your OS (and potentially any VCS etc.) is doing is something else entirely.

First, the obvious questions (frankly, you should have provided this info):

What version of Lazarus? What OS? Do you have multiple IDEs active at the same time?

Now, the non-obvious one:

Does whatever OS you're using have any form of symbolic link facility, and are any of your unit files accessed via something like that?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Handoko

  • Hero Member
  • *****
  • Posts: 5382
  • My goal: build my own game engine using Lazarus
Re: Huge problem with open files?
« Reply #2 on: November 24, 2023, 01:07:07 pm »
@Madoc

Maybe not related, but I ever had problem using Lazarus with different versions of the pas file, which are from different locations.

You can try to quit the Lazarus and rename the folder. By doing so, Lazarus will 'forget' the project files' locations.

And I learn from my experience, now if I am using Lazarus and want to open other pas files to copy/pas some code, I use Pluma (Linux version for Notepad).

4) Closing a file in the editor doesn't actually seem to close it.

I agree it is a bit weird. You can't close a file or project by doing File > Close (Page/All). If I really want to close it, I do: File > New > Project: Application.

5) When I opened a file with the same name as one in the project from another folder for reference, then closed it and later saved all, it overwrote my other file with the contents of its own copy. This actually lost me lots of code.

Don't do it, use Notepad instead.

This seems extremely problematic to me ...

I'm sorry you have problem using Lazarus. At the beginning I experienced similar issues too. But those didn't seem serious to me and can be easily avoided using Pluma/Notepad along with Lazarus.

Madoc

  • Jr. Member
  • **
  • Posts: 52
Re: Huge problem with open files?
« Reply #3 on: November 24, 2023, 01:14:21 pm »
Lazarus 2.2.6, OS is windows 11.

I did have a lot of stuff open, including the delphi IDE on another monitor, and was opening and viewing all sorts of files, but that's pretty normal for me. I did some simple tests after a restart and now if I close a file and reopen it in Lazarus it does revert. Not sure what was happening and can't really speculate without knowing how Lazarus handles files. I guess I'll keep going and see if it happens again.

Handoko

  • Hero Member
  • *****
  • Posts: 5382
  • My goal: build my own game engine using Lazarus
Re: Huge problem with open files?
« Reply #4 on: November 24, 2023, 01:28:34 pm »
I knew Lazarus has problem opening closing files. I haven't submit any bug report because I didn't dig deeper and that issue didn't seem important to me since I found using Pluma/Notepad could solve my problem.

You can do more tests and provide us a full explanation how to reproduce the issue, submit a bug report, it should be fix in the future releases. But remember, you need to make proper backup of your source code to prevent bad things that may happen.

balazsszekely

  • Guest
Re: Huge problem with open files?
« Reply #5 on: November 24, 2023, 02:01:59 pm »
@Madoc
It seems to me that your problems originates from the fact that you have multiple version of a project in different folders. To avoid this switch to a version/source controlling system like git, svn, etc... With that said bugs are always a possibility, but most of your claims are not true:

Quote
1) For some reason it's sometimes opening unit files in the editor that are in a different folder from the project, instead of the ones in the project folder.
The editor always opens the files opened in a previous session. For more options please go to Project->Project Options->Session. Delphi had a similar setting named Project Desktop(IIRC), if checked, you got the same behaviour as with Lazarus. To avoid problems like this, please pay attention to the path in the statusbar(screenshot)

Quote
2) If I overwrite a unit file, and try to compile, Lazarus will somehow open the previous version of the file which no longer exists.
Not true. When you overwrite a file from the current project, Lazarus will ask if you want to reload the file.

Quote
3) If I delete or rename a file, Lazarus will just re-create it, including all of its previous contents.
Only if the IDE is open, the file is opened in the editor and you click "Save" on exit, but that is just normal behaviour.

Quote
4) Closing a file in the editor doesn't actually seem to close it. If I save all it will save files that are no longer open, with whatever contents were in the editor last.
Not true. If you modify a file, you cannot close it without the IDE prompting: "File xxxx has changed. Save?" or something similar.

Quote
5) When I opened a file with the same name as one in the project from another folder for reference, then closed it and later saved all, it overwrote my other file with the contents of its own copy. This actually lost me lots of code.
This is highly unlikely. You probably mixed files from different folders, again switching to source control solves all your issues.

« Last Edit: November 24, 2023, 02:23:06 pm by GetMem »

rvk

  • Hero Member
  • *****
  • Posts: 6640
Re: Huge problem with open files?
« Reply #6 on: November 24, 2023, 04:19:31 pm »
I did have a lot of stuff open, including the delphi IDE on another monitor, and was opening and viewing all sorts of files...
And of course, don't have Delphi open on the same project (or anywhere near the project you are working on in Lazarus).

wp

  • Hero Member
  • *****
  • Posts: 12516
Re: Huge problem with open files?
« Reply #7 on: November 24, 2023, 05:36:43 pm »
I just started trying to port a very large Delphi project to Lazarus, it's my first time really using it
Reading this makes me shiver...

You should not start with Lazarus by porting a large Delphi project, you will be very disappointed. Begin with simple projects in Lazarus and learn to feel comfortable within this new environment. Although it's similar to Delphi there are lots of differences, and you must know them, or at least have a feeling for them, before porting a project.

Port you large Delphi project in small steps. Begin with self-contained units and forms (Aboutbox?) which you can test independently.

As for the main question with open files: Yes, having too many files open, in particular in several instances of Lazarus, can be a problem - simply: don't do this. But... Within the same Lazarus instance it works. I installed the "packagetabs" in "Install/uninstall packages" - this removes the editor tabs and replaces them by a list at the left side so that you can have many files in view, and files are grouped in projects and packages.

I agree some caching mechanism in Lazarus. I think that this happens when lfm files are edited in the editor of the IDE - then it is not clear whether this change is persistent. Don't edit lfm files in the IDE. Always close the IDE, edit the lfm file in an external editor, and then open the IDE again.

You mention that you have files open also in Delphi. This sounds as if you are porting the same source files that you use in Delphi. No, don't do this either. Create a copy of the project for the porting process and open these in Lazarus, and open the original files only in Delphi (and still make sure to have an additional untouched backup!) When a form file is known to work in Delphi it will very probably not be loadable for Lazarus, and vice versa. And conversely, I've had cases when Delphi had problems with the UTF-8 coded sources of Lazarus.

And the most important question at last: Is your project ready to be ported at all? Which components are you using? Is there a Lazarus equivalent for each component? Do you know the difference between the same components in the Delphi and the Lazarus world? If there is no Lazarus component do you know how to work around? Test the workaround in Delphi first if possible, since it is of prime importance to have a working Delphi project all the time for comparison.

Madoc

  • Jr. Member
  • **
  • Posts: 52
Re: Huge problem with open files?
« Reply #8 on: November 26, 2023, 07:38:44 pm »
Don't worry, I have plenty of backups, and yeah, I'm not (intentionally) sharing source files with Delphi, unless I explicitly copy them over or something.

I've been avoiding using both Lazarus and Delphi at the same time and so far I haven't really experienced more issues, though I've also been quite laser focused on a couple of things and not messing around with lots of source files. The one time I opened Delphi at the same time some of my source files started becoming read-only. Maybe I have some dodgy paths configured / inherited somewhere in Lazarus despite using a complete copy of the source in a new location? I did create a fresh Lazarus project now (but with all the same source) as I was getting some other weird behaviour that I didn't know how to fix.

The project has zero dependencies beyond windows headers (there are some differences, but I've amended those), not a single Delphi unit used, everything is written from scratch. There's a lot of low level code that needs adjustments, but I'm getting comfortable with the differences and the Lazarus environment in general.

I'm quite positive overall, hopefully I'll manage to figure out the last few niggling issues in time. Plenty to do still.

Madoc

  • Jr. Member
  • **
  • Posts: 52
Re: Huge problem with open files?
« Reply #9 on: November 28, 2023, 09:08:32 am »
I think I've encountered similar problems a few more times now, and I think it might be caused by using multiple source editor windows, which I usually use 2-3 of at once.

When I have multiple editor windows open, very frequently if I close a source file I will not get a prompt to save or discard changes, and when I open the file again (in the same session at least) the changes I made are still there. Also sometimes the "Save all" option will be greyed out even though I know I've made changes, but if I click on a different editor window "Save all" is enabled. I think this is probably related.

I don't think I can 100% consistently reproduce this behaviour, but it is so common that when I did get a prompt to save or discard changes I was surprised because it doesn't usually happen.

dseligo

  • Hero Member
  • *****
  • Posts: 1443
Re: Huge problem with open files?
« Reply #10 on: November 28, 2023, 09:13:25 am »
I think I've encountered similar problems a few more times now, and I think it might be caused by using multiple source editor windows, which I usually use 2-3 of at once.

What do you mean by 'multiple source editor windows' exactly? How do you accomplish this?

Madoc

  • Jr. Member
  • **
  • Posts: 52
Re: Huge problem with open files?
« Reply #11 on: November 28, 2023, 02:37:25 pm »
What do you mean by 'multiple source editor windows' exactly? How do you accomplish this?

Right click on a source tab -> Move to new window / Clone to new window.

I almost ran away in terror from Lazarus before I found out how to access this feature. Other than this file issue, seems to work great.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8086
Re: Huge problem with open files?
« Reply #12 on: November 28, 2023, 05:11:48 pm »
I think I've encountered similar problems a few more times now, and I think it might be caused by using multiple source editor windows, which I usually use 2-3 of at once.

When I have multiple editor windows open, very frequently if I close a source file I will not get a prompt to save or discard changes, and when I open the file again (in the same session at least) the changes I made are still there. Also sometimes the "Save all" option will be greyed out even though I know I've made changes, but if I click on a different editor window "Save all" is enabled. I think this is probably related.

I don't think I can 100% consistently reproduce this behaviour, but it is so common that when I did get a prompt to save or discard changes I was surprised because it doesn't usually happen.

That will happen if either you've got symbolic links between directories or you've got explicit paths in your project options setup, and the IDE opens a new tab in a secondary (i.e. "cloned" etc.) window in response to a compiler error such that different tabs use different paths to refer to the same file.

However I don't believe I've seen that one recently.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Madoc

  • Jr. Member
  • **
  • Posts: 52
Re: Huge problem with open files?
« Reply #13 on: November 29, 2023, 09:59:01 am »
That will happen if either you've got symbolic links between directories or you've got explicit paths in your project options setup, and the IDE opens a new tab in a secondary (i.e. "cloned" etc.) window in response to a compiler error such that different tabs use different paths to refer to the same file.

I think I understand what most of that means, but my experience is that you really don't need such specific conditions for this to manifest, and even so that sounds kinda broken? I did also re-create the project from scratch now, so if there's any dodgy path configs it's not me.

I've also noticed that files edited in additional windows don't seem to compile until you do a full build, which is problematic, and doing a full build can take a while.

It really seems to me that Lazarus is just not really aware of what files are open or have been modified when they are open in additional source editor windows. Basically every issue I've described is easily explained by this.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8086
Re: Huge problem with open files?
« Reply #14 on: November 29, 2023, 10:03:44 am »
I've also noticed that files edited in additional windows don't seem to compile until you do a full build, which is problematic, and doing a full build can take a while.

What do you mean "additional windows" in this context?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018