xsharp.eu • EXIT in FOR Loop - Page 2
Page 2 of 2

Re: EXIT in FOR Loop

Posted: Tue Apr 23, 2024 6:14 am
by lagraf
Ok, thank you Chris,
pls keep me informed if the #pragma works.

Is there another way to compile user defined formulas?

Franz

Re: EXIT in FOR Loop

Posted: Tue Apr 23, 2024 6:18 am
by robert
Guys,

I think the pragma should be

Code: Select all

#pragma options ("memvars", on)
Robert

Re: EXIT in FOR Loop

Posted: Tue Apr 23, 2024 6:39 am
by lagraf
Hi Robert,
I did the #pragma options ("memvars", on) at the beginning and the #pragma options ("memvars", default) at the end of the method. Compiling shows same errors as without #pragma!

Compiler switch at Properties, Compiler, /memvar works but I get other errors at MCompile / MExec in these methods:

Code: Select all

cVal := MCompile(_aVor[nPos,4])	// => error XS0029: Cannot implicitly convert type 'XSharp._Codeblock' to 'string'
cReturn := AsString(MExec(cVal))	// => error XS1503: Argument 1: cannot convert from 'string' to 'codeblock'

Re: EXIT in FOR Loop

Posted: Tue Apr 23, 2024 8:31 am
by Chris
Robert,

Actually both "memvar" and "memvars" are accepted as an option in the pragma! Looks like a bug, isn't it. But both still result to a parser error on the MEMVAR. Will open a detailed ticket.

Franz, this is a difference between X# and VO, it would not be possible in .Net to return the result of MCompile() in a string, instead it is returned as a codeblock. Also for the same reason MExec() needs a codeblock argument. So please change you var declaration to CODEBLOCK and it will work:

LOCAL cVal AS CODEBLOCK

Re: EXIT in FOR Loop

Posted: Tue Apr 23, 2024 9:46 am
by robert
Chris,

I see what is happening.
The compiler option /memvar (/memvars is also supported) enables a part of the parser that recognizes the PRIVATE keyword.
At this moment, you MUST set the compiler option globally (as command line argument).
The /memvar compiler option also controls if the compiler produces special code to keep track of the lifetime of private and public variables.
That can be enabled / disabled with a pragma.
I will see if I can make the detection of the PRIVATE and PUBLIC statements also dependent of the pragma

Robert

Re: EXIT in FOR Loop

Posted: Tue Apr 23, 2024 3:49 pm
by lagraf
Hi Chris,
I edited it to Codeblock and now it compiles.
Franz