0

I have a multiple tabsheet. Each tabsheet in my PageControl that contain an Dbgrid with some button to manipulate this dbgrid.

Sometimes, when i click on button remove, my DBGrid not change. After delete, i see my value in my DBgrid.

If MyTable.recordcount > 0 then
begin
 str := 'Value of name field/**' + MyTable.FieldByName('Name').AsString+'**/';
 If Application.MessageBox(PChar(str), PChar('NAME'), MB_OKCANCEL + MB_ICONQUESTION) = IDOK then
 begin
      MyTable.Delete;
 end;
end;

I try to add

 MyTable.Refresh;

after delete but it doesn't work. The value of myfield in the MessageBox is correct!

This problem appear when i select another Tabsheet in MyDBgrid. It can be problem of focus in my DBGrid? It can be problem of state of my DBGrid(dsBrowser, dsEdit,...)?

=========================================================

I try to create a log for BeforeDelete event and AfterDelete event :

Log(1,'------------------------------------Before Del');
Log(1,Format('DataSet.IsEmpty:%s',[BoolToStr1(DataSet.IsEmpty)]));
Log(1,Format('DataSet.State:%d',[Ord(DataSet.State)]));
Log(1,'--------');
Log(1,Format('DataSet.RecNo:%d',[DataSet.RecNo]));
Log(1,Format('DataSet.TabSheet:%s',[DataSet.FieldByName('TabSheetName').AsString]));
Log(1,Format('DataSet.FieldName:%s',[DataSet.FieldByName('FieldName').AsString]));
Log(1,Format('DataSet.FieldId:%s',[DataSet.FieldByName('FieldId').AsString])); 

on AfterDelete event :

Log(1,'------------------------------------After Del');
Log(1,Format('DataSet.IsEmpty:%s',[BoolToStr1(DataSet.IsEmpty)]));
Log(1,Format('DataSet.State:%d',[Ord(DataSet.State)]));
Log(1,'--------');
Log(1,Format('DataSet.RecNo:%d',[DataSet.RecNo]));
Log(1,Format('DataSet.TabSheet:%s',[DataSet.FieldByName('TabSheetName').AsString]));
Log(1,Format('DataSet.FieldName:%s',[DataSet.FieldByName('FieldName').AsString]));
Log(1,Format('DataSet.FieldId:%s',[DataSet.FieldByName('FieldId').AsString])); 

I use the tabsheet as :

enter image description here

I obtain this log

------------------------------------Before Del
DataSet.IsEmpty:False
DataSet.State:1
--------
DataSet.RecNo:7
DataSet.TabSheet:tabsheet_0
DataSet.FieldName:
DataSet.FieldId:03
------------------------------------After Del
DataSet.IsEmpty:False
DataSet.State:1
--------
DataSet.RecNo:6
DataSet.TabSheet:tabsheet_0
DataSet.FieldName:
DataSet.FieldId:03

You can see in my log: the dataset not change (filedname and fieldId not change / the RecNo properties is change ) after delete the row that contain 03.

userPro
  • 59
  • 4
  • 12
  • Sorry, I really don't think your q adequately describes your problem. a) Re your screenshot, why are you talking about a tabsheet when what it shows is just part of a DBGrid? b) Why is the LH data column in the DBGrid blank in the selected row? c) And the log you show: is that for a case when RecNo 6 gets successfully deleted? If so, I can't see the point of showing us that - better would be the log for when the record doesn't get deleted. d) Is the dataset being used to record attributes of the form the DBGrid is embedded in or what? Iow, your q gives no clear idea of what you're doing. – MartynA Aug 24 '16 at 16:04
  • Btw, I think that if you want help with this, you're going to have to include an MCVE in your q - see http://stackoverflow.com/help/mcve – MartynA Aug 24 '16 at 16:11
  • @MartynA thank you for help... I try to be clear.. A> I talk about tabsheet because i can reproduce the error when i change my current tabsheet and directly go to remove a row in the new tabsheet selected.. in this case, the delete not perform correctly... B> this cell is empty .. i don't put anything in this cell .... C> you can see a RecNo=6 but the fieldname and the fieldId not changed and my DBgrid interface not changed... D> MyDbgrid is added when i create a new tabsheet ((when i add new tabsheet, i instanciate a class that contain DBGrid, all button )) – userPro Aug 24 '16 at 16:38

1 Answers1

0

Since your problem is intermittent, you'll have to debug it yourself, because readers can't do that for you.

The first thing to do is to set up a logging function and call it in the dataset's BeforeDelete and AfterDelete events. You should record in it the identity of the current dataset row, the dataset's state (dsBrowse, dsEdit, etc) and anything other you think might be relevant (e.g. the identity of the active tabsheet) and see if you can spot in what circumstances the Delete fails. You could write the results of your logging calls to a TMemo on your form.

Ime, it's good practice only to allow a Delete if the dataset is in dsBrowse state.

By the way, I assume you are aware that a Delete operation is automatically aborted if the dataset is in dsInsert or dsSetKey state? From what you've described, I'd start debugging by investigating whether it's in dsInsert state when your problem arises. Of course, you can catch when the dataset is being put into dsInsert state by catching its BeforeInsert event and calling your logging function from there.

MartynA
  • 30,454
  • 4
  • 32
  • 73