EXIT in FOR Loop

Deutschsprachiges X#-Forum – German language forum

Moderator: wriedmann

lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

EXIT in FOR Loop

Post by lagraf »

Hallo,
warum bringt folgender Code einen Fehler
error XS9089: Functions cannot have an INIT or EXIT clause.

Code: Select all

METHOD [Name]
LOCAL x AS DWORD
FOR x := 1 to 9999
	IF [Bedingung]
		EXIT
	ENDIF
NEXT
FFF
Posts: 1590
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: EXIT in FOR Loop

Post by FFF »

Da muss noch was anderes sein.

Code: Select all

FUNCTION Start( ) AS VOID
VAR t :=test{}
? t:z()

CLASS  test
METHOD z() AS DWORD
	LOCAL x AS DWORD
FOR x := 1 TO 9999
	IF TRUE
		EXIT
	ENDIF
NEXT
RETURN x
END CLASS
compiliert bei mir ohne Fehler oder Warnung.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: EXIT in FOR Loop

Post by lagraf »

Hallo Karl,
der Code liegt bei mir in einer Methode einer Klasse (und läuft in VO tadellos), interessanterweise bekomme ich aber noch einen anderen Fehler ein paar Zeilen davor, vielleicht hängen die beiden zusammen:
XS9002: Parser: unexpected input 'nPos'

Code: Select all

CLASS dlgLsBuchen INHERIT dlgLsBuchen_vo
PROTECT _cLiefnr AS STRING
PROTECT _aVor AS ARRAY
...
METHOD GetArtField(cCol AS STRING, lFormel := TRUE AS LOGIC)
LOCAL x AS DWORD
LOCAL odbAGR AS dbAgr
LOCAL nPos AS DWORD
...
nPos := AScan(_aVor, {|aVal|aVal[1] == Upper(cCol)})	// => XS9002
odbAgr := dbAgr{}
FOR x := 1 TO 9999
	odbAgr:Seek({#LIEFNR, #AGRNR}, {_cLiefnr, x}, FALSE)
	IF !odbAgr:Found  .OR. odbAgr:FIELDGET(#TXT) == "SONSTIGES"
		EXIT								// => XS9089
	ENDIF
NEXT
odbAgr:Close()
LG Franz
Last edited by lagraf on Mon Apr 22, 2024 11:33 am, edited 1 time in total.
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: EXIT in FOR Loop

Post by robert »

Franz,

LOPCAL should probably be LOCAL


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: EXIT in FOR Loop

Post by lagraf »

Hi Robert,
that's only a typing error, in sourcecode it's correct!
Franz
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: EXIT in FOR Loop

Post by robert »

Franz,

The best way for us to help you to detect the error is if you include the complete source code.
With snippets of code, this is not possible.
For example: does your class end with END CLASS?


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: EXIT in FOR Loop

Post by lagraf »

Hi Robert,
Class ends with END CLASS.
Here's the class transported from VO to X#, if you need whole project, pls tell me.
Attachments
dlgLsBuchen.zip
(8.15 KiB) Downloaded 114 times
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: EXIT in FOR Loop

Post by Chris »

Hi Franz,

It's because of the PRIVATE variables declared in the method body of GetArtField(), the parser does not expect them and loses sync. If you really need them, you need to enable support for them in the compiler options, in the App properties, Compiler page, check /memvar: Support MEMVAR, PRIVATE, PUBLIC vars.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
lagraf
Posts: 452
Joined: Thu Jan 18, 2018 9:03 am
Location: A

Re: EXIT in FOR Loop

Post by lagraf »

Hi Chris,
the privates are because of the Macrocompiler later in this Method, it compiles user defined formulas.
I changed properties to /memvar
Franz
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: EXIT in FOR Loop

Post by Chris »

Hi Franz,

OK, in that case, in order to avoid having this compiler option always enabled, it's probably better to have it enabled only locally, in this method that needs it. So you would add a

#pragma options ("memvar", on )

just before the method that uses them, and at the end of it a

#pragma options ("memvar", default )

But I see that the compiler has a problem with it, I think the compiler itself accepts it, but the parser is not aware of the pragma and still reports an error. Not sure if this is fixable, but will create a bug report for Robert to have a look.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply