Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating objects programmatically.
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00279243
Message ID:
00279267
Vues:
13
>>>As I am learning VFP, I discovered how to add an object to a form programmatically. What I’m struggling with is, how do you capture event processing for this object? I.e. when a command button receives a double click. Any help is appreciated.
>>
>>The button has a DoubleClick() that can be extended by subclassing the base class and adding code to the method. For example:
>>
>>
DEFINE CLASS ObnoxiousButton as CommandButton
>>   PROCEDURE DoubleClick
>>      ?? CHR(7)
>>      WAIT WINDOW 'Hey dummy, you double-clicked!!!'
>>   ENDPROC
>>ENDDEFINE
>>
>>To create a command button programmatically with this, you ADD OBJECT not from the class CommandButton, but from the subclass you've created called ObnoxiousButton...
>>
>>You can make subclasses using the Visual Class Designer, too.
>
>I tried something like this in my form init procedure but I get the message "methods and events cannot contain nested procedures or class defintions". I kinda want to create the object and its procedures on the fly while the program is running. Is this possible?

Not really. You could put a reference to an external .PRG or another object in a method, and build that at runtime, or build the subclass and compile it before executing it (requires VFP6 SP3 or a development copy of VFP to do) by creating a text file that would contain the class definition, compiling it and then firing the compiled .FXP - the subclass needs to exist before you can instantiate it, and you can't bury an object definition inside a method of an object (creates problems since the object definition is only visible in that method execution, so VFP doesn't allow it.)

example:

DEFINE CLASS FlexibleButtonDef AS CommandButton
icDoubleClickPrgToRun = 'ObnoxiousDoubleClick.FXP'
PROCEDURE DoubleClick
IF FILE(thisform.icDoubleClickPrgToRun)
DO (thisform.icDoubleClickPrgToRun)
ELSE
WAIT WINDOW 'Hey dummy, I can't find my DoubleClick Code!!!!'
ENDIF
ENDPROC
ENDDEFINE

You could then create the program to run for the DubleClick as a text file, compile it, and stick the name of the program to run in the propery you create to hold the name. it's not what I'd do, since i usually know the basic behavior I want well in advance, and might just need to set a couple of properties to get my subclass to behave, but this approach does work with SP3's new ability to compile a .PRG on the fly...
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform