Forum > LCL

Accesin to a property by a string

(1/1)

BlueIcaro:
Hello, my program reads a file like this:

--- Quote ---atmega328.upload.protocol=stk500
atmega328.upload.maximum_size=30720
atmega328.upload.speed=57600
atmega328.bootloader.low_fuses=0xFF
atmega328.bootloader.high_fuses=0xDA
--- End quote ---

I read one line, and I got (after remove some parts):


--- Quote ---String1 := 'upload.protocol'
data1 := 'stk500'

--- End quote ---


I have a object with like this:


--- Quote ---MYobject.upload.protocol
Myobject.bootloader.low
(etc. The object have  property called like the lines)
--- End quote ---

Well I want to assign Data1 to MYobject.upload.protocol

I thought:
 
--- Quote --- IF String1 = 'upload.protocol' Then
   MYobject.upload.protocol := data1;
ElseIf (...)

--- End quote ---

But Can I access to the properties, in other way more easy?, like:

--- Quote ---MyObject.[String1]:=Data1
--- End quote ---


I hope I explain... because It's a very complicate explain this problem for me in english

/BlueIcaro

eny:
Serial communication with an atmega328? I prefer PIC's  :D

I can think if several solutions:
Use an array property like TStringList.Values[...]. This makes using the class easier, but you'll still have to check the string value of the parm within the class.

Use some sort of RTTI. But that's probably a bit messy because you're distributing the parms over several classes.

Swap responsibilities: give the classes that need parameter values (upload, bootloader) access to the settings repository, so they can request the values when needed.

BlueIcaro:
Thank you for your answer. I think I don't have choice, I'll have to hard-code.

I'm making a new IDE for Arduino, because the original it's code in Java, and in my opnion it's a little bit limited. So I'm trying to do a new IDE, like Lazarus. By the moment the proyect is very new, only a few forms, and code.


--- Quote ---Serial communication with an atmega328? I prefer PIC's
--- End quote ---
Well, I have a board called Arduino, check the www.arduino.cc.

/BlueIcaro

Leledumbo:
TStringList supports Key=Value pairs, so if you do:

--- Code: ---StringList.Add('MyKey=MyValue');

--- End code ---
You can get MyValue or assign MyKey with:

--- Code: ---MyValue := StringList.Values['MyKey'];

StringList.Values['MyKey'] := MyValue;

--- End code ---
You can also use true map data structure with TFPGMap from fgl unit.

Navigation

[0] Message Index

Go to full version