fbpx
Welcome, Guest
Username: Password: Remember me
This public forum is meant for questions and discussions about Visual FoxPro
  • Page:
  • 1

TOPIC:

2.6a vs 2.8.1 Primitive Replace Test 09 Jun 2021 23:02 #18757

  • jpmoschi


  • Posts: 34
  • 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


    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:

    Please Log in or Create an account to join the conversation.

    2.6a vs 2.8.1 Primitive Replace Test 10 Jun 2021 15:56 #18769

    • robert
    • robert's Avatar


  • Posts: 2222
  • 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
    local pblock := {|| 
                  FieldPutAlias(Alias(),"m02domicil","domicil ")  
                  FieldPutAlias(Alias(),"m02nombre","nombre ")
                  return 0
                  }

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

    Then you do not need the return statement.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    2.6a vs 2.8.1 Primitive Replace Test 10 Jun 2021 15:58 #18770

    • robert
    • robert's Avatar


  • Posts: 2222
  • Juan,
    I have an idea.
    Can you change the code to:
    DbEval(pblock, pconditionFor, {||TRUE})

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Last edit: by robert.

    2.6a vs 2.8.1 Primitive Replace Test 10 Jun 2021 16:33 #18771

    • jpmoschi


  • Posts: 34
  • 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 ConsoleApplication1\Program.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?
    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

    Please Log in or Create an account to join the conversation.

    2.6a vs 2.8.1 Primitive Replace Test 10 Jun 2021 17:45 #18773

    • jpmoschi


  • Posts: 34
  • It runed ok, the replace test is approved!!
    Thanks Robert

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1