Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can you use commands at design time?
Message
De
13/02/1997 04:20:35
 
 
À
12/02/1997 13:55:27
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00020219
Message ID:
00020330
Vues:
36
>Where would you use WriteMethod?

In a BUILDER or a WIZARD which you run at design time.

For example, here's a builder that makes controls invisible except when glDebug exists. Select a control or some controls in the form designer or class designer, then DO this program from the command window.

* Program....: MAKDEBUG.PRG
* Version....: 1.0
* Author.....: Paul Maskens
* Date.......: June 20, 1996
* Notice.....: Copyright (c) 1996 Foxware M.R., All Rights Reserved.
* Compiler...: Visual FoxPro 03.00.00.0711 for Windows
*
* Abstract...:
* Used from the command window or eventually a toolbar to add the DEBUG
* information to the init() method of all selected controls.
*
* Changes....:
*
* Algorithm..:
* Call ASELOBJ() to get selected objects
* If there are any, iterate through and use READMETHOD()
* follwed by WRITEMETHOD() to add debugging code
* (provided it's not there already!)
* Also set .enabled to .F. always to prevent user fiddling
*-----------------------------------------------------------------------------
#DEFINE _CRLF chr(13)+chr(10)
#DEFINE _TAB chr(9)
#DEFINE THIS_BUILDER "*** Builder: makdebug"

LOCAL lnObjects, laObjects, lcInit
LOCAL ARRAY laObjects[1]

lnObjects = ASELOBJ(laObjects)
IF lnObjects = 0
RETURN
ENDIF && lnObjects = 0

FOR lnObject = 1 to lnObjects
WITH laObjects[lnObject]
lcInit = .READMETHOD("init")
IF lcInit != THIS_BUILDER
lcInit = THIS_BUILDER +_CRLF;
+ [IF TYPE("glDebug") != "U"] +_CRLF;
+ _TAB +[THIS.visible = .T.] +_CRLF;
+ [ELSE] +_CRLF;
+ _TAB +[THIS.visible = .F.] +_CRLF;
+ [ENDIF] +_CRLF;
+ [*** end] +_CRLF;
+lcInit
=.WRITEMETHOD("init",lcInit)
.enabled = .F.
ENDIF
ENDWITH
ENDFOR &&* lnObject = 1 to lnObjects


> Alternately, how can you place code in a method of a control you are creating on the fly?

You don't. You put the code in the CLASS and then create an object based on that class.


Generally I advise avoiding buttons calling buttons.

Put the code to accomplish the action in the CONTAINER and then if two interface objects want to do the same thing, then call the same container method.

I also recommend decoupling the interface from the action by not putting anything more than a method call (e.g. THIS.PARENT.saveallocations) in a button's click method.

This way you can change the interface without changing the code that performs the action. design it this way and just once have the users change their minds <g> You'll be glad of it!
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform