Recent

Author Topic: [SOLVED] Getting a string for a variable name  (Read 2236 times)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
[SOLVED] Getting a string for a variable name
« on: November 03, 2017, 07:08:13 am »
Yes, the question is soooo obscure, I can't even tell if it's sane :D

We have a TObject.ClassName. I can use it to get the class instance name.

Now for the problem.
I have some data construct (a TObject-based data container with its own write and read capabilities) which is written into a XML file and subsequently read.
E.g. I need to write "MaxX=1" but, e.g. "maxx=1" looks like a different value to reader/loader. So, I need to back-track that the value would be equal (with equal capitalization) in two different parts of the code (not that it's too complex, but a bit annoying as the data becomes more complex and more numerous).

In other words is there a way I can write: Container := RootNode.ChildElement({I %VariableName(Container)%}); instead of Container := RootNode.ChildElement('Container'); or at least to Container := RootNode.ChildElement(SomePredefinedStringArray[%Container]); where reference goes to variable name, not it's memory pointer as it's not unique.
As a workaround I could "Stick" to the pointers in the specified data container in constructor Create but it looks dirty and overcomplicated (still that'll guarantee that read and write routines of this class will return always identical names for the read/written variables).

I know there is no way to do this. And that the whole question is stupid and even crazy. But just to make sure  :-[
« Last Edit: November 03, 2017, 11:02:48 am by Eugene Loza »
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: Getting a string for a variable name
« Reply #1 on: November 03, 2017, 11:02:38 am »
Nevermind. I'm stupid  :-X
Just a set of private class constants would do the job perfectly :)
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

 

TinyPortal © 2005-2018