Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A textbox search class.
Message
 
À
29/04/1997 23:53:09
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00030166
Message ID:
00030239
Vues:
57
>>I've been working on a textbox search class. Basically, it allows you to >>click on it, type in your search, and executes the search. What I think

>>If anyone is interested in more specific info on how I achieved this, >>let me know and I'll go into the details.


>
>Can you tell how you achieved this?

Well, so glad you asked ;).

I've seen all sorts of approaches to doing something like this. I've seen people use two seperate textboxes on the same form and moving them around. I've seen people use one textbox but without a control source and manually filling the textbox value what the data from a table. I've even seen an app where someone would reset the control source of the textbox when it was clicked on then set it back once the search was completed. None of them seemed particularly elegant.


The class has a few properties: Search, IsParent, ObjRef, and SearchCode(). Search (defaults .f.) determines whether this textbox will be used as a search textbox. If .f. the box will act like a normal textbox. IsParent (defaults .t.) is needed to check whether the code in methods is referring to the original textbox or to the dynamically created textbox. ObjRef (defaults .NULL.) is as it says, an object reference. In the parent, it gives a reference to the child, in the child it references the parent. Finally SearchCode() is the method where you put your own searching code. This is called from the child after the child looses focus.

On init my textbox class creates another instance of itself in the same position, but behind the original textbox. All relevant properties are copied from the parent (width, color, etc). When the user clicks on the parent the child is brought to the front and focus is set to the child. Once the child looses focus it moves itself back behind the parent, calls the parent's SearchCode() method and sets focus back to the parent.
That's it!

This seems pretty straightforward in concept and it really wasn't particularly difficult. The only stumbling block came in with determining whether a particular piece of code was referencing the parent or the child (remember, they both have the same code since the child is created as a subclass). At one point I goofed a bit of code and when I ran the form I recieved a call stack overflow because my parent's init created a child, then my child's init created another child, and so on until I ran out of stack space after several hundred controls had been created ;).

The great thing about this control is that it is completly transparent from both a design and user standpoint. From a design standpoint, you are only dealing with one textbox so you don't have to worry about positioning and such. From a user standpoint it looks as you are clicking on a field and typing into that same field.


Michael G. Emmons

Michael G. Emmons
memmons@nc.rr.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform