Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Set focus without using setfocus()
Message
From
27/02/2004 13:46:56
 
 
To
27/02/2004 13:11:25
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00881299
Message ID:
00881578
Views:
48
Excellent observation Hilmar. I was just testing if you were paying attention :> But actually this was just an example of using object references in the code to cause "Pseudo SetFocus".

The Ok example was included to illustrate how to remain on the current object or allow next object navigation. The code does depend on the Tab order of the objects, If anyone were to choose to use code like this to avoid the consequences of Setfocus in a Valid event, they MUST insure that objects which are referenced have a non-zero tabindex.

Thanks for the critique.

Glenn




>That is indeed an interesting approach. However, I have two complaints about your code. One, after "case Ok = .T." and "case Ok = .F.", none of the remaining code will execute (unless it is assumed that Ok can have a null value). Two, the TabIndex may have missing numbers, if an object is deleted. Since the solution is otherwise quite efficient, I would simply the developer makes sure to set the TabOrder interactively after deleting objects.
>
>>To "Setfocus" to another control using the return value from the valid event is made more acceptable using the this control / that control offset technique like this:
>>
>>textbox::valid
>>
>>do case
>>  Case Ok = .t.
>>    RetVal = 1
>>  Case Ok = .f.
>>    RetVal = 0
>>  case goto_textname
>>    retval = this.tabindex - this.parent.textname.tabindex
>>  case goto_texttype
>>    retval = this.tabindex - this.parent.texttype.tabindex
>>  case goto_ComboYear
>>    retval = this.tabindex - this.parent.ComboYear.tabindex
>>endcase
>>return retval
>>
>>
>>Glenn
>>
>>>>I agree with your approach of doing a form level valid completely. And we are moving to doing more of this.
>>>>However our large existing app has around 400 forms - so it would be quite a task at this stage.
>>>
>>>Yes, that looks like a lot of work.
>>>
>>>>So we've taken to KEYBOARDing CHR(9) s to workaround the setfocus issue. But this is a horrible kluge.
>>>
>>>That should be more or less equivalent to valid (number). Also a kludge: in both cases you have to count objects, and adjust if you insert additional objects.
>>>
>>>BTW, with the KEYBOARD command, I think you can also use "{TAB}" instead of chr(9). This might make it more readable.
>>>
>>>As a workaround, if you can't SetFocus() within the Valid() event, you might postpone it with a Timer (with a brief interval). But I don't know whether this works; perhaps the Valid() will then fire again.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform