Hello list!

I would like to define a class, Tklasje, of my own which contains a
database in the private section. Using this class I want to access the
database. (another Lazarus-application could succesfully show this
database, so I assume the database is OK).

The class is defined in unit2 and used in unit1 (see below). When
running this little program I see the TEdit change to "gecreeerd" but
then I get an error message: "acces violation". This doesn't change when
I change the DoeIets procedure of the Tklasje class into something
different like:

procedure Tklasje.DoeIets;
begin
  d_database.First;
end;

What do I do wrong? Can anyone help me find a solution?

With kind regards,

Paul van der Vlis.


----------------------------------------------
unit unit2;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, sqlite3ds, DbCtrls, sqldb, db;

type
  Tklasje = class

  private
    d_database : TSqlite3Dataset;

  public
    constructor Create;
    destructor Destroy; override;
    procedure DoeIets;
end;

implementation

constructor Tklasje.Create;
begin
  d_database := TSqlite3Dataset.Create(nil);
  try
    with d_database do
      begin
        if Active then Close;
        FileName := 'sqlite3filenaam';
        TableName := 'tabelnaam';
        Open;
      end;
  except
    d_database.Free;
    d_database := nil;
  end;
end;

destructor Tklasje.Destroy;
begin
  d_database.Free;
  d_database := nil;
  Inherited;
end;

procedure Tklasje.DoeIets;
begin
  d_database.Active := true;
end;

initialization

end.

----------------------------------------------
unit unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, unit2, StdCtrls;

type

  { TSchermpje }

  TSchermpje = class(TForm)
    status: TEdit;
    procedure statusClick(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  MijnSchermpje: TSchermpje;

implementation

procedure TSchermpje.statusClick(Sender: TObject);
var
  MijnKlasje : TKlasje;
begin
  status.Text := 'creeren';
  MijnKlasje.Create;
  status.Text := 'gecreeerd';
  MijnKlasje.DoeIets;
  status.Text := 'gedaan';
  MijnKlasje.Destroy;
  status.Text := 'klaar';
end;

initialization
  {$I unit1.lrs}

end.

----------------------------------------------





Met vriendelijke groet,
Paul van der Vlis.




-- 
http://www.vandervlis.nl/

_______________________________________________
Lazarus mailing list
[email protected]
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to