Warning W0027 Compiling Error

Post Reply
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Warning W0027 Compiling Error

Post 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.
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Warning W0027 Compiling Error

Post 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. )
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Re: Warning W0027 Compiling Error

Post 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
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Warning W0027 Compiling Error

Post 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
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Re: Warning W0027 Compiling Error

Post 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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Warning W0027 Compiling Error

Post by Antonio Linares »

Greg,

Instead of:

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

try this:

IIF ( lNew, oPaperDbf:append(), )
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Warning W0027 Compiling Error

Post 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(),  ) )
 
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
Greg Gammon
Posts: 105
Joined: Fri Jun 09, 2006 3:27 pm
Location: Bryan, Texas

Re: Warning W0027 Compiling Error

Post 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.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Warning W0027 Compiling Error

Post 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... :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply