Recent

Author Topic: Cannot relaod Resouces when regenerate new lrs file  (Read 1000 times)

wytwyt02

  • New Member
  • *
  • Posts: 44
Cannot relaod Resouces when regenerate new lrs file
« 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
« Last Edit: November 14, 2019, 09:51:23 pm by wytwyt02 »

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #1 on: November 14, 2019, 10:47:00 pm »
Number 1 at blue screen app creations!

wp

  • Hero Member
  • *****
  • Posts: 6502
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #2 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".
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wytwyt02

  • New Member
  • *
  • Posts: 44
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #3 on: November 15, 2019, 02:05:42 am »
Please read this..
https://wiki.freepascal.org/Lazarus_Resources

I have read this topic, but nothing about that problem, this might a bug

wytwyt02

  • New Member
  • *
  • Posts: 44
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #4 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

winni

  • Hero Member
  • *****
  • Posts: 609
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #5 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

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #6 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..
Number 1 at blue screen app creations!

wytwyt02

  • New Member
  • *
  • Posts: 44
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #7 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

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #8 on: November 16, 2019, 05:15:55 pm »
part of your problem.
Number 1 at blue screen app creations!

winni

  • Hero Member
  • *****
  • Posts: 609
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #9 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

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #10 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.
Number 1 at blue screen app creations!

wp

  • Hero Member
  • *****
  • Posts: 6502
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #11 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".
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wytwyt02

  • New Member
  • *
  • Posts: 44
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #12 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

wytwyt02

  • New Member
  • *
  • Posts: 44
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #13 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)?

jamie

  • Hero Member
  • *****
  • Posts: 2174
Re: Cannot relaod Resouces when regenerate new lrs file
« Reply #14 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 ;)
Number 1 at blue screen app creations!