Lazarus

Programming => General => Topic started by: wytwyt02 on November 14, 2019, 09:44:49 pm

Title: Cannot relaod Resouces when regenerate new lrs file
Post by: wytwyt02 on November 14, 2019, 09:44:49 pm
I i have a txt file wanna to be generated to the project1.lrs file, and load it from my program.

But If I change the txt file and then regenerate project1.lrs, and compile my project, the project1.lrs file will back to before.

There is only way That remove lib and restart IDE can fix that problem
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: jamie on November 14, 2019, 10:47:00 pm
Please read this..
https://wiki.freepascal.org/Lazarus_Resources  (https://wiki.freepascal.org/Lazarus_Resources)
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: wp on November 14, 2019, 10:56:13 pm
regenerate project1.lrs, and compile my project, the project1.lrs file will back to before.
Try "Run" > "Build" (or "Clean up and Build") instead of "Run" > "Run" or "Run" > "Compile".
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: wytwyt02 on November 15, 2019, 02:05:42 am
Please read this..
https://wiki.freepascal.org/Lazarus_Resources  (https://wiki.freepascal.org/Lazarus_Resources)

I have read this topic, but nothing about that problem, this might a bug
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: wytwyt02 on November 15, 2019, 02:06:06 am
regenerate project1.lrs, and compile my project, the project1.lrs file will back to before.
Try "Run" > "Build" (or "Clean up and Build") instead of "Run" > "Run" or "Run" > "Compile".

I have tried, not work
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: winni on November 15, 2019, 03:30:51 am
Hi!

Delete or rename the old lrs file.

Create a new lrs file.

Build (and NOT compile)  you project.

Should work.

Winni
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: jamie on November 15, 2019, 11:23:25 pm
I assume you created a RC file with the contents of this for example..

TagNameToTheStringData  RT_RAWDATA  TextFilename.txt


and in your code, somewhere..

{$R MYRCFILE.RC}

The MYRCFILE.RC is just a text file of the contents as an example above..

The compiler will compile the RES version of the file..
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: wytwyt02 on November 16, 2019, 10:49:05 am
I assume you created a RC file with the contents of this for example..

TagNameToTheStringData  RT_RAWDATA  TextFilename.txt


and in your code, somewhere..

{$R MYRCFILE.RC}

The MYRCFILE.RC is just a text file of the contents as an example above..

The compiler will compile the RES version of the file..

I am not use rc file , i am use lrs
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: jamie on November 16, 2019, 05:15:55 pm
part of your problem.
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: winni on November 16, 2019, 05:48:47 pm
Hi!

If you project name is "Project1" you should never give a resource that name: It is used by the IDE for the managment of this project!!! Call it "MyText" or whatever.

I don't know if this is solved: I remember situations when the IDE and/or the compiler did not recognize, that the resource changed. So while you are developing give your resource a new name with every change: MyText1, MyText2, MyText3 ....

Winni
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: jamie on November 16, 2019, 05:51:56 pm
I've found that the project will not detect changes to files unless they are in the project list.

For file sources that need to be forced as a recompile making changes in the file while open usually triggers a full rebuild of that file..

 But getting back to resources, I've never done what the poster is attempting in that way, I've always used the precompiled name.res from the resource compiler or use the name.rc and let the compiler add it to the resource.
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: wp on November 16, 2019, 06:36:06 pm
The more the IDE knows about the resources the more things can be done automatically.

The attached demo links a text file "resource-text.txt" as a resource to the binary. The resource file is not created as a separate lrs or res file, but by adding the "resource-text.txt" as a Resource to the project options ("Project" > "Project options" > "Resources" > "Add" > select the file; resource type is RCDATA; the string given in box "Resource" is the name under which the resource is found by the application). Additionally the "resource-text.txt" is added to the project files ("Project" > "Project options" > "Add" > "Add files from file system" > Select resource-text.txt). This way the IDE know that a paricular file is to be linked as a resource, and it can keep track of changes within the file.

Run the demo. Click the button - the contents of "resource-text.txt" are read from the application's resources and displayed in the memo.

End the program. Change the contents of "resource-text.txt". Press F9 to compile and run. When you click the button you will see the new contents.

If "resource-text.txt" would not be included in the project, the IDE would miss that the file content has been changed and the button click will show the unchanged file. In this case you'd have to "Build" the project, then "Run".
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: wytwyt02 on November 16, 2019, 09:56:08 pm
The more the IDE knows about the resources the more things can be done automatically.

The attached demo links a text file "resource-text.txt" as a resource to the binary. The resource file is not created as a separate lrs or res file, but by adding the "resource-text.txt" as a Resource to the project options ("Project" > "Project options" > "Resources" > "Add" > select the file; resource type is RCDATA; the string given in box "Resource" is the name under which the resource is found by the application). Additionally the "resource-text.txt" is added to the project files ("Project" > "Project options" > "Add" > "Add files from file system" > Select resource-text.txt). This way the IDE know that a paricular file is to be linked as a resource, and it can keep track of changes within the file.

Run the demo. Click the button - the contents of "resource-text.txt" are read from the application's resources and displayed in the memo.

End the program. Change the contents of "resource-text.txt". Press F9 to compile and run. When you click the button you will see the new contents.

If "resource-text.txt" would not be included in the project, the IDE would miss that the file content has been changed and the button click will show the unchanged file. In this case you'd have to "Build" the project, then "Run".

Thanks! it is better way to manage resource, This shoule be documented in wiki, https://wiki.freepascal.org/Lazarus_Resources

and seems rc resource is better than lrs resource, because rc resource is ide support in lazarus
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: wytwyt02 on November 16, 2019, 10:39:40 pm
The more the IDE knows about the resources the more things can be done automatically.

The attached demo links a text file "resource-text.txt" as a resource to the binary. The resource file is not created as a separate lrs or res file, but by adding the "resource-text.txt" as a Resource to the project options ("Project" > "Project options" > "Resources" > "Add" > select the file; resource type is RCDATA; the string given in box "Resource" is the name under which the resource is found by the application). Additionally the "resource-text.txt" is added to the project files ("Project" > "Project options" > "Add" > "Add files from file system" > Select resource-text.txt). This way the IDE know that a paricular file is to be linked as a resource, and it can keep track of changes within the file.

Run the demo. Click the button - the contents of "resource-text.txt" are read from the application's resources and displayed in the memo.

End the program. Change the contents of "resource-text.txt". Press F9 to compile and run. When you click the button you will see the new contents.

If "resource-text.txt" would not be included in the project, the IDE would miss that the file content has been changed and the button click will show the unchanged file. In this case you'd have to "Build" the project, then "Run".

In the Project Option -> Resource, What is different between the resouce types?(ICON, CURSOR, HTML, RCDATA)?
Title: Re: Cannot relaod Resouces when regenerate new lrs file
Post by: jamie on November 16, 2019, 11:02:25 pm
the difference is how they are stored and what the resource compile expects to find in the information you give it.

 These data fields are not directly stored as plain ole text, except maybe for the String types
but even those have a header etc in the file for it to keep track of.

 in your case you need to use the STRING type because that is what you are giving it, one long string.

I've never used the Project options to do this because I didn't know it existed however, I still like the in code method because I can see it and that is how it was done in the Delphi days... well at least the days I came from ;)