New topic: Calling Objects by name?
<http://forums.realsoftware.com/viewtopic.php?t=47552> Page 1 of 1 [ 7 posts ] Previous topic | Next topic Author Message simulanics Post subject: Calling Objects by name?Posted: Tue Apr 09, 2013 4:17 pm Joined: Sun Aug 12, 2007 10:10 am Posts: 1041 Location: Boiling Springs, SC I'd like to set the value of a textfield by entering it's name... Example there is a textfield named "TextField1" on a form.... An encryted script is loaded to fill in all the fields...but the fields are not always in the same order or present...so it works as such File Contents: TextField1= "Firstname" TextField2= "Lastname" etc... So...how to call the field by name? TextField("TextField1").Text = Firstname Does not work :-/ I'm missing something. _________________ Matthew A. Combatti Real Studio 2012 r1.2 Visit Real Studio Developer's Spot! Systems I Use: Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8 Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/ Windows Server 2011/CentOS 5.4 /ReactOS/SimOS ~All REAL Compatible~ Top ktekinay Post subject: Re: Calling Objects by name?Posted: Tue Apr 09, 2013 4:41 pm Joined: Mon Feb 05, 2007 5:21 pm Posts: 552 Location: New York, NY You can't do it directly, but you can subclass your TextField and add a field like "Identifier", fill it in appropriately either in the IDE or at runtime, then search each TextField for the matching Identifier when loading your script. To make this faster, you can gather the TextFields into a Dictionary initially using the Identifier as the key. _________________ Kem Tekinay MacTechnologies Consulting http://www.mactechnologies.com/ Need to develop, test, and refine regular expressions? Try RegExRX. Top simulanics Post subject: Re: Calling Objects by name?Posted: Tue Apr 09, 2013 4:51 pm Joined: Sun Aug 12, 2007 10:10 am Posts: 1041 Location: Boiling Springs, SC ktekinay wrote:You can't do it directly, but you can subclass your TextField and add a field like "Identifier", fill it in appropriately either in the IDE or at runtime, then search each TextField for the matching Identifier when loading your script. To make this faster, you can gather the TextFields into a Dictionary initially using the Identifier as the key. Didn't think of that one... in the meantime I settled for //sTextField is fed to the following code via method Dim ControlID as Integer For ControlID = 0 to self.ControlCount -1 If self.Control(ControlID) isa TextField and self.Control(ControlID).Name = sTextField then TextField(self.Control(ControlID)).Text = value end if next ControlID I've been working with C++ and QT Creator for the last couple days for a project and lost my head Once I sat down and got back into the OOP train of thought it became obvious. _________________ Matthew A. Combatti Real Studio 2012 r1.2 Visit Real Studio Developer's Spot! Systems I Use: Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8 Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/ Windows Server 2011/CentOS 5.4 /ReactOS/SimOS ~All REAL Compatible~ Top neonash7777 Post subject: Re: Calling Objects by name?Posted: Tue Apr 09, 2013 4:53 pm Joined: Mon Nov 29, 2010 7:01 pm Posts: 434 EDIT: I see you just found this... -----Original ------ You mean something like this? Function getControlByName(extends w as window, ControlName as string) As control For i as integer = 0 to w.ControlCount If w.Control(i).Name = ControlName then Return w.Control(i) Next return nil End Function Then get it and cast it: Dim c as control = self.getControlByName("TextField1") If c <> nil then TextField(c).text = "woah" Top shaosean Post subject: Re: Calling Objects by name?Posted: Wed Apr 10, 2013 2:04 am Joined: Mon Aug 15, 2011 10:25 pm Posts: 278 You could also go the route of making specific functions for each control type (yeah, lots of work) but you could do the type casting in the return and make your inline code a little easier to read, write and type _________________ Real Studio 2012r1.1 | MacBook Pro i5, 10.6.8 | Windows 7 Top DaveS Post subject: Re: Calling Objects by name?Posted: Wed Apr 10, 2013 9:01 am Joined: Sun Aug 05, 2007 10:46 am Posts: 4737 Location: San Diego, CA Why not create a control array and load the text by the INDEX of the control? // assume S is 'TextArea1="some value" x=instr(s,"=") index=val(mid(s,9,x-9) myTextArea(index)=mid(s,x+1) Crude ... but it is only to illustrate the point _________________ Dave Sisemore iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1 Note : I am not interested in any solutions that involve custom Plug-ins of any kind Top simulanics Post subject: Re: Calling Objects by name?Posted: Wed Apr 10, 2013 2:41 pm Joined: Sun Aug 12, 2007 10:10 am Posts: 1041 Location: Boiling Springs, SC On...but Off-Topic: It was actually for a function I included in my SimScript Plugin Interface to load user information from a website profile for the RSDS Library... SimScripts is basically a front-end for RBScripts so that they could operate outside of a single control context to allow all aspects of Realbasic from within an RBScript and access all controls within a project or generate dynamic controls at runtime. The source of course is not open as it would violate RS Licensing terms since users could generate apps without buying the studio...although it's used in my RealDevSpot.com library for smaller updates... GUI code is generated by a drag n drop interface I made...although can just as easily be entered as plain text... It allows users to download an small encrypted txt-based file for software updates rather than 20-40 MB software updates. I've also used it as a plugin-based system in some pieces of software so greater functionality and features can be added without having to update the software itself....and have added web support and javascript libraries to extent RS web-apps with plugins as well. Here is an encrypted demo of SimScripts and how they work (With Plugin Interface and HTML web demo)....I included a small hexencoder/decoder app to view the rbscripts and/or play around with editing/changing them http://realdevspot.com/SimPlugins.rar _________________ Matthew A. Combatti Real Studio 2012 r1.2 Visit Real Studio Developer's Spot! Systems I Use: Windows XP/Windows Vista/Windows Server 2008 r2/Windows 7/Windows 8 Mac OSX 10.5/Mac OSX 10.6/Mac OSX Server/Ubuntu/Debian/Suse/Red Hat/ Windows Server 2011/CentOS 5.4 /ReactOS/SimOS ~All REAL Compatible~ Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 7 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
