From: Robert Subject: Re: [delphi] Creating Object names from variables Date: Thu, 10 Aug 1995 10:47:09 +0200 >I have an app which utilises various components depending on >selections made by the user (say by entering a number 1 to 6). Each >of the components is named Edit1, Edit2 etc. How can I refer to these >components by combining the 'generic' component name eg 'Edit' with a >variable, sort of > >pick : = 3; >(Edit + IntToStr(pick)).Text := 'You picked this one'; > >Russell Weetch I think the easiest solution would be to use the following function (applies to all components, so you can use it for your form) function FindComponent(const AName: string): TComponent Your code would look something like: pick : = 3; TEdit(FindComponent(Edit + IntToStr(pick))).Text := 'You picked this one'; Hope this helps, Robert. ------------------------------------------------------------------------------- From: keeper@mindspring.com (Mark Johnson) Subject: Re: Error in FindComp tip Date: Fri, 18 Aug 1995 02:26:06 -0500 Apparently a little clarification is needed: FindComponent is a method of TComponent. It will scan through the component's Components[] list property for an owned component of the given name, and will return that component if found. The return value will otherwise be nil. For example, if you have a form (Form1) that owns three TEdits named 'Edit1', 'Edit2', and 'Edit3', then the following code would return the TEdit corresponding to the given integer (or nil if none found): function GetEdit(i : integer) : TEdit; var cmp : TComponent; begin Result := nil; cmp := Form1.FindComponent('Edit' + IntToStr(i)); if (cmp <> nil) then Result := (cmp as TEdit); end; Keep in mind that if Form1 does not own the edits in the example above, this function will not find them. Hope this does the trick. --Mark Johnson ______________________________________________________________________________ Mark R. Johnson _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_ Atlanta, GA USA _/ http://www.mindspring.com/~cityzoo/cityzoo.html _/ keeper@mindspring.com _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/