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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic Got Focus Event

Status
Not open for further replies.

audiopro

Programmer
Apr 1, 2004
3,165
GB
I am creating text boxes dynamically and I am using the standard

Code:
with 
  thisform.text1.visible=.t.
endwith
notation to set the properties.

I am setting up a var which flags whether the displayed data has been altered (it actually detects if any of the text boxes has had focus which is near enough).
How can I add a clause to every text box, to set a flag to '1' if a box has had the focus. The gotfocus event would be the obvious way but it just complains it is read only.

Keith
 
how about the lostfocus event? you set the flag, as the txt box looses focus.



Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Hi!

From the top of my head:
Create a custum property (e.g. HasChanged) for the textbox (preferable in the parent-class) and do some code in the when- or gotfocusmethod like:

This.HasChanged = .T.

That should do what you want.

-Bart
 
I would suggest that you put that code in the parent class of your textbox-class.
Once you programmaticly add a textbox from that class the code is always there.
-Bart
 
Keith,

This is fairly straightfoward.

First, can we assume that your textbox is based on a custom class? It really should be. If it isn't, I suggest you go back and create a class now, and use that as the basis of the textboxes. You'll find it much easier.

Next, give your form a custom property. Let's call it HasChanged.

In the form's Init event, set THISFORM.HasChanged to .F.

In the class's InteractiveChange, set THISFORM.HasChanged to .T.

At any time, you can check the HasChanged property to see if any changes have been made to the data on the form.

A couple of further points:

- I suggest using the InteractiveChange event rather than the GotFocus because a control can get focus without it being edited.

- I don't understand what you mean when you say "it just complains it is read only". What's read-only? Doesn't fit with the rest of your question.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
it just complains it is read only

I assumed (there I go again) that I could just add a clause in the WITH/ ENDWITH declaration such as

Code:
.gotfocus event="editFlag=1"

and it would add it to each instance of the text box - that would be logical, or so I thought. When I tried that, it throws an error at run time saying 'gotfocus is read only'.



I have done as you say and created a custom class but I get an error. I have never needed to create a custom class in VFP before but I have done it in other languages so understand the principles.

The code now sets the text box to my keithtext class.
Code:
BOXNAME="REC"+ALLTRIM(STR(X))
THISFORM.CONTAINER1.ADDOBJECT(BOXNAME,"keithtext")
WITH THISFORM.CONTAINER1.&BOXNAME
	.TOP=TOPP
	.LEFT=LEFTS
	.WIDTH=50
	.VISIBLE=.T.
	.VALUE=YORPICTURES(X,1)
ENDWITH
the class is registered, available on the tool bar but I am getting the error.
'class definition keithtext is not found'

What have I missed this time? :)

Keith
 
Keith,

.gotfocus event="editFlag=1"

As you no doubt realise, this is nonsense (sorry to be blunt). It is not VFP syntax or anything like it.

Re your "class not found" message. This is probably a simpe matter of the class definition not being located in VFP's search path.

Where is Keithtext defined? If it's in a VCX, you might need to add a SET CLASSLIB to let VFP find it, and also ensure the VCX is in the search path. If it isn't, precede the filename with the path.

Similarly, if the class is in a PRG, make sure VFP can find it.

Another point: Do you have a special reason for adding these text boxes dynamically. The normal approach would be to add them at design time.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
It is probably a missing classlib causing the problem but I will have to check tomorrow on my dev machine.

I realise now that it is not VFP syntax but I still don't understand why the content of an event cannot be set in this way when other attributes are set in a similar fashion.

Is it possible to set up a got/lostfocus event at runtime?

Anyway - I need to move this app along and the oddities or otherwise of VFP will have to wait.
The number of text boxes will depend on the number of matching files in the valuation table. There are aditional controls to be added to the form and the layout requires those controls to be up against the bottom of the last record. It makes sense and makes it more versatile than a static form.

Keith
 
Mike,

I presume that Keith is trying to put code in the gotfocus method using:

.gotfocus event="editFlag=1"

-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top