FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Xbrowse SetCheck() Problem
Posts: 110
Joined: Wed Feb 18, 2009 09:58 AM

Xbrowse SetCheck() Problem

Posted: Wed Jul 08, 2009 11:24 AM
Hello,can some one help me
I am using an array in Xbrowse to enable/disable checkbox(BitMap).
IF oRecSetUserPermission:Fields("Menu_Type"):Value=='S' When this Condition if true i want to
Disable CheckBox else i want to enable checkbox(BitMap).When this code is Executed i am Getting a error.

Error:Method valid only for Logical operator is Displayed in MsgBox .
after that Menu is Displayed in x Browse but Status is not Displayed.

Version used FWH(9.04)


Code (fw): Select all Collapse
         @0,30  XBROWSE oBrw  OF oDlg   ;
                   LINES CELL                       ;
                   Size 400,600                     ;
                  FONT oFontGet                  ;
                  COLUMNS 1,2                    ;
                Headers "Menu","Status"

         oBrw:nMarqueeStyle            := 6
         oBrw:nRowDividerStyle        := LINESTYLE_NOLINES
         oBrw:nColDividerStyle         := LINESTYLE_NOLINES
         oBrw:nHeaderHeight           := 38
         oBrw:nRowHeight               := 20
         oBrw:lColDividerComplete   := .T.
         aClrCol                              :={ { 0, nRGB(192,221,255) }, { 0, nRGB(221,245,255) } }
         oBrw:bClrStd                     := { || aClrCol[ oBrw:KeyNo % 2 + 1 ] }
         oBrw:bClrHEADER              := {|| { CLR_BLUE, CLR_WHITE  } }
         oBrw:l2007                        := .T.

           // aadd( aArray1,{"",.F.} )

      WHILE  !oRecSetUserPermission:BOF() .AND. !oRecSetUserPermission:EOF()   
                      //oRecSetUserPermission( RecordSetObject)
             IF  oRecSetUserPermission:Fields("Menu_Type"):Value=='S'
                 aadd( aArray1,{oRecSetUserPermission:Fields("Menu"):Value,nil} )//Disable Check List
             ELSE
                aadd( aArray1,{oRecSetUserPermission:Fields("Menu"):Value,.F.} )//Enable 
            END IF
                oRecSetUserPermission:MoveNext()
     END

         oBrw:SetArray(aArray1)
         oBrw:CreateFromCode()

        oBrw:aCols[1 ]:cHeader := "Menu"
        oBrw:aCols[1 ]:nWidth   :=300
        oBrw:aCols[2 ]:cHeader := "Status"
        oBrw:aCols[2 ]:SetCheck( {"on.bmp","off.bmp"}, {|o,u| o:Value( u ) } )
        oBrw:aCols[2 ]:bStrData := {|| NIL }
        oBrw:aCols[2 ]:lBmpTransparent:= .f.


  //xBrwAdoSettings(oBrw,oRecSetUserPermission)

  oDlg:oClient:=oBrw

  oBrw:Refresh()
  oDlg:Refresh()

  RETURN oBrw


Regards,
sajith
Posts: 1387
Joined: Fri May 23, 2008 01:33 PM

Re: Xbrowse SetCheck() Problem

Posted: Wed Jul 08, 2009 01:24 PM

Hi,

I think I have the same problem. My thread is viewtopic.php?f=3&t=16045. But Nobody answered.

Can you try to add the xbrowse.prg in your project from \FWH\source\classes. Normal xbrowse also does not work properly. I think xbrowse.prg is different than compiled one in Library.

Regards,



Hakan ONEMLI



Harbour & MSVC 2022 & FWH 23.06
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 PM

Re: Xbrowse SetCheck() Problem

Posted: Wed Jul 08, 2009 03:02 PM

Hello sajith

Do you use any SQL with RS?

How do you declare the logical field in DB?

Posts: 110
Joined: Wed Feb 18, 2009 09:58 AM

Re: Xbrowse SetCheck() Problem

Posted: Thu Jul 09, 2009 07:36 AM
Hello Daniel ,Many thanks for ur Rply

My Database is Mysql(5.1).In database there is no Logical Field .i manage Logical field in array(aArray1:={})Pls see my code below.Iam setting User Permission screen .(Pls check While condition )

Sql Query for Table creation:
Code (fw): Select all Collapse
*/Create Query*/

 CREATE TABLE `menu` (
 `Module_ID` int(11) NOT NULL,
 `Menu_ID` int(11) NOT NULL,
 `Menu_Text` varchar(25) DEFAULT NULL,
 `Menu_Type` enum('-','S','M') NOT NULL,
 `ParentMenu_ID` int(11) DEFAULT NULL,
 `Menu_Action` varchar(45) DEFAULT 'n',
 `Menu_Hierarchy` varchar(15) DEFAULT NULL,
 PRIMARY KEY (`Module_ID`,`Menu_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


code
//Code
Code (fw): Select all Collapse
*--------------------------------------------------
FUNCTION UserPermission()
*--------------------------------------------------


LOCAL oDlg, oBrowser,oBrowserUser,oRecSetUserPermission, oFontlabel , oBtnAdd,oBtnSave,oRecSetUser

oRecSetUserPermission:=nil
oRecSetUser:=nil

DEFINE      BRUSH oBrush File "Icons\bg.bmp"
DEFINE      FONT oFontlabel NAME "Arial" SIZE 0,-12 BOLD
DEFINE      FONT oFontGet NAME "Tahoma" SIZE 0,-13
DEFINE      DIALOG oDlg TITLE "User" SIZE 900,600;
                BRUSH oBrush


ACTIVATE DIALOG oDlg CENTER ON INIT( oRecSetUserPermission:= LoadUserPermission() ,  ;
                oBrowser:= CreatexBrowseUserPerMission(oDlg,oRecSetUserPermission))
               

RETURN nil


**------------------------------------------------------------------------------
FUNCTION CreatexBrowseUserPerMission(oDlg,oRecSetUserPermission)    //For creating the xBrowse Control
**------------------------------------------------------------------------------

   LOCAL     aClrCol,oBrw ,oBrush,oBrushxBrowse,aArray1:={}

   DEFINE    BRUSH oBrush File "Icons\bg.bmp"
   DEFINE    BRUSH oBrushxBrowse COLOR nRGB(192,221,255)
   DEFINE    FONT oFontBrowse NAME "Tahoma" SIZE 0,-13 BOLD
   DEFINE    FONT oFontGet NAME "Tahoma" SIZE 0,-13


         @0,30  XBROWSE oBrw  OF oDlg                       ;
                LINES CELL                                  ;
                Size 400,600                                ;
                FONT oFontGet                               ;
                COLUMNS 1,2                                 ;
                Headers "Menu","Status"

         oBrw:nMarqueeStyle       := 6
         oBrw:nRowDividerStyle    := LINESTYLE_NOLINES
         oBrw:nColDividerStyle    := LINESTYLE_NOLINES
         oBrw:nHeaderHeight       := 38
         oBrw:nRowHeight          := 20
         oBrw:lColDividerComplete := .T.
         aClrCol                  :={ { 0, nRGB(192,221,255) }, { 0, nRGB(221,245,255) } }
         oBrw:bClrStd             := { || aClrCol[ oBrw:KeyNo % 2 + 1 ] }
         oBrw:bClrHEADER          := {|| { CLR_BLUE, CLR_WHITE  } }
         oBrw:l2007               := .T.

           // aadd( aArray1,{"",.F.} )

        WHILE  !oRecSetUserPermission:BOF() .AND. !oRecSetUserPermission:EOF()
           IF  oRecSetUserPermission:Fields("Menu_Type"):Value=='S'
              aadd( aArray1,{oRecSetUserPermission:Fields("Menu"):Value,nil} )//Here i want to Hide the CheckBox for that
            //Iam giving Boolean value as Nil
           ELSE
              aadd( aArray1,{oRecSetUserPermission:Fields("Menu"):Value,.F.} )//Here to Show CheckBox
           END IF
              oRecSetUserPermission:MoveNext()
       END

         oBrw:SetArray(aArray1)
         oBrw:CreateFromCode()

        oBrw:aCols[1 ]:cHeader          := "Menu"
        oBrw:aCols[1 ]:nWidth           :=300
        oBrw:aCols[2 ]:cHeader          := "Status"
        oBrw:aCols[2 ]:SetCheck( {"on.bmp","off.bmp"}, {|o,u| o:Value( u ) } )
        oBrw:aCols[2 ]:bStrData         := {|| NIL }
        oBrw:aCols[2 ]:lBmpTransparent  := .f.


  //xBrwAdoSettings(oBrw,oRecSetUserPermission)

  oDlg:oClient:=oBrw

  oBrw:Refresh()
  oDlg:Refresh()

  RETURN oBrw



*------------------------------------------------------------------------------
FUNCTION LoadUserPermission()   //Loading DATA From the database(Mysql)
*------------------------------------------------------------------------------
LOCAL oRecSetUserPermission:=nil,cSql

 cSql:="select Menu_id,Menu_Type, case when Menu_Type='S' and ParentMenu_Id=0 then Menu_Text "
 cSql+=" when Menu_Type='S' and ParentMenu_Id!=0 then INSERT(Menu_Text,1, 0, Space(length(Menu_Hierarchy+12)))"
 cSql+=" Else  INSERT(Menu_Text,1, 0, Space(Menu_Hierarchy )) End as Menu    from menu order by Menu_Hierarchy "

  // QuickWatch(cSql)

  oRecSetUserPermission:=LoadData(cSql)
RETURN oRecSetUserPermission

*---------------------------------------------------------------------------------------
Function LoadData(cSql)
*---------------------------------------------------------------------------------------
  LOCAL oRecSet
// oCon:=GetConnection()
  oRecSet:=CreateObject("ADODB.RecordSet")
  oRecSet:CursorLocation := adUseClient
  oRecSet:LockType := adLockOptimistic
  oRecSet:CursorType := adOpenDynamic
  oRecSet:Source :=cSql
  oRecSet:ActiveConnection(oApp:oConnection)

 TRY
   oRecSet:Open()

 CATCH oError
   MsgInfo("Failed to Open Recordset ")
   oRecSet:=NIL
   Return oRecSet
 END

 if oRecSet:BOF() .AND. oRecSet:EOF()
   Msginfo("Did not find any Record")
   //CloseConnection(oRecSet)
   Return oRecSet
 Endif

 oRecSet:MoveFirst()

RETURN oRecSet


Regards ,
sajith
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM

Re: Xbrowse SetCheck() Problem

Posted: Thu Jul 09, 2009 08:23 AM
Dear Mr.Sajith,

IF oRecSetUserPermission:Fields("Menu_Type"):Value=='S' When this Condition if true i want to
Disable CheckBox else i want to enable checkbox(BitMap).When this code is Executed i am Getting a error.

I could not understand your requirement very well. If your intention is to display the Bitmaps (CheckOn and CheckOff) only on certain rows based on certain condition, then you may use bBmpData

IF oRecSetUserPermission:Fields("Menu_Type"):Value=='S' When this Condition if true


Assuming that your xBrowse array holds the value of oRecSetUserPermission:Fields("Menu_Type"):Value which would be either "S" or some other value

Code (fw): Select all Collapse
// Easiest way to display a BMP based on the Logical Value
*oBrw:aCols[2]:SetCheck( { "CheckOn", "CheckOff" } )

// Alternative way to display BMP, if multiple conditions and more than 2 bitmaps are there
oBrw:aCols[2]:AddResource("CheckOn")

// Now the xBrowse trick to display the BMP's (CheckOn & CheckOff) only on certain rows
// based on a condition
// Checkbox should be displayed only if the menu type is not "S"
// Assuming the 4th element of u'r Xbrowse array contains Menu_type 
// Assuming the 3rd element of u'r Xbrowse array contains Logical value, based
// on which u decide to display either the BMP CheckOn or CheckOff
oBrw:aCols[2]:bBmpData :={ || iif(oBrw:aArrayData[oBrw:nArrayAt][4] == "S",0,iif(oBrw:aArrayData[oBrw:nArrayAt][3],1,2))  }

Hope it is clear to u.

Regards
Anser
Posts: 110
Joined: Wed Feb 18, 2009 09:58 AM

Re: Xbrowse SetCheck() Problem

Posted: Thu Jul 09, 2009 09:27 AM
Dear Anser, many thanks for ur reply

My intention is to display the Bitmaps (CheckOn and CheckOff) only on certain rows based on certain condition.i tried the code given by u still Same Problem Remains.CheckBox is Displayed for all Row.
Code (fw): Select all Collapse
 
      oBrw:aCols[1 ]:cHeader          := "Menu"
        oBrw:aCols[1 ]:nWidth           :=300
        oBrw:aCols[2 ]:cHeader          := "Status"
        oBrw:aCols[2 ]:SetCheck( {"on.bmp","off.bmp"}, {|o,u| o:Value( u ) } )
        oBrw:aCols[2 ]:bStrData         := {|| NIL }
        oBrw:aCols[2 ]:lBmpTransparent  := .f.



        oBrw:aCols[2]:bBmpData :={ || iif(oBrw:aArrayData[oBrw:nArrayAt][1] == "S",0,;
                                      iif(oBrw:aArrayData[oBrw:nArrayAt][2],1,2)) }


Regards,
sajith
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM

Re: Xbrowse SetCheck() Problem

Posted: Thu Jul 09, 2009 10:05 AM

Instead of
oBrw:aCols[2 ]:SetCheck( {"on.bmp","off.bmp"}, {|o,u| o:Value( u ) } )

Try this
oBrw:aCols[2]:AddResource("CheckOn")
oBrw:aCols[2]:AddResource("CheckOff")

OR

Try this
oBrw:aCols[2]:SetCheck( { "CheckOn", "CheckOff" } )

The above code is working fine for me here in my app

If still not working then please confirm whether your array contains expected data/values such that the PRG gives output as per your expectation.

Regards
Anser

Posts: 110
Joined: Wed Feb 18, 2009 09:58 AM

Re: Xbrowse SetCheck() Problem

Posted: Thu Jul 09, 2009 12:10 PM

Dear Anser,Many thanks for ur Rply

Pblm still Remain .

Regards,
sajith

Posts: 110
Joined: Wed Feb 18, 2009 09:58 AM

Re: Xbrowse SetCheck() Problem

Posted: Thu Jul 09, 2009 01:49 PM

Hello Anser,Many thanks for ur Reply ur Advice works

   oBrw:aCols[2]:bBmpData :={ || iif(oBrw:aArrayData[oBrw:nArrayAt][3] == "S",0,;
                                  iif(oBrw:aArrayData[oBrw:nArrayAt][2],1,2)) }

My problem is Solved.

Regards,
sajith

Continue the discussion