Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamically dropping / adding form objects every 60 seco
Message
From
02/08/2007 18:56:22
 
 
To
02/08/2007 17:09:05
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
01245612
Message ID:
01245705
Views:
27
This message has been marked as a message which has helped to the initial question of the thread.
>Perhaps my problem is where or how I am trying to add the buttons. My FOR loop to add the command buttons is in the form's refresh and no matter what I do the error is
>
>
>
statement is only valid within a class definition
>
>The form is a .prg file that is being called as an object. I have tried thisform.NewObject, NewObject, Add property, and the error is always the same whether I work in a visual form or a non-visual form.
>
>I also have problems if I try to release controls. When I run the method below I get an error error that tells me
Member cmdEmp1 is a class member.
>
>
>    PROCEDURE ReleaseButtons
>        * releases all the lot and employee buttons
>        LOCAL x
>        FOR x= 1 TO THISFORM.CONTROLCOUNT
>            IF UPPER(THISFORM.CONTROLS[x].CLASS)$'CMDLOTACTIVE,CMDLOT,CMDEMPLOYEE'
>                REMOVEPROPERTY(THISFORM, THISFORM.CONTROLS[x].NAME)
>            ENDIF
>        ENDFOR
>    ENDPROC
>
>
If you are hard coding the buttons to remove then I don't think you need to cycle through the controls. You might try something like
    PROCEDURE ReleaseButtons
        * releases all the lot and employee buttons
        IF VARTYPE(thisform.cmdlotactive) = "O"
            thisform.removeobject("cmdlotactive")
            thisform.addobject("cmdlotactive","myclass")
        ENDIF

        IF VARTYPE(thisform.cmdlot) = "O"
            thisform.removeobject("cmdlot")
            thisform.addobject("cmdlot","mysecondclass")
        ENDIF
        etc
    ENDPROC
If you have more buttons than just the sample you could, for example, create a two dimensional array. The first column has the name of the control to remove. The second column has the name of the class used to replace it. Thus, in the form's Init method
DIME Thisform.aRemoveButtons[3,2]
aRemoveButtons[1,1]='CMDLOTACTIVE'
aRemoveButtons[2,1]='CMDLOT'
aRemoveButtons[3,1]='CMDEMPLOYEE'
aRemoveButtons[1,2]="myClass1"
aRemoveButtons[1,2]="myClass2"
aRemoveButtons[1,2]="myClass3"
and then.....
    PROCEDURE ReleaseButtons
        * releases all the lot and employee buttons
        FOR I = 1 TO ALEN(thisform.aRemoveButtons,1)
            IF TYPE(aRemoveButtons[I,1]) = "O"
               thisform.removeobject(aRemoveButtons[I,1])
               thisform.addobject(aRemoveButtons[I,1],aRemoveButtons[I,2])
            ENDIF
        NEXT
    ENDPROC

>
Bear in mind that myClass1,2,3, etc. have to be classes defined in an open procedure. There may be (probably are) other, better, ways of doing this but I'm pretty sure something like this will work (but the code has only been mildly tested and may need some tweaking)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform