[fpc-devel] TBufDataSet Stream Error

Dimitrios Chr. Ioannidis dioannidis at artesoft.gr
Tue Jul 21 23:54:07 CEST 2009


Hi,
 
  i'm trying to use TBufDataset as a very simple mem dataset but i get a
"Stream read error". 

  I can reproduce it, but first is it legitimate to use TBufDataset like
this ?


unit Unit2; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, db, FileUtil, LResources, Forms, Controls, Dialogs,
bufdataset;

type

  { TDataModule1 }

  TDataModule1 = class(TDataModule)
    Datasource1: TDatasource;
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    { private declarations }
    FTest: TBufDataset;
    procedure CreateDB;
  public
    { public declarations }
  end; 

var
  DataModule1: TDataModule1; 

implementation

{ TDataModule1 }

var
  sDBFileName: string;

procedure TDataModule1.DataModuleCreate(Sender: TObject);
begin
  FTest := TBufDataset.Create(Self);
  if not FileExists(sDBFileName) then
    CreateDB
  else
    FTest.LoadFromFile(sDBFileName);
  DataSource1.DataSet := FTest;
  FTest.Open;
end;

procedure TDataModule1.DataModuleDestroy(Sender: TObject);
begin
  if FTest.State in [dsEdit, dsInsert] then
    FTest.Post;
  FTest.SaveToFile(sDBFileName);
end;

procedure TDataModule1.CreateDB;
begin
  FTest.FieldDefs.Add('ID', ftInteger, 0, False);
  FTest.FieldDefs.Add('FirstName', ftString, 20, False);
  FTest.FieldDefs.Add('LastName', ftString, 20, False);
  FTest.CreateDataset;
end;

initialization
  {$I unit2.lrs}
  sDBFileName := ExtractFilePath(Application.ExeName) + 'TestDB.db';

end.                                                   




More information about the fpc-devel mailing list