Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Find a flaw in the logic
Message
 
 
À
13/01/2006 09:27:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01086027
Message ID:
01086576
Vues:
27
>>>>>You are right. However, I'm of opinion that you are actually breaking a 'standard rule' here. You are at risk of changing the value of a variable in the calling program. The code should be something like:
>>>>>
>>>>>
lparameters tlEnabled, toObject
>>>>>
>>>>>local loObjectX    && you're already using loObject for another purpose
>>>>>
>>>>>if vartype( m.toObject ) <> "O"
>>>>>	loObjectX = this
>>>>>else
>>>>>	loObjectX = m.toObject
>>>>>endif
>>>>
>>>>No risk at all since I'm using lparameters and not passing variable by reference.
>>>
>>>Ah, but, as far as I know, objects are always passed by reference, because the object type variables are references to actual objects. So if you pass an object by value, you do get a new variable, which still refers to the same object.
>>
>>
>>You're absolutely right. That again proves that Peter is wrong <g>, since two people can only be right at the same time in Hershelle Ostropoller's stories. <g>
>
>Peter is wrong? <g>
>
PUBLIC oform1
>
>oform1=NEWOBJECT("form1")
>oform1.Show
>RETURN
>
>DEFINE CLASS form1 AS form
>
>	Top = 0
>	Left = 0
>	Height = 146
>	Width = 314
>	DoCreate = .T.
>	Caption = "Form1"
>	Name = "Form1"
>
>	ADD OBJECT check1 AS checkbox WITH ;
>		Top = 54, ;
>		Left = 72, ;
>		Height = 17, ;
>		Width = 82, ;
>		AutoSize = .T., ;
>		Caption = "Checkbox 1", ;
>		Value = .F., ;
>		Name = "Check1"
>
>	ADD OBJECT check2 AS checkbox WITH ;
>		Top = 84, ;
>		Left = 72, ;
>		Height = 17, ;
>		Width = 82, ;
>		AutoSize = .T., ;
>		Caption = "Checkbox 2", ;
>		Value = .F., ;
>		Name = "Check2"
>
>	ADD OBJECT command1 AS commandbutton WITH ;
>		Top = 12, ;
>		Left = 72, ;
>		Height = 27, ;
>		Width = 174, ;
>		Caption = "Check/Uncheck checkbox 1", ;
>		Name = "Command1"
>
>	PROCEDURE dummy
>		lparameter toObject
>
>		toObject = thisform.check2
>	ENDPROC
>
>	PROCEDURE command1.Click
>		local loCheckbox
>
>		set udfparms to REFERENCE
>
>		loCheckbox = thisform.check1
>
>		thisform.dummy( loCheckbox )
>
>		loCheckbox.value = not loCheckbox.value
>	ENDPROC
>ENDDEFINE
I see the point now. Also

lparameters tcValue

tcValue = "something"

may break the code if SET UDFPARMS to reference. But I have lots of programs like this, so I can only hope I never set it to be by reference.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform