xsharp.eu • using parentheses to access array elements
Page 1 of 1

using parentheses to access array elements

Posted: Fri Oct 22, 2021 7:23 pm
by kevclark64
The release notes for the version 2.9 include that you added the ability to use parentheses to access array elements, which is great. However, it looks like parentheses can currently only be used on the right side of an equation.

Code: Select all

arrayhold(1)=ofstr  //this generate an error: The left-hand side of an assignment must be a variable, property or indexer
ofstr=arrayhold(1)  //this works

using parentheses to access array elements

Posted: Sat Oct 23, 2021 7:24 am
by Chris
Kevin, how have you declared arrayhold in this case?

using parentheses to access array elements

Posted: Sat Oct 23, 2021 1:06 pm
by Karl-Heinz
Hi Chris,

it seems there´s also a function named arrayHold() involved. When i add such a function i see the "left-hand" compiler error. Try this with /FOX2 enabled / disabled

Code: Select all

FUNCTION Start() AS VOID
dimension arrayHold(3)

	arrayhold(1) = 12 

	RETURN

FUNCTION arrayHold(n)
	
	RETURN 1 
regards
Karl-Heinz

using parentheses to access array elements

Posted: Sat Oct 23, 2021 3:40 pm
by Chris
Hi Karl-Heinz,

This seems to compile and run fine on my machine. Do you get any errors?

.

using parentheses to access array elements

Posted: Sat Oct 23, 2021 3:52 pm
by FFF
Using the FP Sample from Xide, (with no additional /Fox2) i see the error. It dissappears, when i add the switch

using parentheses to access array elements

Posted: Sat Oct 23, 2021 4:00 pm
by Chris
Yeah, indeed /fox2 is indeed necessary for this feature to work. It's mentioned in the What's New document.

using parentheses to access array elements

Posted: Sat Oct 23, 2021 4:45 pm
by Karl-Heinz
Hi Chris,

Does this mean that you never see the "left-hand" compile error ?

When /Fox2 is disabled i see the "left-hand" compile error because in this case the function arrayhold() is meant and not the array. Now "arrayhold(1) = 12" means that i want to assign 12 to the return value of the arrayhold() function, so the error is imo correct.

A - fox independed - sample to enforce a "left-hand" compile error:

12:Tostring() += "34"

Before Kevin isn´t back to explain what excatly he´s doing i have no other explanation why he gets the "left-hand" error

regards
Karl-Heinz

ok, alles klar ;-) - after a refresh i see the the other replies.

using parentheses to access array elements

Posted: Sat Oct 23, 2021 4:51 pm
by Chris
Hi Karl-Heinz,

I do get the error when /fox2 is disabled, and this is by design.

.

using parentheses to access array elements

Posted: Mon Oct 25, 2021 3:38 pm
by kevclark64
I think I understand what happened now. I've been testing a large FoxPro procedure file to see what generates errors. I had the /fox2 switch on, but the array was not declared. The array in the original Foxpro code was declared using EXTERNAL ARRAY, which I think is not supported in XSharp currently. I had commented that out since it was giving an error, but that meant that the array wasn't declared. When I add DIMENSION arrayhold(10) then I can use parentheses with the array. Sorry for the confusion.

using parentheses to access array elements

Posted: Mon Oct 25, 2021 5:07 pm
by Chris
That's fine of course Kevin, thanks for your feedback!