0

I have a table that I have set up as a pointer to be used by another form.

There is a procedure on this form where using a For Loop I create new records in the table if the GUID does not already exist.

With Table^ do
for I := 0 to Results.result.RowCount - 1 do
begin
  IndexName := 'GUID';
  SetKey;
  FieldByName('GUID').AsString := Results.UserDetail[I].Guid;
  if not Gotokey then
  begin
    Insert;
    etc..
  end;


Most of the time it works just fine.. However there is are some scenarios where when it tries to set the key, instead of the table state going from dsBrowse to dsSetKey it stays at dsBrowse and consequently I get a "table not in edit mode error"

One case where this happens it iterates through the forloop like 10 times and works smoothly but then on the 11 time it fails to change the table to setkey mode..

Do you have any ideas what might be going on with the table or why a table would stay in browse mode after calling SetKey?

Thanks

Update-

I also ran into a similar situation with SetRangeStart not changing the state but staying in browse mode. I even got rid of all the change events on the table and traced into the SetRangeStart to make sure no other code was run and it still didn't change the state.

This same code works fine using most data sets. So I believe it might be data related.. Any Ideas?

Trevor
  • 16,080
  • 9
  • 52
  • 83
  • `SetKey` can triggers events on the Table, so, are you sure you don't have any event on the Table like an `OnDataChange` that could have a side effect of changing the state back to `dsBrowse`? – Francesca Nov 09 '12 at 18:44
  • I just verified with some breakpoints and did not get SetKey to trigger any of my events. – Trevor Nov 09 '12 at 21:35
  • 1
    @Trevor This doesn't answer your question but, why are you using SetKey to locate a record, you have better methods, like FindKey and Locate to do such a thing. On the other hand, every time I've seen a state change fail in Delphi it was due to user code in events. Are you sure your events aren't being executed? Is the DataSet associated with visual controls? What class is Table? – jachguate Nov 10 '12 at 01:03
  • Well events are being executed however I can't track down code execution differences between the cases that work and the case that errors out. Though it could be something and I'm just capable of tracking it down. Thanks I'll consider trying FindKey or Locate to see if averts the error.. Thanks – Trevor Nov 12 '12 at 17:48

1 Answers1

0

I found that when running into this issue If I DisabledControls on the table while working with it and then EnabledControls after it solved the problem.

Table.DisableControls;
....
Table.EnableControls;
Trevor
  • 16,080
  • 9
  • 52
  • 83