Strange GRID problem

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
Zimbo
Posts: 56
Joined: Mon Nov 05, 2012 1:28 pm
Location: Scotland
Contact:

Strange GRID problem

Post by Zimbo »

I have encountered a strange problem with a GRID I am working on which displays four columns from a small DBF file (not an array). When the focused row in the GRID changes, I have to refresh the data displayed outside of the grid in the window in which it appears.

My problems were with the ON KEY function where I just could not get the right data to display and I have discovered this seems to be because I had inserted a MSGINFO() call within the ON KEY function (for testing). When I removed this, everything worked properly and the right data was
displayed.

I'm sure there is a simple explanation (surely not a bug?) for this and I am keen to learn more just in case I ever need to interrupt the function by adding something that pauses the function called by ON KEY rather than it running without interruption...

Hope this all makes sense!

Z

The program is almost 1000 lines, so I have extracted the sections that are of most interest.


Code: Select all

DEFINE GRID Grd_Emps
    ROW     40
    COL     40
    WIDTH  270
    HEIGHT 710
    WIDTHS { 80, 155, 155, 155}
    HEADERS {"Emp. No", "Surname", "Forename", "Dept."}
    ALLOWEDIT .F.           // False. Seperate button for this.
    COLUMNCONTROLS Nil      // { aCtrl_1 , aCtrl_2 , aCtrl_3 , aCtrl_4 , aCtrl_5 , aCtrl_6 } // Controls the GUI objects value - linked to above
    SHOWHEADERS .T.
    ROWSOURCE "Users"  // Database file alias
    COLUMNFIELDS { "USERNUMB", "SURNAME", "FORENAME", "DEPARTMT"}
    ALLOWAPPEND .F.          // False. Seperate button for this.
    ALLOWDELETE .F.          // False. NOT allowed with users!
    ONCLICK Win_Grid_Click()   // Works perfectly!
    ONKEY   Win_Grid_Key()     // BIG PROBLEMS WITH RESULTS IF I USE MSGINFO() inside of Win_Grid_Key()
END GRID

//  ************************************************************ //

FUNCTION Win_Grid_Key()

LOCAL lChange := .F.
LOCAL nKey    := 0

nKey := HMG_GetLastVirtualKeyDown()

DO CASE
    CASE nKey == VK_DOWN     // Arrow Down
    
        // THE FUNCTION BELOW HAS BEEN COMMENTED OUT AS IT CAUSED VERY ERRATIC RESULTS!
        // IT APPEARS THAT THE INTERRUPTION TO PROCESSING RESULTS IN THE FUNCTION RETURNING
        // THE OLD CELLROWFOCUSED VALUE RATHER THAT THE ONE IT SHOULD BE WHEN THE ARROW DOWN
        // IS REMOVED. TAKING THIS FUNCTION OUT SOLVED THE PROBLEM!!!
        //MsgInfo(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))  
    
        Users->( DBSEEK(CTON(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))) )
        lChange := .T.
    CASE nKey == VK_UP      // Arrow Up
    
        // AS ABOVE!
        //MsgInfo(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))
        
        Users->( DBSEEK(CTON(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))) )
        lChange := .T.
    CASE nKey == VK_NEXT     // Page Down
        Users->( DBGOBOTTOM() )
        lChange := .T.
    CASE nKey == VK_PRIOR    // Page Up
        Users->( DBGOTOP() )
        lChange := .T.
    OTHERWISE
        lChange := .F.
ENDCASE

// The user has selected a different row in the grid. Move to the
//     new record, then refresh the controls outside of the grid
//     to show the new data
If lChange 
    Win_Admin_Refresh()
ENDIF

RETURN Nil
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Strange GRID problem

Post by dragancesu »

You want control moving up-down, look ON CHANGE, it's for it

I am not sure what do you want? Can you explain?
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: Strange GRID problem

Post by andyglezl »

// THE FUNCTION BELOW HAS BEEN COMMENTED OUT AS IT CAUSED VERY ERRATIC RESULTS!
// IT APPEARS THAT THE INTERRUPTION TO PROCESSING RESULTS IN THE FUNCTION RETURNING
// THE OLD CELLROWFOCUSED VALUE RATHER THAT THE ONE IT SHOULD BE WHEN THE ARROW DOWN
// IS REMOVED. TAKING THIS FUNCTION OUT SOLVED THE PROBLEM!!!
//MsgInfo(Win_Admin.Grd_Emps.CELLEX(Win_Admin.Grd_Emps.CellRowFocused, 1))

Según entiendo, cada vez que oprimes las teclas Abajo y Arriba despliegas algo con MsgInfo(). Es practico esto ?
Porqué no creas un LABEL (en alguna parte de la pantalla) y despliegas el dato que quieres en ella ?
*----------------------------------------------------------------------------------------------------------------------------------------------
As I understand it, every time you press the Down and Up keys, display something with MsgInfo (). Is this practical?
Why do not you create a LABEL (somewhere on the screen) and display the data you want in it?
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
serge_girard
Posts: 3167
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Strange GRID problem

Post by serge_girard »

Zimbo,

MSGINFO can indeed cause problems when the screen is updated.
Best way to debug is (for me) very simple:

SET PRINTER TO somefile.txt
SET PRINTER ON
SET CONSOLE OFF

// put these ? every you want
? procname(), ....
etc.

SET PRINTER TO
SET PRINTER Off
SET CONSOLE On

Serge
There's nothing you can do that can't be done...
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Strange GRID problem

Post by dragancesu »

@Andy,
it's not a problem to understand what he's asking for than why he needs it
I have the impression that it tries to fill in two views (grid) and how it moves once to change the content in the other that will be paired with the value of some field
let's call it a master-detail form
If this solution is simple

@Zimbo, if I am right, can you upload this dbf files?
Zimbo
Posts: 56
Joined: Mon Nov 05, 2012 1:28 pm
Location: Scotland
Contact:

Re: Strange GRID problem

Post by Zimbo »

I think I have confused everyone (including myself!) ;-)

I am still at learner stage with GRID but needed to use it on a screen I am creating. The grid appears on the left side and contains 4 fields from the DBF. To the right are several labels / textbox's (as andyglezl had suggested above). The textboxes contain information from other fields in the DBF. I then wanted to be able to change the row being viewed in the GRID and make sure the information in the textboxes was updated. I had no problems using ON CLICK - that all works perfectly. What I could not get to work was the ON KEY. I had made a small mistake and could not work out why so I added a MSGINFO call to the ON KEY function so I could see what data the function was working with and I found my error (just a coding mistake). BUT, then the data in the textboxes was one record behind the row in the grid. I eventually took out the MSGINFO and it now works fine. As serge_girard says above, using MsgInfo can cause problems when a screen is updated. I had posted this hoping to confirm that this was the case. I'd love to know why it does if anyone knows?

So the lesson for me is to not interrupt the GRID....ON KEY function by displaying something on screen.

I will look at ON CHANGE but I think that may only be useful if the content of the GRID changes (most of the time, it does not).

I would also upload the DBF and the source but I am using a copy of client data, so cannot at the moment. I will create a version with dummy data.

I am happy the program is now working (testing still in progress) and thank you to all of you for the comments back which have been very helpful!

Z
franco
Posts: 821
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Strange GRID problem

Post by franco »

I do like Andy says above.
use a current label or for testing create a special label test.
when you want to use msgbox or msginfo just change the labels value with your msg value.
Franco
All The Best,
Franco
Canada
User avatar
mol
Posts: 3723
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: Strange GRID problem

Post by mol »

I'm using window title for creating debug info sometimes - without creating labels, logs, etc...
Very quick and easy to create, manipulate:

Code: Select all

Form.Title := "My debug info: "+hb_valtoexp(anyVariable)
User avatar
dragancesu
Posts: 921
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia

Re: Strange GRID problem

Post by dragancesu »

If you're a beginner I know how you feel

see <hmg_version>\ samples \ aplications \ contactos

This is an example where you will see how the form works
Post Reply