Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determine if controlsource is a field or a variable/prop
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00592686
Message ID:
00592940
Vues:
20
>>Is there a way to determine if a controlsource was a table field or a property - variable?
>>
>>I need to know this to assign a new value to the controlsource of an object programmatically. I have added the "controlsource" property to a container and i need a way to reassing a value to this controlsource.
>>
>>Fields use the REPLACE command and properties/variables use the "=" assignation.
>>
>>Any clue?
>
>if type('m.'+justext(this.controlsource))<>"U" && It's a variable

And if i have a variable named "myvalue" amd a property of a form named "myvalue" and a field named "myvalue".

The controlsource can be :
"thisform.myvalue"
"m.myvale"
"myvalue"
"tablename.myvalue"

IF TYPE('m.'+justext(this.controlsource))<>"U"
will always evaluate to .T.!

I have found a solution.
BTW, the value was for a checkbox, can be numeric or logical only.
I will include the .NULL. part later.
Here is the code:
IF !empty(this.controlsource)
   WITH this
      IF .Value<>EVAL(.controlsource)
         lIsField=.F.
         nDots=OCCURS(".",.controlsource)
         DO CASE
            CASE nDots > 1  && object property
               lIsField=.F.
            CASE nDots = 1  && property or field
               uObjTest=SUBSTR(.controlsource,1,AT(".",.controlsource)-1)
               uPropTest=ALLTRIM(SUBSTR(.controlsource,AT(".",.controlsource)+1))
               IF TYPE(uObjTest)="O"
                  IF PEMSTATUS(EVAL(uObjTest),uProptest,5)  && property exist
                     lIsField=.F.
                  ELSE
                     && assume controlsource is a field
                     lIsField=.T.
                  ENDIF
               ELSE
                  && assume controlsource is a field
                  lIsField=.T.
               ENDIF
            OTHERWISE  && nDots=0
               * simple test, if fsize=0 it's not a field
               IF FSIZE(.controlsource) = 0
                  lIsField=.F.
               ELSE
                  lIsField=.T.
               ENDIF
         ENDCASE	
         IF lIsField  && field
            cReplace="REPLACE "+.controlsource+" WITH "+;
               IIF(TYPE(".value")="N",ALLTRIM(STR(.value)),;
               IIF(.value=.t.,".T.",".F."))
            &cReplace
         ELSE &&property or variable
            cReplace=.controlsource+" = "+;
            IIF(TYPE(".value")="N",ALLTRIM(STR(.value)),;
               IIF(.value=.t.,".T.",".F."))
            &cReplace
         ENDIF
      ENDIF
   ENDWITH	
ENDIF
If we exchange an apple, we both get an apple.
But if we exchange an idea, we both get 2 ideas, cool...


Gérald Santerre
Independant programmer - internet or intranet stuff - always looking for contracts big or small :)
http://www.siteintranet.qc.ca
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform