?
Solved

container objects and setfocus, gotfocus and lostfocus methods

Posted on 2011-03-04
12
Medium Priority
?
1,264 Views
Last Modified: 2012-05-11
I've got a set of custom container objects that are held in a FORM.

I'd like to organise these so that, when the user clicks on one of them, it changes the BACKCOLOR property (to be a highlighted yellow).

Clearly I'm not understanding how SET/GOT/LOSTFOCUS work - can someone enlighten me?

What I've tried to do, within the custom container object class is

(1) use the .CLICK() method to execute THIS.SETFOCUS()

(2) within .GOTFOCUS, change the .BACKCOLOR property to be yellow, and do THIS.REFRESH().

(3) within .LOSTFOCUS, change the .BACKCOLOR property back to the default, and do THIS.REFRESH().

But ... this doesn't work. I've inserted SET STEP ON into each of the three methods. Of these, (1) genuinely happens. But if I try tracing the subsequent code, it looks as if .GOTFOCUS doesn't happen. And .LOSTFOCUS doesn't happen either.

I'm obviously doing something stupid here, and don't understand how these events fire. Can anybody point me towards a nice simple explanation?
0
Comment
Question by:IainMacb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 1000 total points
ID: 35035171
Well, a container isn't really a control being able to get the focus.

I just did a form with a container and a textbox in that container, and put a ? line in gotfocus and lostfocus of the container. Then a second textbox outside of the container. The result is, both events run, but only once.

I don't know if this is a bug or by design, what you could do is bind all inner controls gotfocus to the container gotfocus, but then lostfocus of any of the controls is not necessarily leaving the container.

Maybe you simply setall() in the gotfocus of the other containers to reset the backcolor. Then the gotfocus binding would be sufficient:

container init():
Local loControl
For each loControl in this.objects
    If pemstatus(oControl,"gotfocus",5)
       Bindevent(oControl,'gotfocus', this,'gotfocus')
    Endif
Endfor

Open in new window


And in gotfocus():
Thisform.setall("backcolor",rgb(...),"container") && default color
This.backcolor = rgb(...) && yellow

Open in new window


Replace ... with the color rgb values you want.

Bye, Olaf.
0
 
LVL 42

Assisted Solution

by:pcelba
pcelba earned 1000 total points
ID: 35035473
This behavior could be a bug in certain VFP version probably.

I am testing a simple form in VFP 9 SP2 (9.00.0000.7423) and the container back color change works for me when placed in GotFocus and LostFocus of the container object.

I'll try to attach the form and you may test it.
form1container.SCT.txt
form1container.scx.txt
0
 
LVL 1

Author Comment

by:IainMacb
ID: 35035856
pcelba - Thanks for that. When I try running the FORM, it's asking for MYCONT.VCX. Is that supposed to be my customer container?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 42

Expert Comment

by:pcelba
ID: 35035911
Sorry for that, I've used old existing form from some tests and it uses this class library. Here it is:


MyCont.VCT.txt
MyCont.VCX.txt
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35036344
Pavel, thanks for the example. This works in my vfp version.

If I add this to my sample form the backcolor also changes back and forth, but I only once get the output of "?" to print. I changed this to print a random value SYS(2015) and the reason is revealed: ? does reset to the home position, so text is overwritten. If I print SYS(2015) i see the text changing every time.

So I shouldn't use ? to test an event is running. Bummer

Finally, the only events you need to program are gotfocus and lostfocus. Calling This.Setfocus() in the container.click() also works for me.

Also, Efuerte, you have one problem in debugging this events with SET STEP ON: Focus changes to the debugger window, so you don't see the normal event behavior, if you debug it.

Bye, Olaf.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 35036471
Good news.

The ? output is probably directed under the last known cursor position. I am rather using Event tracking feature (even when it reports false events sometimes). Debugout could also be good.

But we still don't know where is the problem on EFuerte's form because we both are using scenario which does not work for him...

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35036531
"... last known cursor position". Well, that would mean the ouptu would continue in the next line, like always, somehow the focus change from container back to the form will need to reset the cursor position.

Well, I know Efuertes kind of debugging cannot work, as it moves the focus. But Efuerte should have tried without the SET STEP ON first and should not have had a problem then, which he tried to debug. Maybe some code in parent classes?

Bye, Olaf.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 35036613
The last known cursor position could be always the same after SetFocus because when you set focus to the container then the first contained object gets focus and it sets the cursor position to coordinates of this object...

SET STEP ON is really not so useful in certain context (the best place is Refresh method :-) thus I am voting for event tracking.

Of course, my goal is to write code without bugs :-).
0
 
LVL 1

Author Comment

by:IainMacb
ID: 35038975
OK, the key word in my original question turns out to be "stupid".

Comparing your code and mine, the answer is obvious - you've got controls that can accept the focus, whereas my custom container object is all shapes and labels. Obvious really - "doh" to quote Homer.

So I've added an invisible button which is ANCHORed to cover the whole of the container.

And it all works beautifully.

Thank you!

Iain

ps - Who's Efuerte?

0
 
LVL 42

Expert Comment

by:pcelba
ID: 35040692
LOL, we both supposed this question is asking EFuerte - another EE member.

So, I am sorry and I am glad you've found the solution.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 35042216
Sorry, yes, I read Efuerte from pcelba and didn't look back to the original post.

Bye, Olaf.
0
 
LVL 42

Expert Comment

by:pcelba
ID: 35043060
"I read Efuerte from pcelba "

Hmm, which post it was?  :-))
0

Featured Post

TCP/IP Network Protocol Cheat Sheet

TCP/IP is a set of network protocols which is best known for connecting the machines that make up the Internet. The truth is that TCP/IP is one of the oldest network protocols and its survival is mainly based on its simplicity and universality.

Question has a verified solution.

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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Introducing Priority Question, our latest feature.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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