To effort control throught the value of variable. To run command from a string


Dear advisor !

i use D2005

i have a form about 20 edit controls. And a combobox to contain all of the name of edit controls. Example : edtmathpoint, edtphysicpoint, edtchemistrypont, edtLiteraturepoint ...
And after the user choice any value from combobox, that edit control should be focused (Setfocus)
The code from visual foxpro :
lc = 'Thisform' + '.' + 'txtpoint'
&lc..Setfocus

Please should me the command on Delphi
namcit99Asked:
Who is Participating?
 
kretzschmarConnect With a Mentor Commented:
if there is no reference-prefix, then it is allways self like

var e : TEdit;
begin
  e := self.findcomponent(combobox1.text) as TEdit;
  if assigned(e) then
    e.SetFocus;
end;

whereas self is the object where within the findcomponent-method is called like

procedure TFormX.MethodName;
var e : TEdit;
begin
  e := self.findcomponent(combobox1.text) as TEdit;
  if assigned(e) then
    e.SetFocus;
end;

then the findcomponent is called of the current instance of TFormX

meikl ;-)
0
 
kretzschmarCommented:
have no d2005,
but in earlier versions it should work like

var e : TEdit;
begin
  e := findcomponent(combobox1.text) as TEdit;
  if assigned(e) then
    e.SetFocus;
end;

meikl ;-)
0
 
namcit99Author Commented:

your solution is right. But explain a while

findcomponet is a mothod. What is the oject using this method. I try : form2.findcomponent (but get error, form2 is the name of form)

What i ask is the name of oject has been running findcomponent
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
namcit99Author Commented:

Self  is NOT right

The value of name property of Form is RIGHT. Example FormX

I am studying Delphi . So i feel confused
0
 
namcit99Author Commented:

When i use Self . Only var of Object like Tedit and Construtor like Create, CreateNew, CreateParent
0
 
kretzschmarCommented:
??
>Self  is NOT right
why do you think this?
self is allways present for the instance of the object which method is called,
it must not be declared elsewhere

you may discuss the difference of a variable/object reference and object-instance

it is possible to create objects without any variable/object reference like

with TFormX.Create(nil) do
  show;

meikl ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.