Jump to content
Bill Meyer

FDMemTable - exception on EmptyDataset

Recommended Posts

Posted (edited)

I am using an FDMemTable in a very simple application. I am using Alexandria, but I get the same error in Sydney. I need to ensure before loading that the dataset is empty, so, I do this:

function TdMain.ProcessFileList(const FileList: TStrings): Integer;
var
  fn: TmdFileName;
  s: string;
  sld: TStringList;
begin
  if not fdmAllFiles.Active then
    fdmAllFiles.CreateDataSet
  else
  begin
    fdmAllFiles.Open;
    fdmAllFiles.EmptyDataset; // throws exception
  end;

The FDMemTable is static on the data module, and the fields are created at design time. When I call this routine a second time, the dataset has records, and so I ensure it is open, and call EmptyDataset. I then get this error:

image.thumb.png.e0d6a8a6c0955da010d32d1c86c50203.png

I have tried getting a bookmark before the call, and it makes no difference. Interestingly, I have found no examples of using EmptyDataset in my searching.

Edited by Bill Meyer

Share this post


Link to post

I cannot reproduce this in a simple test program. What I did is placed a TFDMemTable into a form:

 

  object FDMemTable1: TFDMemTable
    FetchOptions.AssignedValues = [evMode]
    FetchOptions.Mode = fmAll
    ResourceOptions.AssignedValues = [rvSilentMode]
    ResourceOptions.SilentMode = True
    UpdateOptions.AssignedValues = [uvCheckRequired, uvAutoCommitUpdates]
    UpdateOptions.CheckRequired = False
    UpdateOptions.AutoCommitUpdates = True
    Left = 304
    Top = 224
    object FDMemTable1a: TIntegerField
      FieldName = 'a'
    end
    object FDMemTable1b: TStringField
      FieldName = 'b'
      Size = 150
    end
  end
 

and a button with the following onclick event:

 

procedure TForm1.Button1Click(Sender: TObject);
begin
  if not FDMemTable1.Active then
    FDMemTable1.CreateDataSet
  else
  begin
//    FDMemTable1.Open; <- There is no need to do this Active is true
    FDMemTable1.EmptyDataSet;
  end;

  FDMemTable1.Append;
  FDMemTable1['a']:=1;
  FDMemTable1['b']:='1';
  FDMemTable1.Append;
  FDMemTable1['a']:=2;
  FDMemTable1['b']:='2';
  FDMemTable1.Append;
  FDMemTable1['a']:=3;
  FDMemTable1['b']:='3';
  FDMemTable1.Append;
  FDMemTable1['a']:=4;
  FDMemTable1['b']:='4';
  FDMemTable1.Post;
end;

It's working with multiple clicks.

Share this post


Link to post

Thanks for your efforts. I went to the smallest possible test program, and I get no error. As to the cause of the problem in the program where I first saw it, I am at a loss. Will come back to it later, and see whether I am able to isolate a cause.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×