Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Error : Illegal redefinition of variable
Message
De
25/07/2013 12:07:05
Mk Sharma
Shrishti Solutions
Mumbai, Inde
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP
Network:
Windows XP
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01579124
Message ID:
01579212
Vues:
54
Thank you,
I Will try to understand your code.


I am using custom class for public purpose in my new project like :
** main.prg
Public oApp As "myApp" Of "Main.prg"
oApp = Createobject("myApp")


Define Class myApp As Custom
	softwareName	 = "Accounting & inventory Solution "
	zsubpath		 = ""
	zdatapath		 = ""
	zdatapath2		 = ""
	ztoday			 = Date()
	zbackcolor		 = Rgb(56, 112, 210)
	zcompany		 = ""
	zsapcode		 = ""
	zsTARTDATE		 = {}
	zeNDDATE		 = {}
	uniquerecordid	 = ""
	accountfilter2	 = ""
	xreportname		 = ""
	xreportdesc		 = ""
	xindexname		 = ""
	xrepotype		 = ""
	lcpcode			 = ""
	lcdno			 = ""
	lcshadeno		 = ""
	lctakagrade		 = ""
	lntakano		 = 0
	docopies		 = 0
	cchildid		 = " "
	cmasterid		 = " "
        zcompid=" "
Enddefine
Warm regards,
mk.
>I don't know if you create classes using the class designer or DEFINE CLASS, but you should be able create the class with the designer from this example.
>This is based on the idea of a singleton class that registers itself when loaded the first time (at startup of the program for instance).
>When instantiating the class at startup, you can assign the values to the properties.
>(For the sake of testing I put the class definition in a method called "Test.PRG")
>
>DEFINE CLASS PublicVariables AS CUSTOM
>	ApplicationName = "Demo"
>	*
>	PROCEDURE INIT
>		IF TYPE("_SCREEN.PublicVariables.Name") <> "C"
>			*-- Create the reference to the singleton object.
>			_SCREEN.AddProperty("PublicVariables",THIS)
>		ENDIF
>		RETURN .T.
>	ENDPROC
>	*
>	PROCEDURE ApplicationName_ACCESS
>		RETURN _SCREEN.PublicVariables.ApplicationName
>	ENDPROC
>	*
>	PROTECTED PROCEDURE ApplicationName_ASSIGN
>		LPARAMETERS m.vNewVal
>		IF THIS = _SCREEN.PublicVariables
>			THIS.ApplicationName = m.vNewVal
>		ELSE
>			*-- This will prevent trying to change a variable in a local instance of this object.
>			MESSAGEBOX("Cannot set variable in this instance of the object.")
>		ENDIF
>	ENDPROC
>	*
>ENDDEFINE
>
>
>At startup of the program you instantiate the class and populate the values.
>
>LOCAL loPublicVariables AS PublicVariables OF Test.PRG
>loPublicVariables = NEWOBJECT("PublicVariables","Test.PRG")
>loPublicVariables.ApplicationName = "My Application"
>
>
>Now it has registered itself in the _SCREEN object and when you need any of the values you can instantiate a new local object, but the object will always return the values from the globally registered instance. In the ASSIGN methods you can prevent that a programmer accidentally tries to change one of the properties if that is necessary in your design.
>
>
>LOCAL loPublicVariables AS PublicVariables OF Test.PRG
>loPublicVariables = NEWOBJECT("PublicVariables","Test.PRG")
>*-- Now it will return the value from _SCREEN.PublicVariables, and not from this local instance. So it simulates a singleton design pattern.
>Messagebox(loPublicVariables.ApplicationName)
>
>
>You can now add multiple properties to this class, and it is easy to keep track of those and use them in the code with confidence.
>A good rule is also to create one object per context, so for instance you have _SCREEN.PrinterSettings and _SCREEN.ApplicationInfo etc and not put all properties necessarily into the same class.
>
>
>>Please send me a example class of this kind to understand the working.
>>
>>My email ID : mk_common@yahoo.com
>>
>>Warm regards,
>>mk.
>>
>>
>>
>>>>Thank you,
>>>>
>>>>The problem was Private Variable.
>>>>
>>>>We can declare a Public variable as Local OR as Public as much time we want.
>>>>But we can not declare a Private as Local OR Public
>>>
>>>I didn't see you already solved it. But just for the thought of it, (or depending how large your project is you can refactor), you may think to do it differently in the future.
>>>Instead of creating numerous public variables you can create one class with those variables as properties in this class. Then you can instantiate this class as PRIVATE in the main.prg (or make it public if you feel more comfortable).
>>>In the code then you can refer to the object and get it's properties, which now serve as kind of "public variables".
>>>For instance in the main prg:
>>>
>>>PUBLIC goPublicVariables
>>>goPublicVariables = NEWOBJECT("PublicVariables", "AppClasses.vcx")
>>>
>>>And in the code where you use those variables:
>>>
>>>LOCAL loPublicVariables AS PublicVariables OF AppClasses.vcx
>>>loPublicVariables = goPublicVariables
>>>Messagebox(loPublicVariables.OldProduct)
>>>
>>>This way you can also add comments to those properties and see the available variables in intellisense, making it easier when you have to refer to them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform