Page 1 of 1
how to prevent
Posted: Tue 27 Apr 2010 23:12
by ccmcbride
Autorefresh from occuring WHILE I am editing/inserting the record?
I've been trying for awhile to get the autorefresh working correctly, but while in the middle of filling out a form to insert the data, autorefresh timer hits, record is autorefreshed (and therefor, posted), and program blows up, as dataset is no longer in edit mode.
using
SDAC version 4.80.0.55
Posted: Wed 28 Apr 2010 08:18
by Dimon
To solve the problem you should disable auto refreshing in the BeforeEdit and BeforeInsert event handlers, and enable it in the AfterPost and AfterCancel event handlers, like this:
Code: Select all
procedure TForm1.MSQueryBeforeEdit(DataSet: TDataSet);
begin
MSQuery.Options.AutoRefresh := False;
end;
procedure TForm1.MSQueryAfterPost(DataSet: TDataSet);
begin
MSQuery.Options.AutoRefresh := True;
end;
Posted: Wed 28 Apr 2010 16:57
by ccmcbride
Can I make a feature request that it get added to the table components?
Much easier if I set a flag in the logic to set the option, instead of writing code for 2 events and attempting to attach to all the tables.
Posted: Thu 29 Apr 2010 11:42
by Dimon
Please describe the case, when edited record is posted because of autorefresh is executed, in more details. If you edit/insert record in the main thread, such situation cannot occur.
Posted: Thu 29 Apr 2010 16:32
by ccmcbride
But it is occurring.
I have a main form and a detail form. The tables are on separate connections, many tables are open.
If I'm not quick enough when filling the detail form, the record gets posted before I tell it to post.
I have already assigned a 'beforeinsert' procedure to turn the autorefresh off in the 'beforeinsert', 'beforeedit', but it is still happening. I know this because all my tables are opened in a procedure, and part of that procedure sets up the table options.
I am using Devexpress controls almost exclusively, and don't know if that's causing the problem or not, but I can't find any flag that says 'seriously, don't allow a refresh to occur if the dataset is in edit/insert mode. Ever. Even if you are told to.'....
Easy enough to replicate - call dataset.refresh when in edit/insert mode.
All I did was create my form, make the call to do an insert on the table, and leave the form hanging there for 60 seconds:
I don't know WHY it's happening. Maybe because the master table is not in edit mode, and therefore, is being auto-refreshed... Just know that it's causing the table that is in insert mode to go get posted.
Call stack shows:
dbmain.TdmMain.tblOrderMatBeforePost($5357E20)
:004ec39b TDataSet.DoBeforePost + $1B
:004e5c36 TDataSource.NotifyDataLinks + $16
:004f3009 TMemDataSet.DataEvent + $25
:004ec030 TDataSet.CheckBrowseMode + $1C
:005048de TCustomDADataSet.InternalRefreshQuick + $26
:004d18f6 TWin32Timer.Timer + $12
:7e418734 USER32.GetDC + 0x6d
:7e418816 ; C:\WINDOWS\system32\USER32.dll
:7e4189cd ; C:\WINDOWS\system32\USER32.dll
:7e4196c7 USER32.DispatchMessageA + 0xf
Posted: Fri 30 Apr 2010 12:17
by Dimon
Thank you for information. We have reproduced this problem and fixed it. This fix will be included in the next SDAC build.