Fighting Xbrowse and lozing !!!

Fighting Xbrowse and lozing !!!

Postby Marc Venken » Sat Dec 17, 2022 11:43 am

Whats in a title....

I have following issue. At random looking at my code, i discoffered a real issue of bad programming from my site of cource !

Using 90% of Xbrowse time in my program, Xbrowse performance is essential, so I need to do it correct.

I put a controlling function "GetOrgfoto" to see how many times it will be called while running my program.

Code: Select all  Expand view  RUN
function getorgfoto(cFoto)
  nErrorTel ++
  cFoto="d:\pictures\origineel\"+alltrim(cFoto)
  aadd(aErrordata,cFoto)
  if !file(cFoto)
    cFoto = "
d:\pictures\origineel\nofoto.jpg"
  endif
return cFoto

function showpicture(cType)
  do case
    case cType = "
WEBSHOP_KLEUREN"
       for I = 1 to 12
         cColor = "
webshop->color"+alltrim(str(i))
         if empty(cColor)
             aGaleryNaam[i] = "
Geen Kleur"
         else
             aGaleryNaam[i] = &cColor
         endif
         oGaleryNaam[i]:refresh()
         oGaleryNaam[i]:show()
       next
    case cType = "
EAN_BASIS"
       ....
  endcase
  oSys_image:refresh()
  oText[3]:refresh() // Supet TXT
  oText[4]:refresh() //  Naam
  oText[5]:refresh() //  Lev. SuperTXT
return



From Xbrowse i do :

Code: Select all  Expand view  RUN

oBrw:bChange    := { ||  showpicture("WEBSHOP_KLEUREN"),oBrw:refresh() }

WITH OBJECT oBrw  // General for all browsers
      case cData = "WEBSHOP_KLEUREN"
         WITH OBJECT :Akt
           :AddBitmap( aBmp )
           :bBmpData   := { || if( ( oBrw:cAlias )->aktief = 1,1,2) }
         END
         WITH OBJECT :Cover
           :nEditType     := EDIT_GET_BUTTON
           :bStrImage     := { || getorgfoto(webshop->orgfoto) }
           :bEditBlock    := { |r,c,oCol| EanfotoSelect( oCol:Value ) }
           :oDataFont     := oFontXS
           :nDataStrAlign := AL_CENTER + AL_BOTTOM
           :nDataBmpAlign := AL_CENTER
         END
         if lCheck[CHK_FOTOGALERY]
            oBrw:nRowHeight:= 99
            oBrw:nFootStrAligns      := AL_CENTER

            for i = 1 to 12
             cPic = "pic"+alltrim(str(i))
             cColor = "color"+alltrim(str(i))
             WITH OBJECT:&cpic
                 :nEditType     := EDIT_GET_BUTTON
                 :bStrImage     := { || getorgfoto(webshop->&cPic) }
                 :bFooter   := { || alltrim( webshop->&cColor ) }
                 :bEditBlock    := { |r,c,oCol| EanfotoSelect( oCol:Value ) }
                 :oDataFont     := oFontXS
                 :nDataStrAlign := AL_CENTER + AL_BOTTOM
                 :nDataBmpAlign := AL_CENTER
              END
            next
         endif
 


What happens :

Just opening the program and the array (controling function) has 13 items
Clicking a foldertab to go to a selected xbrowse the items are : 169
Clicking on the browse with the right key 5 times, no edit, just move 5 celss to the right : items : 598
Moving up/down en left to right 2 times : Items : 1652
A dobble click will add more that 200 items

Clear that every movement is calling the function many many times....
Not only movement, but editing etc... is calling functions more than once at some times.


Clear that my fundamentals in programming xbrowse are wrong comming to the point how to use :

refresh() the browse, the cells , and the rows.... (HERE IT IS GOING WRONG)
How to move without calling any action ? It should not call one.

I know that when I digg into the forum and extract samples, I can get the issue solved, but the refresh stuff I do need to know !!

Please some advice ....

The browse :
Image
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Sat Dec 17, 2022 5:57 pm

This one is at least one of the big problems.

in the loop

for i = 1 to 12

:bStrImage := { || getorgfoto(webshop->&cPic) }
...
next

Looking for why
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby Detlef » Wed Dec 21, 2022 5:49 pm

Hi Marc,
I'm sorry not to be able giving you any help. :(
I just write this answer to push your request on top again… maybe someone has a solution for your problem.
This would be also interesting for me.
Regards
Detlef
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Thu Dec 22, 2022 8:17 am

Thanks Detlef,

The fact is that I think wrong about some of the methods of Xbrowse. So it is a hunt for information on the forum, but Xbrowse is surrely one of the most disscusted topic's, so a lot of data.
For all the methods are pretty clear, but using the correct method is important.

I have to look into methods :
bChange
bOnchange
Key

because it is not normal that in my program when I move to the right, a function is called. In Yunus it is not, so I have to Dissect Yunus and some more samples (but finding them..)

Also in the code above, in the loop for i 1 to 12 this loop is executed every time and when there is a bstrimage : getorgfoto... this is also executed, so I get a lot of code that is processed.
This technique I use is wrong, so this is what I need to discover.

I probably do it also when there is data to retrieve/write to a dbf, and then I get delays for sure. I have to look into this also.

The program is working ok, In normal way I would not even know that I do it wrong, but putting a debug array/message in a function it shows how many times it is executed. Then you start to know that you are doing stuff wrong.
In debug mode, I now have a second screen/monitor open with running debug parameters, so I can see where it is going wrong.

I was hoping to put the program live starting on 1 jan in my business (5 pc's). Then the time delays will be much more noticesable.

I have to setup a system like Otto has told before... Running on a server and not like I do Peer to Peer. I works dow!!! but sometimes with delay's and these can be possible due to my minor program techniques.

BTW : Maybe we can convince Mr. Rao to put his collection of samples he build for the forum on one place in the FW repository so that we can look into those. This would help a lot :wink: :wink:
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby Detlef » Thu Dec 22, 2022 10:11 am

Hi Marc,
You are right.
Mr. Rao is the one who could perhaps introduce some xBrowse templates about the most common cases of our daily work? :wink:
I'd be glad for this because I'm often unsure about the xBrowse internals concerning refreshing and updating the display of data values.

Regards,
Detlef
User avatar
Detlef
 
Posts: 209
Joined: Mon Feb 07, 2022 9:54 pm

Re: Fighting Xbrowse and lozing !!!

Postby RSalazarU » Thu Dec 22, 2022 3:45 pm

Hola Marc,

Tube un problema similar en mi programa.

Despues de revisar vi que era por que estaba habilitada la transparencia en el Browse

Prueba esto
Code: Select all  Expand view  RUN

   oBrw:lTransparent := .F.
 


Saludos,
Rolando
RSalazarU
 
Posts: 211
Joined: Wed Jul 16, 2008 12:59 pm
Location: Cochabamba-Bolivia

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Thu Dec 22, 2022 10:01 pm

Hey Rolando,

Tried it, but no changes. It seems also that lTransparent = .f. by default.

It however gave me the idea to look at the settings : and see if that make any changes.

Code: Select all  Expand view  RUN
Static Function StyleBrowse( oBrwSel, aBarget, aEditget, cNaam )
   LOCAL hBmp    := ReadBitmap( 0, "bitmaps\search.bmp" )
   local cCol,cTemp
   DEFAULT aBarget:={}
   DEFAULT aEditget:={}
   DEFAULT cNaam:=""

   if lPijama  //  Make stripes in the browse
      oBrwSel:bClrStd = { || If( oBrwSel:KeyNo() % 2 == 0, ;
                            { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrTxtBrw ),;
                              CLR_BROWSE2 }, ;
                            { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrTxtBrw ),;
                              CLR_BROWSE1 } ) }
      oBrwSel:bClrSel = { || { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrBackBrw ),;
                              CLR_BROWSEROW } }
   else
      oBrwSel:bClrStd := { || { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrTxtBrw ),;
                          nClrBackBrw } }
      oBrwSel:bClrSel := { || { If( ( oBrwSel:cAlias )->( Deleted() ), CLR_HRED, nClrBackBrw ),;
                           MY_PAARS } }
   endif


   cClrBack     := Eval( oBrwSel:bClrSelFocus )[ 2 ]  //  I don't know what this is doing

   oBrwSel:SetChecks()
   oBrwSel:bRClickHeaders := { || XbrColSelector( oBrwSel, cNaam ) }  // Kies welke velden tezien zijn
   //oBrwSel:SetRecSelBmp( "set.bmp" ) // red arrow as record-selector

   WITH OBJECT oBrwSel
      :l2007               := .F.
      :lFooter          := .T.
      :bRecSelHeader    := {|| "Klant" }
      :bRecSelData      := {| o | o:KeyNo }
      :bRecSelFooter    := {| o | o:nLen }
      :oRecSelFont      := oFont  // optional
      :nRecSelWidth     := "99999" // required size

      :lColChangeNotify    := .T.
      :nMarqueeStyle       := MARQSTYLE_HIGHLROW

      //:lAllowRowSizing     := .F.
      //:lAllowSizings       := .f.

      //:lHScroll      := .F.
      :lFullGrid           := .T.
      :lMultiSelect        := .T.
      :lRowDividerComplete := .T.
      :lColDividerComplete := .T.
      :nColDividerStyle    := LINESTYLE_LIGHTGRAY
      :nRowDividerStyle    := LINESTYLE_LIGHTGRAY
      :bClrSelFocus        := {|| { CLR_WHITE, CLR_BROWSECEL } } // CUANDO TIENE EL FOCUS
      :bClrRowFocus        := {|| { CLR_WHITE, CLR_BROWSEROW } }

      :nHeaderHeight       := 23
      :oHeaderFonts        := oBold
      :nHeadStrAligns      := AL_CENTER


      //:nFooterHeight     := oBrwSel:nHeaderHeight
      :nRowHeight          := oBrwSel:nHeaderHeight
      :nStretchCol         := NIL  // -2 // STRETCHCOL_WIDEST
      :nFreeze             := 1
      if lPijama
         :SetColor( CLR_BLACK, RGB( 232, 255, 232 ) ) // Pink
      else
         :SetColor( nClrTxtBrw, nClrBackBrw )
      endif
   END
   //  Toon de Bargetdata (Gets boven Bar)

   oBrwSel:lGetBar   := .T.  // Button to activate


   if len(aBarget)>0


      FOR EACH cCol in aBarget

         WITH OBJECT oBrwSel:oCol( cCol )

            :uBarGetVal    := uValBlank( :Value )

            :cBarGetPic    := :cEditPicture
            :bClrEdit      := {|| { CLR_BLACK, MY_LIGHTYELLOW } }

            :lBarGetOnKey := .T. // after having setfocus the oBrowse object, the end user can insert the characters directly into the get
//            :cBarGetBmp := hBmp // this for show the Bitmap on the get
            :bBarGetAction := {|| ( oBrwSel:cAlias )->( MARC_SETFILTER( oBrwSel ) ) } // this for show the bitmap on the get and associated a action
// //         :bBarGetAction := {|| ( oBrwSel:cAlias )->( SETFILTER( oBrwSel ) ) } // this for show the bitmap on the get and associated a action

         END

      NEXT


   endif
   */


   if len(aEditget)>0
      //xbrowser(aEditget) title oBrwSel:cAlias()
      FOR EACH cCol in aEditget
         //msginfo(cCol+oBrwSel:cAlias(),"Info")
         WITH OBJECT oBrwSel:oCol( cCol )
            :nEditType     := EDIT_GET
            :bClrHeader    := {|| { CLR_WHITE, CLR_BROWSEINDEX } }
            //msginfo(cCol+oBrwSel:cAlias(),"Info Done")
         END
      NEXT
   endif

   */
Return nil
 


Please keep in mind that my program consist of cut and paste parts that I find on the forum. Indeed sometimes with code i 'm not sure what is does :oops:

cClrBack     := Eval( oBrwSel:bClrSelFocus )[ 2 ]  //  I don't know what this is doing Even chatGPT will give not a clear answer :twisted:

:lColChangeNotify := .T. // from a post but maybe not good in this situation.
:lFullGrid := .T.

This function above is used to layout almost all of my browses. (designed from a dbf)
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Thu Dec 22, 2022 10:28 pm

I also noticed that just clicking the arrow to right, it processes the debug function 65 times
and hitting the arrow to go left just 13 times ??? while I would think that just moving to a cell, the debug would not be called once.

Commenting this code out, from the point of lCheck... (Lcheck is for painting the images or not. Not when I want more speed)
The number go from
Right key 65 times to 5
Left key 13 times to 1
Almost ok, but then I have no pictures, but only the filenames as text

Code: Select all  Expand view  RUN
        WITH OBJECT :Cover
           :nEditType     := EDIT_GET_BUTTON
           :bStrImage     := { || getorgfoto(webshop->orgfoto) }
           :bEditBlock    := { |r,c,oCol| EanfotoSelect( oCol:Value ) }
           :oDataFont     := oFontXS
           :nDataStrAlign := AL_CENTER + AL_BOTTOM
           :nDataBmpAlign := AL_CENTER
         END

         if lCheck[CHK_FOTOGALERY]
            oBrw:nRowHeight:= 99
            oBrw:nFootStrAligns      := AL_CENTER


            for i = 1 to 12
             cPic = "pic"+alltrim(str(i))
             cColor = "color"+alltrim(str(i))
             WITH OBJECT:&cpic
                 :nEditType     := EDIT_GET_BUTTON

                 //:nEditType     := EDIT_GET_LISTBOX
                 //:aEditListTxt  := oMarc:aLever
//                 :bStrImage     := { || "d:\pictures\origineel\"+alltrim(webshop->&cPic) }
                 :bStrImage     := { || getorgfoto(webshop->&cPic) }

                 //:bStrImage := {|x, oBrw| oBrw:aRow[ 2 ] }
                 //:bRClickData := { |r,c,oCol| oBrw:oCol:varput(EanfotoSelect())  }
                 :bFooter   := { || alltrim( webshop->&cColor ) }
                 :bEditBlock    := { |r,c,oCol| EanfotoSelect( oCol:Value ) }
                 //:cFooter   := { || Ltrim( webshop->&cColor ) }
                 :oDataFont     := oFontXS
                 :nDataStrAlign := AL_CENTER + AL_BOTTOM
                 :nDataBmpAlign := AL_CENTER
//                 :aImgRect      := { nil, nil, -15, nil }
//                 :lBmpTransparent  := .t.

              END
            next

         endif
 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Thu Dec 22, 2022 11:00 pm

This is the browse system that I use : Generate a browse with 1 line of code

oBrw[10] = getXBrowser("WEBSHOP_KLEUREN",oFld:aDialogs[FOL_WEBSHOP_KLEUREN])


Code: Select all  Expand view  RUN
  //  Code above this line is retrieving xbrowse data fields etc... from DBF
   @ nTop,nLeft XBROWSE oBrw size nBreed,nHoogte PIXEL OF oTarget font oFont ;
      DATASOURCE cDbf ;
      COLUMNS aVeld ;
      HEADERS aKop ;
      COLSIZES aSizes ;
      AUTOSORT CELL LINES NOBORDER FOOTERS

   oBrw:bToolTips   := ;
         { | oBrw,r,c,f,oMouseCol,nMouseRow| MyColToolTip( oBrw,r,c,f,oMouseCol,nMouseRow ) }

   oBrw:bRClicked     := { |r,c,f,oStru| msgWait(oBrw:aCols[oBrw:nColSel]:VALUE,,2),oClp:SetText(oBrw:aCols[oBrw:nColSel]:VALUE) }

   StyleBrowse(oBrw, aBrwGet, aBrwEdit ,cData )
   XbrSetupBar( oBrw , Cdata )

   if len(aBrwCols) > 0
     for i = 1 to len(aBrwCols)
        cVeld = aBrwCols[i][1]
        cExpres = aBrwCols[i][2]
        cFront = val(aBrwCols[i][3])
        cBack = val(aBrwCols[i][4])
        cZoek = oBrw:&cVeld:value
        lZoek = &cExpres

        oBrw:&cVeld:bClrStd := { || if ( lZoek  , ;
        {nClrTxtBrw, cBack } ,;
        {nClrTxtBrw, If( oBrw:KeyNo() % 2 == 0, CLR_BROWSE2, CLR_BROWSE1 )}    )}

     next
   endif
   ///  ONCHANGE
   if len(aOnchange) > 0
     for i = 1 to len(aOnchange)
        cVeld = aOnchange[i][1]
        cExpres = aOnchange[i][2]
        cZoek = oBrw:&cVeld:value
        cApi = StrTran( getdata(cExpres), "API-", "" )
        oBrw:&cVeld:bOnchange := { |oCol,uOldVal| web_changes(cApi,, oBrw) }
     next
   endif
   ///  Toont totaal selecties counter
   if len(aSelCount) > 0
     for i = 1 to len(aSelCount)
        cVeld = aSelCount[i][1]
        cExpres = aSelCount[i][2]
        cZoek = oBrw:&cVeld:value
        oBrw:&cVeld:nFooterType := AGGR_COUNT
        oBrw:&cVeld:bSumCondition := { || ( oBrw:cAlias )->selected }
     next
   endif

   WITH OBJECT oBrw  // General for all browsers
     //  cData = one of the browse that can be used.  I deleted most of them here because the don't be needed here
     do case
      case cData = "EMAILS_BASIS"  //  Browse 1
        oBrw:chimp:nFooterType := AGGR_COUNT
        oBrw:chimp:bSumCondition := { || ( oBrw:cAlias )->chimp }
      case cData = "SHOP_OPTIONS"  //  Browse 2
           WITH OBJECT :Act
             :AddBitmap( aBmp )
             :bBmpData   := { || if( ( oBrw:cAlias )->aktief = 1,1,2) }
           END

      case cData = "WEBSHOP_KLEUREN" //  Browse with issue
         WITH OBJECT :Akt
           :AddBitmap( aBmp )
           :bBmpData   := { || if( ( oBrw:cAlias )->aktief = 1,1,2) }
         END

         WITH OBJECT :Cover
           :nEditType     := EDIT_GET_BUTTON
           :bStrImage     := { || getorgfoto(webshop->orgfoto) }
           :bEditBlock    := { |r,c,oCol| EanfotoSelect( oCol:Value ) }
           :oDataFont     := oFontXS
           :nDataStrAlign := AL_CENTER + AL_BOTTOM
           :nDataBmpAlign := AL_CENTER
         END

         if lCheck[CHK_FOTOGALERY]
            oBrw:nRowHeight:= 99
            oBrw:nFootStrAligns      := AL_CENTER

            for i = 1 to 12
             cPic = "pic"+alltrim(str(i))
             cColor = "color"+alltrim(str(i))
             WITH OBJECT:&cpic
                 :nEditType     := EDIT_GET_BUTTON

                 //:nEditType     := EDIT_GET_LISTBOX
                 //:aEditListTxt  := oMarc:aLever
//                 :bStrImage     := { || "d:\pictures\origineel\"+alltrim(webshop->&cPic) }
                 :bStrImage     := { || getorgfoto(webshop->&cPic) }

                 //:bStrImage := {|x, oBrw| oBrw:aRow[ 2 ] }
                 //:bRClickData := { |r,c,oCol| oBrw:oCol:varput(EanfotoSelect())  }
                 :bFooter   := { || alltrim( webshop->&cColor ) }
                 :bEditBlock    := { |r,c,oCol| EanfotoSelect( oCol:Value ) }
                 //:cFooter   := { || Ltrim( webshop->&cColor ) }
                 :oDataFont     := oFontXS
                 :nDataStrAlign := AL_CENTER + AL_BOTTOM
                 :nDataBmpAlign := AL_CENTER
//                 :aImgRect      := { nil, nil, -15, nil }
//                 :lBmpTransparent  := .t.

              END
            next
            */
         endif
     endcase
   END
   oBrw:CreateFromCode()
   oBrw:MakeTotals()
   oBrw:refresh()

//   oBrw:CreateFromCode()
   oBrw:setfocus()
   if !empty(cRelation)  // not to refresh to much ?
      msginfo("cRelation : 2677")
      oBrw:gotop()
      oBrw:refresh()
   endif
   AEval( oBrw:aCols, { |o| o:bClrStd := FnClrStdBlock( o ) } )  // Kolom kleur voor index

return oBrw
 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby nageswaragunupudi » Fri Dec 23, 2022 8:01 am

How many records you have in the DBF. Please let me know.

Most of the times, you get better results if you keep the code to the least number of lines and do not change the xbrowse defaults.

For example, remove oBrw:lColChangeNotify := .t.
What is the need for it?

Change the default settings only when required and you clearly know why are you doing and its impact on the performance.

I try to give you a template soon for this kind of browse.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Fri Dec 23, 2022 9:40 am

There are 2.001 records in de dbf.

Indeed, The less code (options) the faster Xbrowse will be.... But you made Xbrowse so powerfull that we can pimp it to have a nice looking tool. Thanks for that.
It will be the goal to program it and keep speed/looks in the middle. Therefore I have put a selection tool (lCheck) to see pics or see tekst.

My problem is that I use the tools from Xbrowse the wrong way and I have to find them.

One of them is moving left to right and sure for right that is calling a function much more then expected.

From monday I have a week free, and have some time to check my code for these errors, but I have some fundamentals of Xbrowse that I use wrong.

It would be great if there was a demo program (like Yunus) that has as much as possible options activated and running. There could be a comment in the code if it is
- for design
- for speed
- or if a options will slow down.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Fri Dec 23, 2022 9:58 am

nageswaragunupudi wrote:
For example, remove oBrw:lColChangeNotify := .t.
What is the need for it?


I put it in by reading one of the topics here. Have to check wich one.

I suppose that was at a time that I wanted to have a automatic saving system (when something changes in any column of the browse, it will call a function that saves the old data and the new data in a kind of logging database
I think that lColChangeNotify := .t. will help doing this. (I will check de code)
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby nageswaragunupudi » Sat Dec 24, 2022 12:43 pm

We need to highly optimize image painting logic in the cells.
I will try to make a sample for you.

It will help me very much if you can share your dbf with me.
my email:
nageswaragunupudi [at] gmail [dot] com.
I don't need images. I will substitute with some images that are with me here
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Fighting Xbrowse and lozing !!!

Postby Marc Venken » Sat Dec 24, 2022 5:22 pm

Files are send... Thanks for the effort !
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Fighting Xbrowse and lozing !!!

Postby nageswaragunupudi » Fri Dec 30, 2022 8:38 am

With the existing code, painting or repainting of any image cell involves reading an image file from the disk, which consumes time. We have 12 image cells in each row.

When full browse is refreshed, ( number of visible rows + 1 ) * 12 times the image files are read from the disk.

Even repainting of a single row involves 12 file reads. Moving cursor to right or left involves full row painting.

We can not reduce the number of times image cells are repainted. What we can do is to read from disk only once per image file and when repainting the same cell, access the image from the memory. That is the best optimization we can do.

Based on this approach, I made a test program accessing image files from \fwh\bitmaps folder.
In this program I have focused on optimizing painting of image cells only.

You can test this program on your computer.
Code: Select all  Expand view  RUN

#include "fivewin.ch"

REQUEST DBFCDX

static cImagePath := "c:\fwh\bitmaps\"

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oFont, oBrw
   local cAlias, nPicCol, nCol, oCol
   local hImages  := {=>}

   if !File( "
IMGTEST" )
      CreateDBF()
   endif

   USE IMGTEST NEW SHARED ALIAS ( cAlias := cGetNewAlias( "
IMG" ) ) VIA "DBFCDX"

   hb_hSetCaseMatch( hImages, .f. )

   DEFINE FONT oFont NAME "
TAHOMA" SIZE 0,-12
   DEFINE DIALOG oDlg SIZE ScreenWidth() * 0.6, ScreenHeight() * 0.6 PIXEL TRUEPIXEL ;
      FONT oFont

   @ 20,20 XBROWSE oBrw SIZE -20, -20 PIXEL OF oDlg ;
      DATASOURCE cAlias ;
      COLUMNS "
Text","Pic1","Pic2","Pic3","Pic4","Pic5","Pic6", ;
                     "
Pic7","Pic8","Pic9","Pic10","Pic11","Pic12" ;
      LINES NOBORDER FOOTERS

   WITH OBJECT oBrw
      :nRowHeight    := 80
      :nWidths       := 80
      :RecSelShowRecNo()
      :lVThumbTrack  := .t.

      nPicCol        := :oCol( "
PIC1" ):nCreationOrder
      for nCol := nPicCol to nPicCol + 11
         WITH OBJECT :aCols[ nCol ]
            :nWidth     := 70
            :bStrData   := { |x,o| cFileName( o:Value ) }
            :bStrImage  := { |oCol| GetOrgFoto( oCol:Value, hImages ) }
            :nDataStrAlign := AL_CENTER + AL_BOTTOM
            :nDataBmpAlign := AL_CENTER
            :aImgRect      := { nil, nil, -20, nil }
         END
      next
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

   ( cAlias )->( DBCLOSEAREA() )

   hb_HEval( hImages, { |cKey, uVal| PalBmpFree( uVal ) } )

return nil

//----------------------------------------------------------------------------//

static function GetOrgFoto( cFile, hImages )

   if !hb_hHasKey( hImages, cFile )
      hImages[ cFile ]  := FW_ReadImage( nil, cImagePath + cFile, , .t. )[ 1 ]
   endif

return cValToChar( hImages[ cFile ] )

//----------------------------------------------------------------------------//

static function CreateDBF()

   local aFiles   := DIRECTORYRECURSE( cImagePath + "
*.*" )
   local i, j, n, nLen := Len( aFiles )
   local aStruct  := { { "
TEXT", "C", 20, 0 } }

   AEval( aFiles, { |a,i| a[ 1 ] := AfterAtNum( cImagePath, a[ 1 ] ) } )

   for i := 1 to 12
      AAdd( aStruct, { "
PIC" + cValToChar( i ), "C", 100, 0 } )
   next

   n  := 1
   DBCREATE( "
IMGTEST", aStruct, "DBFCDX", .T., "IMG" )
   for i := 1 to 2500
      DBAPPEND()
      FIELD->TEXT    := NtoCMONTH( ( i - 1 ) % 12 + 1 ) // some text
      for j := 2 to 13
         FieldPut( j, aFiles[ n, 1 ] )
         if ( ++n > nLen ); n := 1; endif
      next
   next

   CLOSE IMG

return nil


Image

Incorporating this logic into your application will greatly enhance the speed of image cell painting.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 103 guests