How to Change a Method at Run Time

Last reviewed: December 12, 1995
Article ID: Q141076
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0 and 3.0b

SUMMARY

All methods are read-only at run time. You can, however, have several methods and decide at run time which method to execute. This article shows you how.

MORE INFORMATION

Step-by-Step Example

  1. Create a new form.

  2. Place a command button (Command1) on the form, and add the following code to its Click event:

    lcTemp=ThisForm.gcCurrentclk &lcTemp

  3. Place an Option Group on the form, and add the following code to its Click event:

    IF This.Value=1

         ThisForm.gcCurrentclk="ThisForm.Click1"
    
    ELSE

         ThisForm.gcCurrentclk="ThisForm.Click2"
    
    ENDIF

  4. Create a new form property called gcCurrentclk, and assign ThisForm.Click1 to gcCurrentclk.

  5. Create a new Form method called Click1, and place the following in the Form.Click1 method:

    WAIT WINDOW "Click #1"

  6. Create a new method called Click2, and place the following code in the Form.Click2 method:

    WAIT WINDOW "Click #2"

  7. Run the form.

The option group determines which Click method for the command button will execute.

NOTE: The Click event for the command button does not have to be a method of the current form. For example:

gcCurrentclk="DO myprog.PRG" would execute a program. gcCurrentclk="oMyclass.Click1" would execute a method of an external class. gcCurrentclk="WAIT WINDOW" would execute a wait window.


Additional reference words: 3.00 3.00b VFoxWin
KBCategory: kbprg kbhowto
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 12, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.