2.6a vs 2.8.1 Primitive Replace Test

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

Post Reply
jpmoschi
Posts: 77
Joined: Thu May 21, 2020 3:45 pm

2.6a vs 2.8.1 Primitive Replace Test

Post by jpmoschi »

Good morning forum, I am trying to jump from 2.6a to the last revision but i have primitive problems.
The next is a part of conseptual tests passed in revision 2.6a that fail in the last one
Attached a screen capture error catched in the code line below a fail comment
Best regards
Juan


Code: Select all

method TestReplace
    private stext                
    STORE SqlConnect("MSSQLTEST") to _handle
    LRESULT:= SqlExec(_handle , "select * from m02clie","m02clie")
    IF LRESULT >0
         DBGoTop()
         stext:= ""
         MALIAS:= ALIAS()
         DO WHILE (!Eof()) 
            FieldPutSelect(Alias(),"M02NOMBRE" , "CAMBIADO "+ LTrim(Str(RecNo())))
            DbSkip()
         ENDDO      
         // until here the test is passed!!!!
         local pblock := {|| 
              FieldPutAlias(Alias(),"m02domicil","domicil ")  
              FieldPutAlias(Alias(),"m02nombre","nombre ")
              return 0
              }
        local pconditionFor:= {|| (Mod(RecNo(),2)=0) }
         // FAIL!!! next line produce error, see the screen capture 
         if DbEval(pblock, pconditionFor )
            stext:= "ok"
            DbEval({|| stext:= stext + chr(13)+ m02domicil +"-" + m02nombre})
         else 
            stext:= "er"
         endif 
      endif 
Attachments
Captura.PNG
Captura.PNG (100.29 KiB) Viewed 614 times
User avatar
robert
Posts: 4478
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

2.6a vs 2.8.1 Primitive Replace Test

Post by robert »

Juan,

I am not sure what you are trying to do in the code on the bottom.
Without the rest of the code example database I find it hard to see where the problem is.
The error messages seems to indicate that somewhere in the code the runtime tries to convert a LOGIC value to a CODEBLOCK. This may be dependent on the contents of the table, or of private / public memvars that were defined before this code runs.

I see that your pblock returns a value of 0. Why is that ?
In the RDD system this return value is ignored, but if the value is a LOGIC and FALSE then the do while loop that processes all records will abort.
Btw: you can write this

Code: Select all

 local pblock := {|| 
              FieldPutAlias(Alias(),"m02domicil","domicil ")  
              FieldPutAlias(Alias(),"m02nombre","nombre ")
              return 0
              }
also as

Code: Select all

 local pblock := {||  FieldPutAlias(Alias(),"m02domicil","domicil ") , FieldPutAlias(Alias(),"m02nombre","nombre ")}
Then you do not need the return statement.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4478
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

2.6a vs 2.8.1 Primitive Replace Test

Post by robert »

Juan,
I have an idea.
Can you change the code to:

Code: Select all

DbEval(pblock, pconditionFor, {||TRUE})
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
jpmoschi
Posts: 77
Joined: Thu May 21, 2020 3:45 pm

2.6a vs 2.8.1 Primitive Replace Test

Post by jpmoschi »

Robert, thanks for your attention

I changed with your suggestion and the result is the same.The error : System.InvalidCastException
HResult=0x80004002
Message=No se puede convertir un objeto de tipo 'System.Boolean' al tipo 'XSharp.ICodeblock'.
Source=XSharp.RT
StackTrace:
at XSharp.RT.Functions.DbEval(__Usual[] Xs$Args)
at ConsoleApplication1.Exe.Functions.Start() in ConsoleApplication1Program.prg:line 31

Next the Program.prg (the only program in the Console Application project)
Look , i omitted the for block and the error not change. Do you want that i send you the datatable schema with 2 example rows to run the code?

Code: Select all

USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text

FUNCTION Start() AS VOID STRICT
    ? "Hello World! Today is ",Date()
    private _handle
    STORE SqlConnect("BITEST4") to _handle
    local LRESULT
    private stext                
    LRESULT:= sqlexec(_handle,"Select top 100 * from M02CLIE ","M02CLIE")
    IF LRESULT 
       DBGoTop()
       stext:= ""
       MALIAS:= ALIAS()
       DO WHILE (!EOF()) 
          FieldPutSelect(Alias(),"M02NOMBRE" , "CAMBIADO "+ LTRIM(STR(RECNO())))
          DBSKIP()
       ENDDO      
         
       /*local pblock := {|| 
              FieldPutAlias(Alias(),"m02domicil","domicil ")  
              FieldPutAlias(Alias(),"m02nombre","nombre ")
              return true
              }
        local pconditionFor:= {|| (Mod(RecNo(),2)=0) }
        */
        local pblock := {|| FieldPutAlias(Alias(),"m02domicil","domicil ") , FieldPutAlias(Alias(),"m02nombre","nombre ")}
         if DbEval(pblock )
            stext:= "ok"
            DbEval({|| stext:= stext + chr(13)+ m02domicil +"-" + m02nombre})
         else 
            stext:= "er"
         endif 
      endif 
      ?stext
      close 
    WAIT
    RETURN
jpmoschi
Posts: 77
Joined: Thu May 21, 2020 3:45 pm

2.6a vs 2.8.1 Primitive Replace Test

Post by jpmoschi »

It runed ok, the replace test is approved!!
Thanks Robert
jpmoschi
Posts: 77
Joined: Thu May 21, 2020 3:45 pm

2.6a vs 2.8.1 Primitive Replace Test

Post by jpmoschi »

Good morning guys, don't forget this old reported bug.
The primitive dbEval() must be forced cbforcondition and cbwhilecondition arguments to avoid an error. Look the attached image
FUNCTION DbEval(cbExecute AS USUAL := NIL,cbForCondition AS USUAL := NIL, cbWhileCondition AS USUAL := NIL, nNext AS USUAL := NIL,nRecord AS USUAL := NIL,lRest AS USUAL := NIL) AS LOGIC[/code]

thanks
Juan
Attachments
Captura.PNG
Captura.PNG (92.62 KiB) Viewed 614 times
User avatar
Chris
Posts: 4854
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

2.6a vs 2.8.1 Primitive Replace Test

Post by Chris »

Hi Juan,

Sorry about that, this bug must have slipped. At the moment Git is not behaving well, but will log it as soon as possible, so it will not be forgotten. Btw, in my tests it seems that when specifying both for and while blocks, the error does not happen anymore, but the records are not processed correctly either. It's a bug in the FoxPro dialect only, as it is working well in the VO dialect.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

2.6a vs 2.8.1 Primitive Replace Test

Post by Karl-Heinz »

Hi Chris

i think it´s the same DBEval() problem i described here:

https://github.com/X-Sharp/XSharpPublic/issues/673

It works in the VO dialect, but fails in the Foxpro dialect.

Karl-Heinz
User avatar
Chris
Posts: 4854
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

2.6a vs 2.8.1 Primitive Replace Test

Post by Chris »

Hi Karl-Heinz,

Ah thanks, so no need to log a new ticket, I have now updated your report with more info.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4478
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

2.6a vs 2.8.1 Primitive Replace Test

Post by robert »

Juan, Karl-Heinz, Chris,

This problem is caused by the fact that in the FoxPro dialect the default value of a USUAL is .F. and not NIL.
The IsNil() function recognizes that a usual value is uninitialized, but apparently the DbEval() code checks for uninitialized parameters in a different way.
I'll fix this for the next build.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply