TimC 0 Posted June 9 Is there a setting or a shortcut that will rename all references to a VCL object that has been renamed? Thanks in Advance -Tim C. Share this post Link to post
Remy Lebeau 1394 Posted June 10 (edited) If you simply rename the object manually, then you have to update all references manually. A search & replace may help, but is spotty and may have to be performed multiple times depending on how many files you need to update.. To rename everything automatically, you need to use the Refactor > Rename feature and let it update all of the references for you. Edited June 10 by Remy Lebeau Share this post Link to post
David Heffernan 2345 Posted June 10 Another good reason not to write code which depends on the string name of objects. Share this post Link to post
Stano 143 Posted June 10 2 hours ago, David Heffernan said: Another good reason not to write code which depends on the string name of objects. Hm, and how is it done? I can't imagine. Share this post Link to post
TimC 0 Posted June 10 Mr. Heffer How does one write code not relying on object names? Share this post Link to post
TimC 0 Posted June 10 I found (3) techniques that allow one to access an object by other than its name BUT there seems to be one point in each of these techniques that require the object name to be changed in a single spot, essentially the object name is linked to an abstraction layer of sortS (COURTESY OF CHAT GPT: 1. USING OBJECT REFERENCE var MyObject: TMyObject; begin MyObject := Form1.SomeObject; MyObject.Property := Value; MyObject.Method; end; 2. USING AN INTERFACE var MyInterface: IMyInterface; begin MyInterface := Form1.SomeObject as IMyInterface; MyInterface.Property := Value; MyInterface.Method; end; 3. USING A LOOKUP TABLE var ObjectDictionary: TDictionary<string, TObject>; begin ObjectDictionary := TDictionary<string, TObject>.Create; ObjectDictionary.Add('ObjectKey', Form1.SomeObject); (ObjectDictionary['ObjectKey'] as TMyObject).Property := Value; (ObjectDictionary['ObjectKey'] as TMyObject).Method; ObjectDictionary.Free; end; 4. USING RUNTIME TYPE INFORMATION: uses RTTI; var Context: TRttiContext; RttiType: TRttiType; RttiProp: TRttiProperty; Obj: TObject; begin Obj := Form1.SomeObject; RttiType := Context.GetType(Obj.ClassType); RttiProp := RttiType.GetProperty('Property'); if Assigned(RttiProp) then RttiProp.SetValue(Obj, Value); end; At first glance, I am drawn to the idea of the LOOKUP Table, it seems like a pretty clean way to setup a central point to manage object reference Any comments on this topic from the group? Best Regards -Tim C. Share this post Link to post
David Heffernan 2345 Posted June 10 1 hour ago, TimC said: Mr. Heffer How does one write code not relying on object names? You use variables which contain references to them. Share this post Link to post