Error in Virtual Grid with dynamic font

Moderator: Rathinagiri

User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Error in Virtual Grid with dynamic font

Post by mol »

I found wrong behavior of GRID control when DynamicFont is used.
I want to use editable virtual grid with last column displayed with different font.
Everything goes OK with displaying.
When I edit cell and want to save it in array, This.CellColIndex always returns index of column dynamic font (in my sample last column, but you can test it with another)

Code: Select all

#include "hmg.ch"

Function Main
	public aCellCoordinates := {0,0}
	private aItems := {}

	AADD (aItems, {"Carrot",        5, "A"})
	AADD (aItems, {"Cauliflower",   0, "B"})
	AADD (aItems, {"Corn",         15, "C"})
	AADD (aItems, {"Tomato",        0, "D"})
	AADD (aItems, {"Zucchini",     20, "E"})

	aControls := { NIL, {'TEXTBOX','NUMERIC'}, NIL }
	aValid	:= { {||Grid_1_Valid()}, {||Grid_1_Valid()}, {||Grid_1_Valid()} }
	aWhen	:= { {||Grid_1_When()}, {||Grid_1_When()}, {||Grid_1_When()} }
	aJustify := {  GRID_JTFY_LEFT, GRID_JTFY_RIGHT, GRID_JTFY_CENTER }
   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 600 ;
      HEIGHT 400 ;
      MAIN 

	DEFINE GRID Grid_1
		PARENT Form_1
		ROW 10
		COL 10
		WIDTH 550
		HEIGHT 330
		ITEMS NIL
		HEADERS {'Product','Stock','Supplier'}
		FONTNAME "ARIAL"
		FONTSIZE 12
		WIDTHS {250,150,100}
		ALLOWEDIT .T.
		CELLNAVIGATION .T.
		COLUMNCONTROLS aControls
		COLUMNVALID aValid
		COLUMNWHEN aWhen
		VIRTUAL .T.
		OnQueryData Grid_1_OnQueryData()
		ITEMCOUNT len(aItems)
	END GRID
	
	aFont := ARRAY FONT "Webdings" SIZE 12 BOLD ITALIC
	if MsgYesNo("Do you want to test with Dynamic Font?")
		Form_1.Grid_1.ColumnDYNAMICFONT  (3) := {|| IF ( Form_1.Grid_1.CellEx(This.CellRowIndex,2) == 0, aFont, NIL) }
	endif

   END WINDOW

   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

Return
*--------------------------------
function Grid_1_OnQueryData

	local nRow
	local nCol

	nRow := This.QueryRowIndex
	nCol := This.QueryColIndex

	if nRow>0 .and. nCol >0
		This.QueryData := aItems[nRow, nCol]
	endif
return
*--------------------------------
function Grid_1_Valid
	local nRow
	local nCol

	nRow := This.CellRowIndex
	nCol := This.CellColIndex
	MsgInfo( "Coordinates saved in VALID function: " + hb_valtoexp(aCellCoordinates)+chr(10)+;
		"Actual coordinates: "+hb_valtoexp({nRow, nCol}) )
	aItems[nRow, nCol ] := This.CellValue
 return .t.
*--------------------------------
function Grid_1_When
	
	aCellCoordinates := { This.CellRowIndex, This.CellColIndex }
return .T.
*--------------------------------

User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Error in Virtual Grid with dynamic font

Post by andyglezl »

Yo veo que si se está grabando en el ARRAY lo que hay en el GRID...(o tal vez no entendí tu pregunta)
*-----------------------------------------------------------------------------------------------------------------------------
I see that if you are recording in the ARRAY what is in the GRID ... (or maybe I did not understand your question)


mol.png
mol.png (46.9 KiB) Viewed 4645 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Error in Virtual Grid with dynamic font

Post by andyglezl »

OK ya vi el problema
*-----------------------------------
OK I saw the problem
mol.png
mol.png (56.38 KiB) Viewed 4641 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Error in Virtual Grid with dynamic font

Post by andyglezl »

Si cambias lo siguiente, funciona OK
*----------------------------------------------------
If you change the following, it works OK

Code: Select all

*--------------------------------
function Grid_1_Valid
	local nRow
	local nCol

	*nRow := This.CellRowIndex
	*nCol := This.CellColIndex
	
	nRow := aCellCoordinates[ 1 ]
	nCol := aCellCoordinates[ 2 ]
	
	MsgInfo( "Coordinates saved in VALID function: " + hb_valtoexp(aCellCoordinates)+chr(10)+;
		"Actual coordinates: "+hb_valtoexp({nRow, nCol}) )
	aItems[nRow, nCol ] := This.CellValue
	MSGDEBUG( aItems )
 return .t.
mol.png
mol.png (66.55 KiB) Viewed 4637 times
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Error in Virtual Grid with dynamic font

Post by mol »

Of course we can use workaround, but this situation is a bug and should be repaired in sources.
I've lost a lot of time to find what's going on
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Error in Virtual Grid with dynamic font

Post by andyglezl »

Lo siento, yo nunca he modificado algún fuente de HMG...
*----------------------------------------------------------------------------
I'm sorry, I've never modified any source of HMG ...

A quien corresponda:
*---------------------------
To whom it May concern:
mol wrote: Fri May 10, 2019 9:22 pm Of course we can use workaround, but this situation is a bug and should be repaired in sources.
I've lost a lot of time to find what's going on
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Error in Virtual Grid with dynamic font

Post by mol »

I found another strange behavior of GRID control.
When I'm editing cell with defined WHEN, when function is called for every cell in row - it causes strange flickering, etc...
I'll prepare small sample or video.
While investigating this, I found the problem is within PROCEDURE _HMG_GRIDINPLACEKBDEDIT_2(i) in h_grid.prg lines 1957-2035:

Code: Select all

If ValType ( aColumnWhen ) == 'A'

                  nStart := _HMG_SYSDATA [ 15 ] [I]
   
                  nEnd := HMG_LEN ( aColumnWhen )

                  For j := nStart To nEnd

                     If ValType ( aColumnWhen [j] ) == 'B'

*******************************************************************************************************************************
                        IF _HMG_SYSDATA [ 40 ] [ i ] [ 9 ] == .F.
                           aTemp := this.item( nWhenRow )
                           xTmpCellValue := aTemp [j]
                        ELSE
                           _HMG_SYSDATA [ 201 ] := nWhenRow // QueryRowIndex
                           _HMG_SYSDATA [ 202 ] := j   // QueryColIndex
                           _HMG_SYSDATA [ 320 ] := .T.
                           IF ValType ( _HMG_SYSDATA [ 40 ] [ i ] [ 10 ] ) == 'C'
                              GetDataGridCellData ( i , .t. )
                           ELSE
                              Eval( _HMG_SYSDATA [  6 ] [ i ]  )      
                           ENDIF
                           _HMG_SYSDATA [ 320 ] := .F.
                           xTmpCellValue := _HMG_SYSDATA [ 230 ]   
                        ENDIF
********************************************************************************************************************************

                        _HMG_SYSDATA [ 318 ] := xTmpCellValue

                        _HMG_SYSDATA [ 232 ] := 'GRID_WHEN'

                        lResult := Eval ( aColumnWhen [j] )

                        _HMG_SYSDATA [ 232 ] := ''

                        If lResult == .F.

                           _HMG_SYSDATA [ 15 ] [I]++
                        
                        Else

                           Exit

                        EndIf

                     EndIf

                  Next j
Setting nEnd to HMG_LEN ( aColumnWhen ) causes testing every cell to the end of row - why?!
In my opinion it should be tested only current cell.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Error in Virtual Grid with dynamic font

Post by serge_girard »

Marek,

I'm afraid that as long as we have no successor for Claudio, we will have to work with this kind of work-arounds...
Regretfully, but I don't see any other option...

Serge
There's nothing you can do that can't be done...
User avatar
mol
Posts: 3718
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Error in Virtual Grid with dynamic font

Post by mol »

You are right, Serge!
It's very sad.
Our hmg is going to dead.
It is dangerous to have only one leader
User avatar
apais
Posts: 440
Joined: Fri Aug 01, 2008 6:03 pm
DBs Used: DBF
Location: uruguay
Contact:

Re: Error in Virtual Grid with dynamic font

Post by apais »

That's why I've been suggesting the merge among HMG and HMG Extended.
HMG Extended has a better development pace, and Harbour has a better forum/community.
Angel Pais
Web Apps consultant/architect/developer.
HW_apache (webserver modules) co-developer.
HbTron (Html GUI for harbour desktop hybrid apps) co-developer.
https://www.hbtron.com
Post Reply