Data base RecNo() in Grid

Moderator: Rathinagiri

Post Reply
KDJ
Posts: 178
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 190 times

Data base RecNo() in Grid

Post by KDJ » Fri Oct 28, 2016 6:13 pm

Moving the mouse cursor within Grid control causes the change of database record (Alias->(RecNo())).
This is a bug or intentional action?

Example:

Code: Select all

// Move the mouse cursor within Grid control and observe StatusBar.

#include 'hmg.ch'

FUNCTION Main()

  OpenData()

  DEFINE WINDOW Main_WA;
    MAIN;
    WIDTH  310;
    HEIGHT 235;
    TITLE  'Grid Test'

    DEFINE GRID Users_GR
      ROW             10
      COL             10
      WIDTH          280
      HEIGHT         120
      HEADERS        {'Record', 'Name', 'Price'}
      WIDTHS         {55, 130, 70}
      CELLNAVIGATION .F.
      ROWSOURCE      'Comp'
      COLUMNFIELDS   {'RecNo()', 'Name', 'Price'}
      JUSTIFY        {GRID_JTFY_RIGHT, GRID_JTFY_LEFT, GRID_JTFY_RIGHT}
    END GRID

    DEFINE BUTTON Exit_BU
      ROW      140
      COL      100
      WIDTH     80
      HEIGHT    25
      CAPTION 'Exit'
      ACTION   Main_WA.RELEASE
    END BUTTON
  
    DEFINE STATUSBAR
      STATUSITEM ''
      STATUSITEM '' WIDTH 200
    END STATUSBAR

    DEFINE TIMER Timer;
      INTERVAL 10;
      ACTION   UpdateStatus()

    ON KEY ESCAPE ACTION Main_WA.RELEASE

  END WINDOW

  Main_WA.Users_GR.RECNO := 1

  Main_WA.CENTER
  Main_WA.ACTIVATE

RETURN NIL

FUNCTION UpdateStatus()

  Main_WA.STATUSBAR.Item(1) := 'RecNo(): ' + LTrim(Str(RecNo()))
  Main_WA.STATUSBAR.Item(2) := 'Grid.RECNO: ' + LTrim(Str(Main_WA.Users_GR.RECNO))

RETURN NIL

FUNCTION OpenData()

  IF File('Comp.dbf')
    dbUseArea(NIL, NIL, 'Comp')
  ELSE
    dbCreate('Comp', {{'Name', 'C', 30, 0}, {'Price', 'N', 6, 2}})
    dbUseArea(NIL, NIL, 'Comp')

    dbAppend()
    Comp->Name  := 'Main board'
    Comp->Price := 120.34
    dbAppend()
    Comp->Name  := 'Processor'
    Comp->Price := 97.95
    dbAppend()
    Comp->Name  := 'RAM'
    Comp->Price := 204.58
    dbAppend()
    Comp->Name  := 'HDD'
    Comp->Price := 142.71
    dbAppend()
    Comp->Name  := 'SSD'
    Comp->Price := 316.94
    dbAppend()
    Comp->Name  := 'Graphics card'
    Comp->Price := 143.48
    dbAppend()
    Comp->Name  := 'Power supply'
    Comp->Price := 54.29
    dbAppend()
    Comp->Name  := 'PC case'
    Comp->Price := 72.85
  ENDIF

RETURN NIL

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Fri Oct 28, 2016 6:48 pm

Hi KDJ,

It's displaying at Status Item(1) := 'RecNo() according mouse's position at row/grid. IMHO this we would not considered as bug is correct indicating the right recno. Second item displaying according highlited cursor of grid navigator.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

KDJ
Posts: 178
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 190 times

Post by KDJ » Fri Oct 28, 2016 9:07 pm

Hi, Pablo

Thanks for your answer.

RecNo() is data base function, it returns current record number in data base.
I don't understand why moving mouse (without changing selection in Grid) causes changing record in data base.

In addition, it turns out that the record is changed, even when we do not use the mouse.
Try following test using keyboard only:
1. Move mouse cursor to any edge of desktop.
2. Run my example program (Enter).
Now RecNo() returns 1 and Grid.RECNO is 1.
3. Open window menu (Alt+Space) and select "Minimize". Window was minimized.
4. Restore window by using Alt+TAB.
Now RecNo() returns eg. 6 and Grid.RECNO is still 1.

User avatar
Pablo César
Posts: 4058
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil
Has thanked: 100 times
Been thanked: 177 times

Post by Pablo César » Fri Oct 28, 2016 9:33 pm

KDJ wrote:I don't understand why moving mouse (without changing selection in Grid) causes changing record in data base.
You're right Recno() should returns record number and here it is doing upto the moment when mouse is poiting any other row/record in the grid. This behaviour seems to obey to Grid Events when mouse is positioning.

Regarding your steps for testing: I make already and all seems good for me.

When change by keyboard arrors down/up and right and left Recno number are equal the same, but as you've indicated: with mouse's pointer out of form. When minimize and restored returns at the same recno number. for me returns at 4 (both status/items).

I'm testing under Win 7 32 bits with HMG 3.4.3

Probably Claudio can explain this behaviour if is working in accordingly.
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein

KDJ
Posts: 178
Joined: Mon Sep 05, 2016 3:04 am
Location: Poland
Been thanked: 190 times

Post by KDJ » Fri Oct 28, 2016 10:01 pm

This last test (without mouse) I have done on Win-XP. Result:
RecNo() --> 6 (6 is last visible item is Grid)
Grid.RECNO --> 1

Now I have tested on Win7. Result:
RecNo() --> 1
Grid.RECNO --> 1

It seems that the behavior depends on Windows version.

User avatar
srvet_claudio
Posts: 1953
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 31 times
Been thanked: 120 times
Contact:

Post by srvet_claudio » Fri Oct 28, 2016 10:09 pm

I will check.
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

Post Reply