Discussion:
String Reference to Object
Gene Wirchenko
2018-02-15 18:51:46 UTC
Permalink
Dear Foxers:

I sometimes have a "reference" to an object that is in the form
of a string variable. I have used
&reference..referredto

Is there a better way of doing this?

(reference).referredto
would be nice, but it does not compile.

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@mtlp000086
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Stephen Russell
2018-02-15 18:56:47 UTC
Permalink
Cast it to a string comes to mind but VFP will let you change the value of
a type in a heartbeat.

&reference..referredto.ToString()
I sometimes have a "reference" to an object that is in the form of a
string variable. I have used
&reference..referredto
Is there a better way of doing this?
(reference).referredto
would be nice, but it does not compile.
Sincerely,
Gene Wirchenko
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAJidMYJAs0bz890owbYWC2DSNB-***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Fernando D. Bozzo
2018-02-15 18:57:53 UTC
Permalink
Hi Gene:

To talk with an example, if you have this:

oObj = createobject("custom")
reference = "oObj"

The you have at least 3 options:

1) The way you know => &reference..referredto

2) Using evaluate => =Evaluate(reference + ".referredto")

3) My preferred: Caching the object and then using it:

oRef = Evaluate(reference)
? oRef.refered1
? oRef.refered2
...
I sometimes have a "reference" to an object that is in the form of a
string variable. I have used
&reference..referredto
Is there a better way of doing this?
(reference).referredto
would be nice, but it does not compile.
Sincerely,
Gene Wirchenko
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGQ_JukotJHyYsJ5OtmJ8jSiO3jGOMZ=W+***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Gene Wirchenko
2018-02-15 19:07:22 UTC
Permalink
Post by Fernando D. Bozzo
oObj = createobject("custom")
reference = "oObj"
1) The way you know => &reference..referredto
2) Using evaluate => =Evaluate(reference + ".referredto")
oRef = Evaluate(reference)
? oRef.refered1
? oRef.refered2
...
I was hoping to avoid evaluate(), but your third way makes
sense. I will check if it works in all the contexts I am thinking
of. (I was using "object" and "reference" rather loosely.)

[snip]

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@mtlp000084
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Jean MAURICE
2018-02-15 19:07:45 UTC
Permalink
Hi Gene,

have you tried

WITH (m.reference)
.referredto =
etc
ENDWITH

?
The Foxil

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/94f71b4d-fbbc-a474-7fc2-***@wanadoo.fr
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Gene Wirchenko
2018-02-15 19:16:58 UTC
Permalink
Post by Gene Wirchenko
Post by Fernando D. Bozzo
oObj = createobject("custom")
reference = "oObj"
1) The way you know => &reference..referredto
2) Using evaluate => =Evaluate(reference + ".referredto")
oRef = Evaluate(reference)
? oRef.refered1
? oRef.refered2
...
I was hoping to avoid evaluate(), but your third way makes
sense. I will check if it works in all the contexts I am thinking
of. (I was using "object" and "reference" rather loosely.)
Unfortunately, it does not work in my usual use case: as an
alias. Example:
use ccli
where=evaluate("ccli") && Nope
? where.clcode

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@mtlp000085
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Koen Piller
2018-02-15 19:24:34 UTC
Permalink
You cannot use a field as an form
Property.
What are you trying to accomplish here?
Post by Gene Wirchenko
Post by Gene Wirchenko
Post by Fernando D. Bozzo
oObj = createobject("custom")
reference = "oObj"
1) The way you know => &reference..referredto
2) Using evaluate => =Evaluate(reference + ".referredto")
oRef = Evaluate(reference)
? oRef.refered1
? oRef.refered2
...
I was hoping to avoid evaluate(), but your third way makes
sense. I will check if it works in all the contexts I am thinking
of. (I was using "object" and "reference" rather loosely.)
Unfortunately, it does not work in my usual use case: as an
use ccli
where=evaluate("ccli") && Nope
? where.clcode
Sincerely,
Gene Wirchenko
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CACUu1Su+DkWnDtGnq2r_Bt9uJMEK00nJu-=jpQ0Hmoz+***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Ted Roche
2018-02-15 19:26:09 UTC
Permalink
Unfortunately, it does not work in my usual use case: as an alias.
use ccli
where=evaluate("ccli") && Nope
? where.clcode
Well, in that case you should be using an alias:

use ccli alias TheTable

? TheTable.clcode
--
Ted Roche
Ted Roche & Associates, LLC
http://www.tedroche.com

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CACW6n4sGhuBkHMLCdYXQZz5Oh-GEVQe-***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Ken Dibble
2018-02-15 20:00:04 UTC
Permalink
Post by Ted Roche
Unfortunately, it does not work in my usual use case: as an alias.
use ccli
where=evaluate("ccli") && Nope
? where.clcode
use ccli alias TheTable
? TheTable.clcode
Well, I don't understand this at all.

"Use" is a VFP command that only opens a table. The following works
fine for me:

CLOSE TABLES ALL

ccli = "C:\Some Path To\SomeTable.dbf"

USE (ccli) && table is now open

EVALUATE() applies when the parameter you feed it is the name of an
object or a variable that stores the name of another variable.

You can do:

var1 = 3
var2 = "var1"

? EVALUATE(var2) && 3

And you can do:

myarray = "aList"

oMyObj.AddProperty(myarray)

? ALEN(oMyObj.&myarray.,1) && 1

But if you want to do this:

mytable = "foo"
myfield = "bar"

? mytable.myfield

Then you need to do:

? &mytable..&myfield

A [table].[field] reference is not an object reference and can't be
treated like one. It's a thing unto itself.

Ken Dibble
www.stic-cil.org





_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
AndyHC
2018-02-16 10:56:38 UTC
Permalink
may I suggest SCATTER .... NAME

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/caf175de-721e-6b96-f69a-***@hawthorncottage.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
AndyHC
2018-02-16 10:59:32 UTC
Permalink
may I suggest SCATTER .... NAME

... but using a cursoradapter is better!

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/fbb51fc2-f527-3ddc-dcb0-***@hawthorncottage.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Fernando D. Bozzo
2018-02-15 19:50:37 UTC
Permalink
Gene, you did talk about objects, not tables and fields. They are not
treated the same way.

In this case, then Ted is right, the alias must be used.

You can use generically with something like this:

use ccli alias *mytable*
? *mytable*.clcode

Nice thing about aliases is that you can use the same alias for any table
in the case that those tables have the same fields you want to access.
Post by Fernando D. Bozzo
oObj = createobject("custom")
reference = "oObj"
1) The way you know => &reference..referredto
2) Using evaluate => =Evaluate(reference + ".referredto")
oRef = Evaluate(reference)
? oRef.refered1
? oRef.refered2
...
I was hoping to avoid evaluate(), but your third way makes sense. I
will check if it works in all the contexts I am thinking of. (I was using
"object" and "reference" rather loosely.)
Unfortunately, it does not work in my usual use case: as an alias.
use ccli
where=evaluate("ccli") && Nope
? where.clcode
Sincerely,
Gene Wirchenko
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGQ_JunYKisUBVyaZ7OGVPFXMxQwt8MLwb_2X_1Thxkr5E-***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Fernando D. Bozzo
2018-02-15 20:00:14 UTC
Permalink
(part 2)

Gene, about the alias thing:

If you have your table already open with something like this:

use ccli

Then you can re-open the same table under another alias this way:

use ccli alias *mytable again shared*
? *mytable*.clcode
...
use in (select("mytable"))


Interesting things about this:
- VFP does not create a second handle to the table, just reuse the existing
one with another name
- Because of that, the reopening with different aliases is the fastest way
to reuse an already opened table
- Each alias have it's own record pointer and can have it own index too,
without interfering with the other aliases
- Aliases allows you to encapsulate functionality for a group of tables
that share one or more fields when you need to treat them the same way
Post by Fernando D. Bozzo
Gene, you did talk about objects, not tables and fields. They are not
treated the same way.
In this case, then Ted is right, the alias must be used.
use ccli alias *mytable*
? *mytable*.clcode
Nice thing about aliases is that you can use the same alias for any table
in the case that those tables have the same fields you want to access.
Post by Fernando D. Bozzo
oObj = createobject("custom")
reference = "oObj"
1) The way you know => &reference..referredto
2) Using evaluate => =Evaluate(reference + ".referredto")
oRef = Evaluate(reference)
? oRef.refered1
? oRef.refered2
...
I was hoping to avoid evaluate(), but your third way makes sense.
I will check if it works in all the contexts I am thinking of. (I was
using "object" and "reference" rather loosely.)
Unfortunately, it does not work in my usual use case: as an alias.
use ccli
where=evaluate("ccli") && Nope
? where.clcode
Sincerely,
Gene Wirchenko
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CAGQ_JumE_wB5unwo3=Qi1JWEABuCu3GeX46htEwbex+***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Gene Wirchenko
2018-02-15 19:42:41 UTC
Permalink
Post by Jean MAURICE
Hi Gene,
have you tried
WITH (m.reference)
.referredto =
etc
ENDWITH
?
The WITH gives a datatype mismatch error.

At any rate, I want to avoid WITH, because, 1) it gets messy
for complicated statements and 2) I might need more than one
different reference variable.

Sincerely,

Gene Wirchenko


_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/***@mtlp000087
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Ted Roche
2018-02-15 19:48:07 UTC
Permalink
EVAL() is really your best choice for Objects, though not for tables
as you used in your example.

loObject1=EVAL(somestring)
loObject2=EVAL(someotherstring)

Do Something With loObject1, loObject2

Eval evaluates the string's value, where & dynamically recompiles the
entire line of code with string substitution of whatever follows the
&. Each has their place.

NB: And "where" is a poor choice of keywords for a variable ;)
Post by Gene Wirchenko
Post by Jean MAURICE
Hi Gene,
have you tried
WITH (m.reference)
.referredto =
etc
ENDWITH
?
The WITH gives a datatype mismatch error.
At any rate, I want to avoid WITH, because, 1) it gets messy for
complicated statements and 2) I might need more than one different reference
variable.
Sincerely,
Gene Wirchenko
[excessive quoting removed by server]

_______________________________________________
Post Messages to: ***@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: http://leafe.com/archives/byMID/profox/CACW6n4vSpShyYyMBqiDNf76uGN=CpMez-AidK+***@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.
Loading...