Page 1 of 1

Warning W0027 Compiling Error

Posted: Mon Jan 20, 2014 8:36 pm
by Greg Gammon
Recently upgraded to Harbour 3.0 (downloaded from FiveWin site) as well as FWH13x. First upgrade in about 6 years. Following problem also exists using older FWH libraries so is Harbour related I believe.

I have numerous (hundreds) of Warning W0027 Meaningless use of expression "logical"...as well as others that I have not dug into yet (and I'm not eager to get into the run-time errors after a successful compile!) All of my code has been stable using the previous FWH/Harbour dated around 2006.

Here are two code blocks that I get this message regarding:

Code: Select all

        REDEFINE BUTTON oBtn4 ID 1007 OF oDlg WHEN lEdit ACTION;  //save
            IIF ( lNew, oPaperDbf:append(), .t.), ;
            IIF( (aSave[1] .or. aSave[2] .or. aSave[3] .or. aSave[4] .or. aSave[5] ), ;
                papsave(oPaperDbf, oSizeDbf, aSave), .t.) , ;
            oPaperDbf:Save(), lEdit := .F., ;
            IIF(lNew, papersize(oPaperDbf, oSizeDbf),.T.),;
            PostMessage(oLbx1:hWnd, WM_SETFOCUS), lNew := .F., oDlg:update()

Code: Select all

        REDEFINE BUTTON oBtn4 ID 1002 OF oDlg WHEN lEdit  ACTION ;
            IIF ( lEdit, oSizeDbf:append(), .t.), ;
            oSizeDbf:StkSize := STR(oSizeDbf:hsize,6,3)+ " X " +STR(oSizeDbf:vsize,6,3), ;
            oSizeDbf:Save(), lEdit := .F., PostMessage(oLbx1:hWnd, WM_SETFOCUS), oDlg:update()  
What I have discerned so far, is that almost all of the Warning errors are BUTTON commands that have more than one IIF statement or include a Postmessage statement.

Re: Warning W0027 Compiling Error

Posted: Mon Jan 20, 2014 8:54 pm
by cnavarro
The functions myfunction() included in the IIF (<lcond>, myfunction (), T.) return a boolean?
If not, try like this: IIF (<lcond>, (myfunction (), T.), T. )

Re: Warning W0027 Compiling Error

Posted: Mon Jan 20, 2014 9:03 pm
by Greg Gammon
Christobal,
Thanks for the quick reply. No, the functions do not return a logical, so I tried your idea of (myfunc(), t.) and it doubled the number of W0027 errors...twice as many ".t."...twice as many errors! oy vey....(and im not even jewish) :)
Greg

Re: Warning W0027 Compiling Error

Posted: Mon Jan 20, 2014 9:17 pm
by cnavarro
Sorry, did not understand well your problem
The solution is that the IIF function must be returned to a variable
Try also:

Code: Select all


REDEFINE BUTTON oBtn4 ID 1002 OF oDlg WHEN lEdit  ACTION ;
            lEdit := IIF ( lEdit, oSizeDbf:append(), .t.), ;
            oSizeDbf:StkSize := STR(oSizeDbf:hsize,6,3)+ " X " +STR(oSizeDbf:vsize,6,3), ;
            oSizeDbf:Save(), lEdit := .F., PostMessage(oLbx1:hWnd, WM_SETFOCUS), oDlg:update()
 
Use LEDIT for example or any variable

Re: Warning W0027 Compiling Error

Posted: Mon Jan 20, 2014 9:29 pm
by Greg Gammon
Christobal...that does indeed work (as far as getting rid of the compiler warning..but in runtime??), but Im confused as to why it is needed. I probably have 1000's of IIF's in my programs but only a hundred or so are coming up with this compile error. The "placeholder" variable ( lwhatever := IIF(...) is useless in the program itself. But thanks for the workaround...there will be more to come!
Greg

Re: Warning W0027 Compiling Error

Posted: Mon Jan 20, 2014 10:41 pm
by Antonio Linares
Greg,

Instead of:

IIF ( lNew, oPaperDbf:append(), .t.)

try this:

IIF ( lNew, oPaperDbf:append(), )

Re: Warning W0027 Compiling Error

Posted: Mon Jan 20, 2014 11:23 pm
by cnavarro
However, this code compiles perfectly

Code: Select all

@ ( nHg/2 ) - 30, 2*Int( nWd/6) + 50 BUTTON oBtn1 PROMPT "Aceptar" ;
             SIZE 50, 18 PIXEL OF oDlg ;
             FONT oFont2 ;
             ACTION ( lOk := .T., iif( lOk, oDlg:End(), .F. ) )
 
And this also

Code: Select all

@ ( nHg/2 ) - 30, 2*Int( nWd/6) + 50 BUTTON oBtn1 PROMPT "Aceptar" ;
             SIZE 50, 18 PIXEL OF oDlg ;
             FONT oFont2 ;
             ACTION ( lOk := .T., iif( lOk, oDlg:End(),  ) )
 

Re: Warning W0027 Compiling Error

Posted: Tue Jan 21, 2014 3:18 pm
by Greg Gammon
This is really a mystery to me. Here is a code block for a BUTTON that has 8 IIF statements. I was only getting two compile warnings on this block, so by elimination, I added a "placeholder" variable ph := IIF(.... to all of them and deleted one at a time and compiled to find which two lines were offending.

Code: Select all

        REDEFINE BUTTON oBtn1 ID 1026  WHEN nPermis < 4 ACTION ;                          //Save
            oEstDbf:CustMat := oCbx1:varget(), ; //to save custom entries in CustMat combo box
            IIF(oEstDbf:CustMat = '  ', (oCbx1:setcolor(nColorWht, nColorRed),oCbx1:refresh()), (la := .T. , oCbx1:setcolor(nColorBlk, nColorWht), oCbx1:refresh()  )), ;           
            IIF(oEstDbf:SheetPrmt = '  ', (oCbx6:setcolor(nColorWht, nColorRed),oCbx6:refresh()), (lh := .T. , oCbx6:setcolor(nColorBlk, nColorWht), oCbx6:refresh()  )), ;         
            IIF(oEstDbf:JobName = '  ', (oGet1:setcolor(nColorWht, nColorRed),oGet1:refresh()), (lb := .T. , oGet1:setcolor(nColorBlk, nColorWht), oGet1:refresh()  )), ;
            IIF(oEstDbf:salesmn = '  ', (oGet2:setcolor(nColorWht, nColorRed),oGet2:refresh()), (lc := .T. , oGet2:setcolor(nColorBlk, nColorWht), oGet2:refresh()  )), ;
            IIF(oEstDbf:TotPages < 2 , (oGet7:setcolor(nColorWht, nColorRed),oGet7:refresh()), (ld := .T. , oGet7:setcolor(nColorBlk, nColorLBlue), oGet7:refresh()  )), ;
            ph := IIF(oEstDbf:FlatH = 0 .OR. oEstDbf:FlatW = 0, (oGet3:setcolor(nColorWht, nColorRed), oGet4:setcolor(nColorWht, nColorRed), oGet3:refresh(), oGet4:refresh()), (le := .T. , oGet3:setcolor(nColorBlk, nColorWht), oGet4:setcolor(nColorBlk, nColorWht), oGet3:refresh(), oGet4:refresh  )), ;
            ph := IIF(oEstDbf:FinH = 0 .OR. oEstDbf:FinW = 0, (oGet5:setcolor(nColorWht, nColorRed), oGet6:setcolor(nColorWht, nColorRed), oGet5:refresh(), oGet6:refresh()), (lf := .T. , oGet5:setcolor(nColorBlk, nColorLBlue),oGet6:setcolor(nColorBLk, nColorLBlue), oGet5:refresh(), oGet6:refresh  )), ;
            IIF ( (la .and. lb .and. lc .and. ld .and. le .and. lf .and. lh) , (oDlg:end(), lSave := .T.), .T.)
The 2 offending lines don't seem to be much different than all the other lines. I also tried eliminating the ".T." on the last IIF statement as Antonio suggested but that had no effect.

Re: Warning W0027 Compiling Error

Posted: Tue Jan 21, 2014 10:52 pm
by Antonio Linares
Greg,

Those sentences get into a codeblock, and the compiler warns when there is a logical value that does nothing. In example:

local n := 1

.T.

MsgInfo( "hello world" )

in the above lines the .T. has no sense at all. Now lets take that code to a codeblock:

{ || n := 1, .T., MsgInfo( "hello world" ) }

again, whats the meaning for that .T. ? thats what the compiler warns us about. Not sure if this may help... :-)