indirect reference to field name

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

indirect reference to field name

Post by kevclark64 »

Is there a way, either in Foxpro dialect or the core dialect, to indirectly reference a field name? In FoxPro I can do this:

replace (field(1)) with "somevalue"

-or-

cfieldname="myfield"
replace (cfieldname) with "somevalue"

Is there anyway to do that currently in XSharp?
FoxProMatt

indirect reference to field name

Post by FoxProMatt »

This presently fails at compile time... It complains about the wrapping parens:

Code: Select all

Replace (cfieldname) with "somevalue"

Another similar construct in VFP syntax is this, it doesn't compile either:

Code: Select all

Replace &cFieldName With "somevalue"

They have a listing of current VFP support here: https://www.xsharp.eu/itm-help/foxpro-c ... ility-list

Is shows that REPLACE command is implemented, but apparently it needs further tweaking to get there all the way.
User avatar
robert
Posts: 4473
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

indirect reference to field name

Post by robert »

Kevin,
If you want to do it the "command" way then we need to tweak the commands a bit.
Function based it already works like this (and this is what VO people are used to)

Code: Select all

replace (field(1)) with "somevalue"
becomes

Code: Select all

FieldPut(1, "somevalue")
and

Code: Select all

cfieldname="myfield"
replace (cfieldname) with "somevalue"
becomes either:

Code: Select all

cfieldname="myfield"
FieldPutSym(cFieldName, "Somevalue)
or

Code: Select all

FieldPutSelect("Customers", cFieldName, "SomeValue)
if you want to add a cursor name.

Don't worry if the help says that the fieldname has to be a symbol. The compiler will automatically convert the string to a symbol for you, because there is an implicit conversion between a symbol and a string and vice versa.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
FoxProMatt

indirect reference to field name

Post by FoxProMatt »

Robert said
If you want to do it the "command" way then we need to tweak the commands a bit.
Yes sir, we definitely need the Command version.

Don't forget this version of it:

Code: Select all

cFieldName = "SomeField"
Replace &cFieldName With "somevalue"
And even this is valid in VFP:

Code: Select all

lcFieldRef = "Cursor1.AppName"
Replace &lcFieldRef with "MyApp"
And this is valid:

Code: Select all

lcCursor = "TsqlQuery"
lcField = "App"
Replace &lcField With "MyApp" In &lcCursor
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

indirect reference to field name

Post by mainhatten »

FoxProMatt_MattSlay wrote: And even this is valid in VFP:

Code: Select all

lcFieldRef = "Cursor1.AppName"
Replace &lcFieldRef with "MyApp"
While valid, it borders on problematic - perhaps throw a warning, as it is often meant to be executed as some version of[

Code: Select all

lcCursor = "TsqlQuery"
lcField = "App"
Replace &lcField With "MyApp" In &lcCursor
as "In" is the correct way to indicate another alias without running into possible problems with seletcted cursor at eof().
FoxProMatt

indirect reference to field name

Post by FoxProMatt »

@ mainhatten - Yep, I understand the issue you are referring to, and I'm not offering examples posted here as best-practices, I'm just trying to help the X# Dev Team be aware of every possible code construct they may face in VFP code bases, even hacky ones.
Post Reply