Question

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?

Was it helpful?

Solution

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top