?
Solved

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

Posted on 2005-04-26
6
Medium Priority
?
183 Views
Last Modified: 2010-05-18

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
0
Comment
Question by:namcit99
  • 3
  • 3
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 13873407
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
 

Author Comment

by:namcit99
ID: 13873506

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
 
LVL 27

Accepted Solution

by:
kretzschmar earned 80 total points
ID: 13873528
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:namcit99
ID: 13873774

Self  is NOT right

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

I am studying Delphi . So i feel confused
0
 

Author Comment

by:namcit99
ID: 13873779

When i use Self . Only var of Object like Tedit and Construtor like Create, CreateNew, CreateParent
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 13873862
??
>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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question