Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scope of Properties
Message
From
08/12/2001 23:52:49
Carmen Gassi
Perseus Software Systems
Oakville, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00591662
Message ID:
00591788
Views:
32
Hi Sergey
I just tried code exactly as described. I did create the property through the visual design environment, not at runtime using addproperty(), but that shouldn't make a difference. I assigned it the parameter in the init method, and then tried to display that value ( just for testing ), in the click method of a command button. An error was generated ( unknown variable ... ) and in the debugger, the scope of said property was listed as local. I don't know what I'm missing here, but I'm obviously missing something. Any ideas?

Thanks
Carmen
>Hi Carmen,
>The parameters are passed to the form's Init event not Load.
* Form's Init
>LPARAMETERS parameter1
>thisform.property = parameter1
However the Load event wouldn't see this property change because it fires before Init.
>
>>Hi Ed
>> A very informative explanation. Just to elaborate a bit on my actions, I defined the property using the form design environment. I accessed the form menu and added the new property and then ran the form. At that point, the property shows up in the (Other) tab in the properties of the form as a logical data type. In the load method, and I tried it in the init method as well, is where I tried to assign a parameter passed by another form to that property. I tried to assign it two different ways thinking that I had made a syntactical error. I tried as follows
>> load method code:
>> thisform.property = parameter passed,
>> and I tried
>> thisform.property.value = parameter passed
>>Neither one of the above worked, so I fell back ( I know OO philosophy ), on the tried and true public variable. If you could tell me how to correct whatever mistake I made, I will incorporate it. Thanks again Ed.
>>
>>Regards
>>Carmen
>>>>Forgive me if I sound confused. I was under the impression that if you add a property to a form, that property is available for the duration of the form. Example, I added a new property to a form, that will accept a parameter passed to it from another form. When I query the value of the property ( variable ? ), I see in the debugger that it is considered a local type. Am I just as far ahead to declare a public variable in the load event to accomplish the same thing, because the add property approach doesn't seem to do what I want. Of course I could be setting it up incorrectly.
>>>>
>>>
>>>I think you're misinterpreting what a property is vs a local variable declared in a method or defined in a PARAMETERS or LPARAMETERS statement of a method. A property is scoped to the life of the object which owns it; it is created by definition in the class as a property (in non-visual classes, these are any declarations occuring prior to the first method is specified in the DEFINE CLASS code block, or defined through the menu point to add a property to the object in the class browser or a visual design tool. They can also be created dynamically in certain classes by invoking the AddProperty() method of the class.
>>>
>>>Variables defined in method code within a class are just that, variables, whose scope is limited to the scope of the method, unless they are declared as PUBLIC, which in general terms is a bad idea because of a variety of side effects, and OO philosophical issues, such as violating the concept of encapsulation. Unless created explicitly as proprties, these things go away when the method terminates, so they csan't be used to propagate a value within the scoping of the object. The following will persist across the life of a Form:
>>>
>>>
thisform.AddProperty('myFormProperty','Foo bar mumble')
>>>? thisform.myFormProperty
>>>
>>>The following disappears after the method in which the code is invokes terminates:
>>>
>>>
PRIVATE myMethodVariable  && could just as easily be declared local
>>>myMethodVariable = 'Foo bar mumble'
>>>? myMethodVariable
>>>
>>>If you attempt to reference thisform.myFormProperty in another method of the form, it persists; it remains defined and in scope while the Form is active. However, myMethodVariable, being scoped to the method it was created in, is not available to other methods once the first method terminates.
>>>
>>>So variables, even variables that are created in the code in a method, are not properties, and do not remian in scope while the object is in scope, only while that instance of the method invocation is in scope. Properties have a life as long as the object that owns them has a life.
>>>
>>>>I guess I misunderstood the use of properties, I was able to accomplish my objective by using a plain old public variable declaration. Properties I guess are restricted to classes and controls.
>>>>
>>>
>>>No, you just fail to differentiate between variables declared in a method and properties. The difference between them is the reference point for their existance; they also use a different notation, in the form of objectreference.PropertyName for a property as opposed to simply VariableName for a variable. Properties have a point of reference for their existance; variables do not have the same, they're either alive or dead, regardless of the reference point.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform