Page 1 of 1
indirect reference to field name
Posted: Tue Jan 14, 2020 7:16 pm
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?
indirect reference to field name
Posted: Tue Jan 14, 2020 8:20 pm
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.
indirect reference to field name
Posted: Tue Jan 14, 2020 9:03 pm
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
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
indirect reference to field name
Posted: Wed Jan 15, 2020 4:09 pm
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
indirect reference to field name
Posted: Wed Jan 15, 2020 9:27 pm
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().
indirect reference to field name
Posted: Wed Jan 15, 2020 9:38 pm
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.