Help with referencing components by name lazarus / 13-General ---------------------------------------------------------------------- FlippityWidget · 2008-09-02 06:32 Hello, My thanks to the creators of FP and Lazarus. I need some help with using components. Let me explain first that I am an "old dog" and it's been a while since I have programmed in Pascal. Turbo Pascal (TP) for DOS was the version I last used and that was only for a brief time. I have a basic understanding of OOP but have a long way to go yet with understanding many of the "new" (new to me anyway) concepts that are available in Free Pascal/Lazarus. Nor have I used C or any "main stream" language since my TP days. I have been programming but in a limited scripting language for a game server. It resembles Pascal but as I said it's limited. Anyway, I am trying to create a GUI editor for some configuration files. They are in plain text and have a format something like the following: TimeOut=10 CommandLevel=2 IsLocal=1 Path=c:\ufp\earth The file contains basically three types of data: string, boolean and multiple choice options. My plans were to create my GUI and name the components with the same name as the parameters in the text file. I thought there was a way to look-up a component by name and then reference that component in some way and thereby have access to its members. Thus I could write my program to do something like the following: 1. read the text line from the file 2. parse the line and get the parameter name and value 3. look-up and reference the component by parameter name 4. Assign the value to the proper member of the referenced component 5. repeat until EOF Thus in the first line of my example text file above I would have a TEdit component named TimeOut and when I read in the TimeOut=10 line from the file I would be able to look-up and reference that component and then perform an assignment of the value (10) to the Text member of the component. I spent a long time attempting to discover if this was possible and found a function in the 'classes' unit called FindNestedComponent that will allow me to pass it the name of the component I am interested in. However I only have access to the members of the parent object 'TComponent', such as Name and none of the child members of the referenced component. Is what I want to do possible? As it stands right now I can (and temporarily have) accomplish(ed) my goal with a long series of Case/switch statements but I would think there's a more elegant way to handle this. I tried to find an example application for handling ini or configuration files of this this type but was unsuccessful. I would appreciate any help you can offer. Thanks in advance. ---------------------------------------------------------------------- MyIden · 2008-09-25 16:22 The example you have shown is very similar to an ini file, however i don't know if there are ini files allowed without section headers. But you may load the file into memory and then in the beginning of file you can add section header and then treat the file as ordinal ini file. So if you like here you are : - some ini handling component : Code: [Select] if fileexists(app_directory + 'Config.ini') then  begin     IniFile := TInifile.Create(app_directory + 'Config.ini');     mplayer_path := IniFile.ReadString('MPLAYER','path','mplayer');     mplayer_extopt := IniFile.ReadString('MPLAYER','extopt','');     mplayer_extvol := IniFile.ReadBool('MPLAYER','extvol',false); end; *************************************** Ini file ; Ustawienia odtwarzacza muzyki. [MPLAYER] ; Scierzka do odtwarzacza path=mplayer ; Dodatkowe opcje odtwarzacza np. -ao oss:/dev/dsp1 extopt= ; Czy odtwarzacz ma stosować ustawienia dźwięku zapisane w ; plikach kompozycji. extvol=1 ; Ustawienia oświetlenia. Returning to your post i think that you want something like this : Code: [Select] procedure TForm1.ON1Click(Sender: TObject); begin   for x := 1 to 50 do begin   if TSpeedButton(sender).Name = 'ON' + inttostr(x) then begin      bufor[x+8] := #$FF ;      break ;      end;     end; end; I'm calling many buttons by their names ( have 40 buttons ). you can do so with other components. Hope that this is what you are looking for.