Link to home
Start Free TrialLog in
Avatar of namcit99
namcit99

asked on

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
Avatar of kretzschmar
kretzschmar
Flag of Germany image

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 ;-)
Avatar of namcit99
namcit99

ASKER


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
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Self  is NOT right

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

I am studying Delphi . So i feel confused

When i use Self . Only var of Object like Tedit and Construtor like Create, CreateNew, CreateParent
??
>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 ;-)