Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error when using Activecontrol in when event

Status
Not open for further replies.

davidy

IS-IT--Management
Apr 19, 2002
13
NL
Hi,

I have to following situation:
When entering a textbox I use a function in the When and Valid event. In this function I use the ActiveControl property. Now in the valid event this works great but in the When event a get the message "ACTIVECONTROL is not an object"

WAIT WINDOW ofrmQu_edit1.ActiveControl.name
WAIT WINDOW _screen.ActiveForm.ActiveControl.name

Please help!

Also did it in the GotFocus event but also there I get the error.
The textbox is active because after ignoring the message the cursor is returned in it.

Thanx
 
Hi David


The when event fires even before the focus is shifted to the object. That means, the ActiveControl is still the previous control. If that previous control is not existing, then you are getting an error.

Gotfocus event fires after the when event returns .t. and the control gets focus. So the activecontrol is the object itself in this case.

That explains the error. :)


____________________________________________
ramani - (Subramanian.G) :)
 
Davidy,

Given that you are working in the When event, you can use THIS to refer to the control on question.

So, instead of this:

WAIT WINDOW ofrmQu_edit1.ActiveControl.name

try this:

WAIT WINDOW THIS.name

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Yes, that is very important basic thing, the note from Mike.

Inside the form (and all its controls) code always use

THIS. to refer the control,
THIS.Parent. to refer controls container,
THISFORM. to refer the form.

Avoid using of _ActiveForm, _ActiveControl. If there is no other possibility in some code outside of form, always make a test, if the object exists, f.e.:

IF TYPE( _screen._ActiveForm )=[O] AND NOT ISNULL( _screen._ActiveForm )
DO something WITH _screen._ActiveForm
ENDIF
 
Thanx for the replys,

ramani:
I tried the gotfocus event but also then I get the message: "ACTIVECONTROL is not an object"

MikeLewis:
When I try to option you gave me and I put This.name in the function (that is located in a .prg) I get the message: "THIS can only be used within a method"

Do you maybe have another option?

Thanx
 
Davidy,

When I try to option you gave me and I put This.name in the function (that is located in a .prg) I get the message: "THIS can only be used within a method"

But you said in your original message that you wanted to put the code in the When event. You didn't say anything about putting it in a PRG.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
-> davidy:

If you call the code outside the form, then correct style (and maybe only one correct style) is following:

In form:
DO procedureX WITH THISFORM --or-- =procedureX( THISFORM )

In f.e. .prg outside of form:
PROCEDURE procedureX( toForm )
toForm.MethodX()
lcVariable = toForm.TextBox1.PropertyX()
toForm.Label1.Visible = .F.

...and so on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top