Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to use the addproperty function correct

Status
Not open for further replies.

ExtraD

Programmer
Jul 6, 2005
41
NL
Hi,

A time ago we migrated from Foxpro 2.6 to 8. With this migration we saw that the SCATTER VAR wasn’t “public” anymore. With the migration we miss used the READ to continue the “public” effect of the m. VAR’s. But now we are planning to migrate to SQL Server, with this migration I also would like to make use of the Foxpro 8 way of storing data on forms and memory.

A while ago I already asked how the way would be to approach this. One of the suggestions was to SCATTER the data to an object and to add this object as an property to the form. I tried some examples but I can’t figure out how it really works:

What I do is the following:

The structure of the table at this moment is just 1 field called runo_nr which is a string.

1. In the load of the first form I have:
USE "f:\order08.dbf\db\12102007.dbf" ALIAS "table" SHARED IN 0
SELECT "table"
SCATTER NAME oTable
AddProperty(oTable, "myProperty")

In my world this should created a property “myProperty” to access the data that was scattered to the object oTable…

2. In the click event of the button on the form I have this:
WAIT WINDOW thisform.myProperty.runo_nr

But I get the message that the property myProperty doesn’t exist.

Why cant I use this property, it should already be added via addproperty ????

Second, how can I copy this data to another form?
Maybe like: DO FORM form2 NAME oForm2 WITH thisform.myProperty

And in the load of the 2nd form:
PARAMETERS oTable
AddProperty(oTable, "myProperty")

Is this valid?

---------------------
In vb I solve this by making a class module and making a Public VAR in the form that is a type “oTable”, and pass it to functions/forms “byref”
---------------------

I know this is a dummy question but I keep banging head against it :) So if you could please help or suggest a better way to do this I would be very grateful!

 
The reason you are getting an error is that you are adding "myproperty" to your data object with this code, not to the form:
Code:
SELECT "table"
SCATTER NAME oTable
AddProperty(oTable, "myProperty")
The correct code is:
Code:
SELECT "table"
SCATTER NAME oTable
ThisForm.AddProperty( "oData", oTable )
WAIT WINDOW ThisForm.oData.runo_nr

OR

ADDPROPERTY( ThisForm, "oData" )
WAIT WINDOW ThisForm.oData.runo_nr



----
Andy Kramek
Visual FoxPro MVP
 
ExtraD,

Alternatively, you can add the object at design time, and so avoidthe AddProperty completely.

Add a property in form designer, called oData. Then:

SELECT Table
SCATTER NAME THISFORM.oData

The use, say, THISFORM.oData.runo_nr to access the field values.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi ExtraD,

I assume, the 2nd form you run will be release before the 1st form is released. In this case, you want to create an object in 1st form and use it in second form.

So in the
Form1.Init..
PUBLIC oTable
oTable = NEWOBJECT([CUSTOM])
SELECT myTable
SCATTER NAME oTable BLANK

This is to ensure that this object is available to all forms that will be opened after this form is run. To ensure that the fields are also part of the object, the SACTTER BLANK is used, while, depending on your form, this line may not be required. In case, the called forms are run without scatter fields encountered, this will avoid an error.

Then in suitable place... simply put code
SCATTER NAME oTable
This will put the fields contents to the object created.

Now you can use this object anywhere in the form or ouside in another form, till oTable object is released, by simply using.. example...
oTable.runo_nr

Make sure that you release this object at suitable place, in this example.. in the Destroy event of form1..
Form1.Destroy
RELEASE oTable
DODEFAULT()

Probably, this will be much more simpler. So you dont need to use passing of parameters etc..
Even if you need to use a tenporary copy of the object, you can copy this object to another local object or copy a field value to another variable for temporary use.

Hope this is of some help to you :)

Good luck :)

____________________________________________
ramani - (Subramanian.G) :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top