Recent

Author Topic: Reading Form Data  (Read 549 times)

diogenes

  • Jr. Member
  • **
  • Posts: 66
    • http://members.chello.at/diogenes
Reading Form Data
« on: October 09, 2025, 09:59:09 am »
When Lazarus compiles a GUI application, it integreates the .LFM data into the executable tu build the forms from them, right?

If so, I'd like to read some data (
Code: Pascal  [Select][+][-]
  1. Caption
and
Code: Pascal  [Select][+][-]
  1. Visible
properties, specifically) out of this to avoid defining the values a second time (which provokes bugs and other problems).
Therefore, please tell me how to do this (a Lazarus Resource?) if, for example, the form has class
Code: Pascal  [Select][+][-]
  1. TExampleForm
, the unut us
Code: Pascal  [Select][+][-]
  1. FEExample
, and the variable where the form is stored is
Code: Pascal  [Select][+][-]
  1. ExampleForm
.

Thanks in advance!

jamie

  • Hero Member
  • *****
  • Posts: 7317
Re: Reading Form Data
« Reply #1 on: October 09, 2025, 11:32:03 am »
Humm, use a resourestring ?
Not sure abt your question but the llm is already a resoure string.
The only true wisdom is knowing you know nothing

diogenes

  • Jr. Member
  • **
  • Posts: 66
    • http://members.chello.at/diogenes
Re: Reading Form Data
« Reply #2 on: October 09, 2025, 04:02:29 pm »
I wat to read the data at runtime. As far as I know, the .lfm file is a tempalte for the Lazarus resource compiled in, or do I misunderstand something?

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1566
    • Lebeau Software
Re: Reading Form Data
« Reply #3 on: October 09, 2025, 06:16:25 pm »
If so, I'd like to read some data (Caption and Visible properties, specifically) out of this

Why? What is the actual use-case here?

to avoid defining the values a second time (which provokes bugs and other problems).

Where are you defining values a second time? What bugs are you trying to avoid?

What is stopping you from simply defining your own constants in your code, and then assigning those constants to your properties at runtime? This way, you don't need to rely on the design-time values at all.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11824
  • Debugger - SynEdit - and more
    • wiki
Re: Reading Form Data
« Reply #4 on: October 09, 2025, 06:28:39 pm »
I would have to spent some time researching this myself. So just top level pointers....

The properties are stored in the LFM file when the IDE edits the form.

AFAIK: When you compiler your app/exe then the LFM is compiled into a binary format (same content, just binary encoded), and that is added to the resources (under a name derived from the forms (class?) name.

So, you can open the resource and load that binary LFM from it (probably see TForm.Create).
But that wont help you much.

You need TReader and the correct "driver" for the binary format.
Yet afaik, TReader will write the read content to the form (I don't know, maybe it can be redirected... / but you are in for a lot of work, even without redirecting).

So why not just load (create) the form. That will not (yet) display it, but allow you to read all the values for its properties.
If needs must, you can then destroy it again.

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Reading Form Data
« Reply #5 on: October 09, 2025, 06:42:29 pm »
Read/WriteComponent. Tstream supports it.
« Last Edit: October 09, 2025, 07:02:06 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

diogenes

  • Jr. Member
  • **
  • Posts: 66
    • http://members.chello.at/diogenes
Re: Reading Form Data
« Reply #6 on: October 09, 2025, 08:46:22 pm »
See, my idea is as follows: Of course I can just create the forms and then retrieve the data from the form instances, but I'd like to keep unloaded what the user doesn't need (yet), but I need the data mnentioned for creeating menu items to let the user access them when he wants them (form Caption converted into a menu item Caption)) and the information if the form ist to bee seen by default layout (by the way, I'm usier AnchorDockimng, which also provides non-default storage or loading of layout).

Correct me, but shouldn't be the data for the form somehow compiled into the binary for creating at startup? If so, the initialization code obviously reads this data, and I'd like to know how it does that to get the data I neeed.

I hope I'm clearer now. Sometimes, my English (non.-native) fails me.

 

TinyPortal © 2005-2018