Forum > LCL

DBGrid exit

(1/2) > >>


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, ?????



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.



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.

  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
#2 TCUSTOMGRID__DOEXIT(0x2e7f9a8) at grids.pas:5500
#3 TCUSTOMDBGRID__DOEXIT(0x2e7f9a8) at dbgrids.pas:2350
#5 TCUSTOMGRID__WMKILLFOCUS() at grids.pas:3795
#6 SYSTEM_TOBJECT_$__DISPATCH$formal at :0
#7 NEXTROWHEIGHT(43972080, 48757160, 0x0) at grids.pas:3695
#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
#13 USER32!GetDC at :0
#14 ?? at :0
#15 ?? at :0
#16 ?? at :0
#17 ?? at :0



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???


#0 TFORM1__BUTTON1CLICK(0x2e71358, 0x2e7f548) at unit1.pas:48
#1 TCONTROL__CLICK(0x2e71358) at
#2 TBUTTONCONTROL__CLICK(0x2e71358) at
#3 TCUSTOMBUTTON__CLICK(0x2e71358) at
#4 TBUTTON__CLICK(0x2e71358) at
#6 SYSTEM_TOBJECT_$__DISPATCH$formal at :0
#9 DELIVERMESSAGE(0x2e71358, void) at lclmessageglue.pas:111
#10 WINDOWPROC(5177782, 273, 4952, 3736160) at
#11 USER32!GetDC at :0
#12 TTOOLBUTTON__CALCULATEPREFERREDSIZE(-2115663531, 0, true (16), 0x0) at
#13 USER32!GetDC at :0
#14 GETNEEDPARENTPAINT(0x0, 0x7e418830) at
#15 USER32!GetParent at :0
#16 ?? at :0


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.



[0] Message Index

[#] Next page

Go to full version