Lazarus

Using the Lazarus IDE => General => Topic started by: cymatics on September 12, 2019, 03:44:41 am

Title: ide runs older version of my project
Post by: cymatics on September 12, 2019, 03:44:41 am
Hi,

I'm new to Lazarus and have started a project with multiple folders for each version as i progress. I use the "project save as" and "save as" for the .pas (forms) files. As i've progressed, i noticed that sometimes the IDE compiles and runs the version of the program i am working on, and most recently, it seems to build but then an older version of my app pops up instead. The sources and forms in hte IDE are the newest version but it is running an older version.

I'm running Lazarus IDE V 2.0.4 on a Windows 7 SP1 64-bit machine.

Does anyone have an idea of what is going on and how to fix this? I've searched on the web and i can't find any mention of this.

Thanks in advance.
Title: Re: ide runs older version of my project
Post by: lainz on September 12, 2019, 04:04:34 am
Hi,

I'm new to Lazarus and have started a project with multiple folders for each version as i progress. I use the "project save as" and "save as" for the .pas (forms) files. As i've progressed, i noticed that sometimes the IDE compiles and runs the version of the program i am working on, and most recently, it seems to build but then an older version of my app pops up instead. The sources and forms in hte IDE are the newest version but it is running an older version.

I'm running Lazarus IDE V 2.0.4 on a Windows 7 SP1 64-bit machine.

Does anyone have an idea of what is going on and how to fix this? I've searched on the web and i can't find any mention of this.

Thanks in advance.

Use version control software instead of writing the project to different folders. Try SVN or GIT.
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 04:23:47 am
Thanks for your quick reply.

But i can't compile and run the latest code i wrote at this point. How do i "reset" the IDE to run the current project i have? I haven't used VCS before. I would like to get this current project version out as soon as possible.

I've tried copying  the original files (.pas) inot a new folder and opening from ther but it is still linking to the much older version of hte project. Thus my question about a "reset"...

Thanks again.
Title: Re: ide runs older version of my project
Post by: lucamar on September 12, 2019, 05:10:56 am
Try closing the project ("Project->Close Project") and then click "Open project", navigate to the new folder and (re-)open the newly saved project.

If that still dosn't work, you'll have to take more "heroic" measures: open the project's ".lpi" in a text editor and check whether it's referencing files in an specific folder rather than in none (which means "use the current one").

Check also, though I suposse you've done it, whether the main program file (the .lps) or any of the units "uses" other units in a specific folder, for example something like:
Code: [Select]
uses someunit in 'OldPath/someunit.pas';
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 06:51:00 am
Thank you. I've tried many things, including what you've suggested and the following:

* Created a new subfolder in the same main directory as all the other versions, then in the current project, saved it using "project as.." to the new folder, as well as the .pas files. But when i build the newly saved project, it reverts to the old project.

* Copied all the project files over to a new folder, shut down Lazarus and reopened the newly saved project from the new folder, but with the same outcome (old project gets built)

* opened project files ( lpi, lps, lpr) files and edited them with Notepad++ to remove references to older projects, but to no avail.

* tried copying only the main .pas files to a new folder, opening with Lazarus as "New project from File...", then went through the painful process of importing all of the libraries i used in my project and recompiling it. In this case, the correct project compiled (as it detected known errors in the code)..but when it runs, the EXE is of a much older file.

It seems that Lazarus saves the project information in a different location from that of the project itself. It remembers project history, even when i try to start fresh and edit out old references in the project XML files. I can view the new code with all the changes in the IDE, but i simply cannot build it. It's quite frustrating.

Are there any other ways to circumvent this behavior and actually get on with my project? I've even tried copying my new project with only hte new files onto another drive, but still with the same results. It's incredible that i cannot build my new project but i can see it and edit it.

Any other ideas would be greatly appreciated.

Thanks again.
Title: Re: ide runs older version of my project
Post by: af0815 on September 12, 2019, 07:06:17 am
Make a Backup :-)
Go into your projectfolder and look where the exe and the copiled files are stored. Remove ALL files out of the folder lib (in Projectinspector as Path for Libraries declared). Delete the exe
 Go into menu: run->cleanup and build and use all checks activated.
Wait for finish of compiling. Try a test and check if your exe is new build.
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 07:58:17 am
Hi, thank you for that suggestion. I haven't gone into the lib folder before, never thought to look there. I'll follow your suggestion and i'll let you know what happens. By the way, i do back up my files, both by copying all the files from the work in progress to a backup folder, as well as making a new project folder each time i want to rev up to the next version. I had always thought that using "Project save as..." and saving all the main .pas folders into that new file, then opening the project form that new file, would do the trick. I guess Lazarus has other ideas abut that...

Thanks again.
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 08:37:09 am
Hi Ianz,

I tried yur suggestions but the IDE is still compiling an older version of hte code. I have tried to find the path for Project Source Directory but i haven't been able to, so far. Would you or anyone else know where the project source path is defined? I'd love to take a look and see if that's the source of the problem.

Still searching for answers and suggestions,

Cheers.
Title: Re: ide runs older version of my project
Post by: wp on September 12, 2019, 10:13:02 am
Hard to tell what's wrong...

Does your project have a "flat" struture, i.e. are all source files in the same directory? If not you had to add the individual paths to "Other unit files" in "Project" > "Project Options" > "Compiler Optios". Only use relative paths here, relative to the project folder which is the one which contains the .lpr/.lpi files of the project. If you'd have absolute paths here the compiler would always use the first location, not that of the copied project.

Does the issue happen with another project, too? Begin a new project, add a button to the form, move it to the upper left corner of the form. Save, compile and run; the button should be in the upper left corner of the form.

Copy the entire project directory to a new directory. Load the project from the new location. Drag the button to the lower right corner of the form. Save, compile and run: the button should now be in the lower right corner of the form.

If the button is at the old position (upper left corner) something is very wrong. At first, rename the folder with your user settings so that Lazarus uses default settings. To find the folder go to "View" > "IDE Internals" > "About IDE"; find the folder name in the line "Primary config directory". Close Lazarus before you do the renaming. If default settings do not help, it is probably fastest to reinstall Lazarus.

If the button is at the new position (lower left corner) compare your original project with this one and find out what is different. Look in the "Project options"
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 06:40:11 pm
Hi wp,

In regards to your question: yes, it is a flat file structure as described by you, that is how i have traditionally made the file structure. I like to keep each complete version in a separate folder and then make backups on other drives of those folders, since i've lost too many project files over the years by not taking these steps (when it's really late and i'm really tired, i tend to do stupid things and lose work that way...). Painful.

However, i did try to add the individual paths to "Other unit files" in "Project" > "Project Options" > "Compiler Options" but when i open the Compiler Options window, it does not show any paths and it won't allow me to add any paths.

I did go through some of the Lazarus internals files with Notepad++, and deleted any reference to older versions of my project, then reran Lazarus and recompiled again....still the smae result. I'd really like to know why using flat file structures doesn't work. I'd prefer to treat each up version of my project as a completely new project.

I've decided to completely uninstall Lazarus, including registry settings and any dangling files, and reinstall it. It's painful but what other choice do i have? I'll post what the results are after i'm done.

Thanks for your suggestions.

Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 07:25:25 pm
I completely uninstalled Lazarus including registry entries, then reinstalled it. I loaded the new project and ran it and...the old program exe popped up!

I then renamed all of the previous version folders and compiled and ran the project and... still showing the old project exe (version 17).

I then deleted the exe file (version 23) in the current working project folder. Compiling / building worked without error. But as soon as i tried to Run the code, i get the error:

"No program file (my project name).exe found".

What's happening here? Anybody have any ideas?
Title: Re: ide runs older version of my project
Post by: af0815 on September 12, 2019, 08:23:21 pm
check. the path in your projectoptions. after check the run options. you must have a problem with one of the options.
Title: Re: ide runs older version of my project
Post by: lucamar on September 12, 2019, 09:16:01 pm
Would you or anyone else know where the project source path is defined? I'd love to take a look and see if that's the source of the problem.

All the paths for the application, other than the common ones (fpc, LCL, etc.) and any you may have custom-set globally (as default for all projects), are stored in the LPI file. That's the first stop to check for extraneous paths.

The second and third places are the file environmentoptions.xml, in Lazarus's configuration folder, and fpc.cfg (you might have to use fpc -va to find which and where it's read from).

HTH.
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 11:04:17 pm
Thank you Andreas and lucamar for your responses.

In order:
* i have checked Project Options and in the Compiler Options window i tried both adding (to the Other unit files" box the built-in template as well as the putting the path to my working project. For the latter, I had to "Import" it, as when i click on the Open Files glyph, the popup window remains unpopulated. However, adding either of htese to the path and then clicking "OK" brings up an error window. See the attachment.

* regarding the Run "Configure Build+Run File": i have tried adding my working directory path to both the Run and Build windows, and then without (default). Since default directory is the current working directory, i didn't expect it to change the behavior of the IDE, and it didn't.

* I have checked the project lpi files with a text editor and found no reference to other directories. I also checked all the XML and cfg files in the Users\...\lazarus/fpc directory and, again, didn't find any reference to older projects of mine. Expected, as it is a new install...

* i tried using fpc -va and got a very long, verbose list which i tried to peruse but didn't see any references to my project directory or files. What should i be searching for?

Before re-installing Lazarus, i first uninstalled it then searched for any leftover file on my drive, including the registry. I deleted these wherever i found them. I then reinstalled Lazarus (same version, 2.0.4) and checked the "delete leftover files" (something like that), and reinstalled all the component packages that i use. On first boot up of the IDE, Lazarus IMMEDIATELY went to my project working directory. How did it find it on the very first run of the IDE?? WHERE is this information being saved? There must be another location that Lazarus keeps this information, but i haven't been able to find it. Is it hidden in the directories? If so, can anyone please tell me where it is so that i can deal with it once and for all?

In any case, if i install a version of my project's EXE into the ew project folder, the IDE seems to be compiling but the old EXE runs. If i delete the old EXE form my working folder, i get the message "No program file ("...my program.EXE" found".

What is causing this behavior? I'm still no closer to understanding it than i was when i first started posting, although i have learned a bit more about the IDE settings.

Still looking for a solution....if anyone has seen this before or understands what's going on, i'd appreciate your input.

Thanks again to lucamar, Andreas and the others that have helped. It's much appreciated.

Cheers



Title: Re: ide runs older version of my project
Post by: howardpc on September 12, 2019, 11:07:48 pm
Do you have an antivirus running?
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 11:14:23 pm
Thank you for the reply. Yes but it was always running before when i was developing hte earlier versions.
Title: Re: ide runs older version of my project
Post by: cymatics on September 12, 2019, 11:21:25 pm
wp,

I forgot to mention that i built a  simple project as you had suggested. Both projects work well, no issues.

I would start from scratch on this project (ie: using New Project) but the forms are quite complicated, so i am first trying to see if i can import the existing forms and build a new project around them.

Do you, or does anyone, know what the best way to go abut this is?

Thanks again in advance for any help.

Title: Re: ide runs older version of my project
Post by: wp on September 12, 2019, 11:50:54 pm
On first boot up of the IDE, Lazarus IMMEDIATELY went to my project working directory. How did it find it on the very first run of the IDE?? WHERE is this information being saved?
This indicates that you probably installed the new Lazarus version but kept the old config settings - which may not be optimal.

Where is the config folder, i.e. where did Lazarus get this information from?

In Lazarus, go to "View" > "IDE Internals" > "About IDE". The highlighted line in the attached screenshot shows the folder which contains all the configuration files. Close the IDE and delete this folder (or rename it to keep a backup) - next time when Lazarus starts it does not find its configs and silently creates default settings. The bad thing: you must restore all your settings manually again and reinstall all packages. For a test I'd only install the packages which are needed for your project immediately - nothing else, there is a risk that you do the same misconfiguration error again and again.

When the issue still occurs afterward:
Ideally you should try to remove everything unnecessary from your project and post the rest so that we can have look. But maybe it is sufficient to look only at the lpi file because this is where I would expect the error to be. Can you pack the lpi into a zip and upload it this way here?
Title: Re: ide runs older version of my project
Post by: cymatics on September 13, 2019, 12:23:13 am
Hi wp,

Thank you for the detailed explanation. I must have inadvertently missed the config settings, not sure how. I attached my "View IDE" results here. Also, i have only been installing the packages i need, as you suggested.

I am currently trying to build and run a project using only the .pas files of my original., giving the project a different name. I have reinstalled the necessary ("uses") components for the project. Now when i compile / bild and run, my main window doesn't open but the IDE says it is running. This is a new wrinkle.

I'm going to try a couple of more things and if nothing works, i will do as you suggest. I am also attaching the lpi file here for you.

Thanks again!




Title: Re: ide runs older version of my project
Post by: cymatics on September 13, 2019, 12:59:52 am
I finally managed to get the project running again. It required the following:

* Copy only the .pas and .lfm files of my project to a new blank directory
* start a new project in the IDE and in Project inspector, load the .pas files as well as the required units
* modifying the .lpr file to include Application.CreateForm(..) for each of the forms since they these lines weren't included in using the IDE tools

Now it seems to be back on track and building and running hte correct file.

A big "Thank you!" to those who helped. It got me t exploring and finding out finally what was not working.

Cheers.
Title: Re: ide runs older version of my project
Post by: wp on September 13, 2019, 01:09:43 am
Nice that you got it working. Can you copy this regenerated project now?

But there are some things which I don't understand. Why can't you copy the .lpi and .lpr files? Why do you have to add Application.Createform manually?

Thanks for the lpi file - it looks normal (except for the many packages - do you really need all of them?). Could you also provide a zipped version of the lpr file (which matches the version of the lpi that you already have uploaded, i.e. the old non-working version)? I should already have requested it in the first place.
Title: Re: ide runs older version of my project
Post by: cymatics on September 17, 2019, 07:47:04 am
Hi wp,

Apologies for the tardy reply. Been getting some last minute things ready for an imminent trip.

At this moment i can only give you a quick reply.

I did originally copy the lip and lpr files but that didn't work. I'm sure where i went wrong, after simply doing project "save as.."  in another folder, Lazarus wouldn't run the project and kept giving me errors (sorry, i don;t remember which at that time). I ended up editing files looking for the cause and i could never get it right (ie: project wouldn't compile as a new project, always falling back to the old project). Finally, i created a new folder for th e updated project, went tothe original folder and did "project save as..." to the new folder, saved the .pas files o the new folder under different names, and used the project inspector to add the new .pas files to the  new project. I had to also modify the .lpr file to insert the missing non-primary forms (dialogs) since they were missing. All in all, it was obviously a series of my own screw-ups that garbled the project files, since this was the first Lazarus project i have worked on and i am still unfamiliar with the IDE tools.

In short: culpa mia est...

I am leaving day after tomorrow, so i will have to wait until i get back to see if i can send you the old files you requested.

Thanks very much again. Your help is really appreciated.

Title: Re: ide runs older version of my project
Post by: lucamar on September 17, 2019, 03:50:27 pm
For future reference, you didn't need to add the "CreateForm", etc. by hand; after copying the .lfm/.pas files to the new folder and creating the new project, you can either open the "Project Inspector" (menu "Project") and use "Add Files from File Sytem", or use "File -> Open" to open the .lfm/.pas and then, in the "Project Inspector", use "Add editor files" to add them.

This last can also be done by typing "Shift+F11" in the editor, to add a single, currently opened unit/form.

After adding all the forms/units, open "Project Options", go to "Forms" and set which should be "auto-created".

It sounds like more work when written than it really is in practice, and it has the advantage that you don't run the risk of missing any step that the IDE takes to do it.
Title: Re: ide runs older version of my project
Post by: wp on September 17, 2019, 05:53:51 pm
[...] after simply doing project "save as.."  in another folder [...]
This is not the correct way to make a backup copy of a project. When you call "Project" > "Save as" only the project files (.lpi and .lpr) are saved to the new folder, the units remain at their old location. References to the units are changed such that the units are found from the project in new folder. So, when you compile the project in the new folder it will use units from the old folder.

In order to make a backup copy of a project you can use "Project" > "Publish project" which just copies all required files to a new directory but does not change any unit references. Alternatively you can also simply use the file manager of the operating system, outside Lazarus, to copy the project folder.
Title: Re: ide runs older version of my project
Post by: valdir.marcos on September 18, 2019, 01:17:39 am
[...] after simply doing project "save as.."  in another folder [...]
This is not the correct way to make a backup copy of a project. When you call "Project" > "Save as" only the project files (.lpi and .lpr) are saved to the new folder, the units remain at their old location. References to the units are changed such that the units are found from the project in new folder. So, when you compile the project in the new folder it will use units from the old folder.

In order to make a backup copy of a project you can use "Project" > "Publish project" which just copies all required files to a new directory but does not change any unit references. Alternatively you can also simply use the file manager of the operating system, outside Lazarus, to copy the project folder.
End of the mystery.
Thank you all.