Recent

Author Topic: DBGrid exit  (Read 10018 times)

iru

  • Sr. Member
  • ****
  • Posts: 300
DBGrid exit
« on: April 20, 2010, 01:43:59 am »
Gentlefolk,

Using Laz 0.9.28, ZEOS 6.6.6, Windows XP SP3.

I have a DBGrid>DataSource>ZQuery structure. All works Ok, data displays nicely, etc.

I wish to detect when control/focus leaves the DBGrid.

It would appear that the event "OnExit" occurs when

  1 Assign focus to DBGrid, set dataSet to "First", set SlectedIndex to the required colum.
  Click on the highlighted cell.

  2 Enter data in a cell, press enter. AutoIncrement is set to aaDown. Data is displayed in correct cell.
  The cell "down one row" is highlighted.
  On the first character entered in that cell the OnExit occurs.

  3 When the DBgrid loses focus by clicking on some other object on the form.

From delphi and some lazarus documentation only 3 (loss of focus) should cause an OnExit.

Any ideas, comments, ?????

Ian

iru

  • Sr. Member
  • ****
  • Posts: 300
Re: DBGrid exit
« Reply #1 on: April 26, 2010, 11:10:27 am »
Gentlefolk,

Some more research on this one.....

I fixed one aspect of this problem by adding dataset.disable control and dataset.enablecontrol around some code that appended some rows to the dataset.

The main issue of "OnExit" being executed on the initial click on the DBGrid, on the first character input after an <enter> (in new row)and on clicking on some other object on the form (expected behaviour) remains......

Looking at the stack trace when stopped on a breakpoint in OnExit it appears that in all cases the path through the code is the same, few if any decisions made, generally "inherited DoExit" and then wind up in "onexit".

So I chase on (slowly), any thoughts, suggestions, etc appreciated.

Ian

iru

  • Sr. Member
  • ****
  • Posts: 300
Re: DBGrid exit
« Reply #2 on: April 27, 2010, 12:02:20 am »
Gentlefolk,

More on this one.
Created a  simple test environment, one form, ZConnection, ZQuery, DataSource, DBGrid and one Button. Same database.
Columns, fields configured, all OK.

Empty database.
One event "onExit" on the DBGrid. Debug breakpoint stop here.

Start program, form displayed, one row displayed in DBgrid, first cell highlighted.

Click on highlighted cell, stop on OnExit debug.

Click on non-highlighted cell, cell is highlighted, second click on highlighted cell - stop on OnExit debug.

Enter some data into cell (no enter, cell not highlighted), click on button - no stop on DBGrid OnExit debug.

Enter <enter> (cell highlighted), click on button - stop on  DBGrid exit.

You cannot get it any simpler, the only code I have written is the debug code in the Onexit event, one line saving a field to a string variable.

So:
  Why do I take an OnExit when entering the DBgrid????

  Why do I not take an exit when in a non-highlighted cell
    l and change focus to the button????
   Why (just noticed) does the DBGrid.AutoAdvance "aadown"
   not work (worked in original program)????

Perplexed, does not seem logical and is impacting my project.

The following is an edited stack trace obtained when clicking on a empty DBGrid immediatley after loading the program:

Empty database, start program, click on highlighted cell in dbgrid

#0 TFORM1__DBGRID1EXIT(0x2e7f9a8, 0x2e7f548) at unit1.pas:42
#1 TWINCONTROL__DOEXIT(0x2e7f9a8) at wincontrol.inc:6091
#2 TCUSTOMGRID__DOEXIT(0x2e7f9a8) at grids.pas:5500
#3 TCUSTOMDBGRID__DOEXIT(0x2e7f9a8) at dbgrids.pas:2350
#4 TWINCONTROL__WMKILLFOCUS() at wincontrol.inc:6203
#5 TCUSTOMGRID__WMKILLFOCUS() at grids.pas:3795
#6 SYSTEM_TOBJECT_$__DISPATCH$formal at :0
#7 NEXTROWHEIGHT(43972080, 48757160, 0x0) at grids.pas:3695
#8 TWINCONTROL__WNDPROC() at wincontrol.inc:4920
#9 TCUSTOMGRID__WNDPROC() at grids.pas:3850
#10 TCUSTOMDBGRID__WNDPROC() at dbgrids.pas:1211
#11 DELIVERMESSAGE(0x2e7f9a8, void) at lclmessageglue.pas:111
#12 WINDOWPROC(1311154, 8, 1704596, 0) at win32callback.inc:2574
#13 USER32!GetDC at :0
#14 ?? at :0
#15 ?? at :0
#16 ?? at :0
#17 ?? at :0

Ian








iru

  • Sr. Member
  • ****
  • Posts: 300
Re: DBGrid exit
« Reply #3 on: April 30, 2010, 11:30:42 pm »
Gentlefolk,

I have revisited this one, even stranger than I thought.....

Simple one form program, dbgrid, datasource, zconnection, zquery and a single tbutton.

Within the IDE start the program with a breakpoint on the DBGrid.OnExit.

Do only one thing - click on the button.

Program stops in the DBGrid.OnExit. Stack trace shows path through "dbgrid" code as shown in the previous post.

Remove the breakpoint on DBGrid. Add a breakpoint on the Button.OnClick.

Within the IDE start the program, do only one thing - click on the button.

Program stops - Nothing in the stack trace about grids, all about Buttons.

Hmmmm, Remove breakpoint from DBGrid.OnExit, insert some code to simply set a global flag if the program passes through DBGrid.OnExit.

Within the IDE start the program, do only one thing - click on the button. Stop on breakpoint in button.onclick.

The "I have been through the DBGrid.OnExit code is SET. Nothing in the stack trace about grids.....

An edited stack trace follows:

This "OnExit" problem does not look good, any help, suggestions???

Ian

#0 TFORM1__BUTTON1CLICK(0x2e71358, 0x2e7f548) at unit1.pas:48
#1 TCONTROL__CLICK(0x2e71358) at control.inc:2227
#2 TBUTTONCONTROL__CLICK(0x2e71358) at buttoncontrol.inc:72
#3 TCUSTOMBUTTON__CLICK(0x2e71358) at buttons.inc:164
#4 TBUTTON__CLICK(0x2e71358) at buttons.inc:331
#5 TBUTTONCONTROL__WMDEFAULTCLICKED({MSG =) at buttoncontrol.inc:26
#6 SYSTEM_TOBJECT_$__DISPATCH$formal at :0
#7 TBUTTONCONTROL__ISCHECKEDSTORED(0x29ef758) at buttoncontrol.inc:22
#8 TWINCONTROL__WNDPROC({MSG = ) at wincontrol.inc:4920
#9 DELIVERMESSAGE(0x2e71358, void) at lclmessageglue.pas:111
#10 WINDOWPROC(5177782, 273, 4952, 3736160) at win32callback.inc:2574
#11 USER32!GetDC at :0
#12 TTOOLBUTTON__CALCULATEPREFERREDSIZE(-2115663531, 0, true (16), 0x0) at toolbutton.inc:929
#13 USER32!GetDC at :0
#14 GETNEEDPARENTPAINT(0x0, 0x7e418830) at win32callback.inc:205
#15 USER32!GetParent at :0
#16 ?? at :0



iru

  • Sr. Member
  • ****
  • Posts: 300
Re: DBGrid exit
« Reply #4 on: May 01, 2010, 07:49:09 am »
Gentlefolk.

A little more progress?

Load the program, click on button, stop on breakpoint in the DBGrid.NoExit code.

Continue the program, stop on the Button.Click breakpoint.

Continue the program, form displayed.

Click on button, stop on the Button.Click breakpoint.

The DBGrid.NoExit is only taken once, immediatley after the program is loaded.

Ian






iru

  • Sr. Member
  • ****
  • Posts: 300
Re: DBGrid exit
« Reply #5 on: May 01, 2010, 08:24:02 am »
Gentlefolk,

The cause of the program going through the DBGrid.OnExit when clicking on a button immediatley after the form is displayed is simple.

When the form is created/loaded the DBGrid gets the focus! By chance/creation order in the test program, because I specifically set the DBGrid with the focus in my project.

Clicking on the button changed the focus, hence the DBGrid.OnExit.

Need to think about things.

The end, Ian

 

TinyPortal © 2005-2018