Access Violation in multitier application

Posted by Olivier on October 09, 2001

Hello,

I am developing a multitier application, with a UI tier, a domain tier and a DB tier. I use record structures to store data between the database and the domain units. I then transfer the records data to an object in the domain in the constructor Create. This is apparently wrong, because i keep getting an access violation. Please look at the code below, and post an answer (or mail me) as soon as possible, because time is a major issue!!!

Thanks in advance,
Olivier

-----------code-------------

unit Main;
// interface and more
procedure THovedV.Button1Click(Sender: TObject);
var p1 : TPoint;
begin
  p1.Create(StrToInt(Edit1.text));
  Label1.Caption := IntToStr(p1.GetValue);
  p1.destroy;
end;
-------
unit PointU;
interface
uses Main;
type TPoint = class
private
  Point_id : integer;
  Value    : integer;
public
  constructor create(P_id : integer);
  destructor destroy; override;
end;
implementation
uses DBPointU, SysUtils;
constructor TPoint.Create(P_id: integer);
var PointRec : TPointRec;
begin
  inherited Create;
  DBGetPoint(P_id, PointRec);
  Point_id := PointRec.Point_id;
  Value    := PointRec.Value;
end;
destructor TPoint.destroy;
var PointRec : TPointRec;
begin
  PointRec.Po_id := Point_id;
  PointRec.Value := Value;
  DBUpdatePoint(PointRec);
  inherited destroy;
end;
----------------
unit DBPointU;
interface
type TPointRec = Record
   Point_id : integer;
   Value    : integer;
   end;
function DBGetPoint(P_id : integer; VAR Po_id, Value : 
                    Integer) : Boolean;
procedure DBUpdatePoint(Po_id, Value: integer);
implementation
uses SysUtils, DBTables, Main;
function DBGetPoint(P_id : integer; VAR Po_id, Value : 
                    Integer) : Boolean;
begin
  with Main.HovedV.IBQuery do begin
    // get the data of the specified point
    Close;
    SQL.Clear;
    SQL.Add('SELECT * FROM Point WHERE point_id 
             = :P_id');
    Prepare;
    Params[0].AsInteger := P_id;
    Open;
    if RecordCount > 0 then begin
      // transfer the dataset to the record
      Po_id := FieldValues['point_id'];
      Value := FieldValues['value'];
    end;
    DBGetPoint := RecordCount > 0;
  end; // with
end;   // DBGetPoint
procedure DBUpdatePoint(Po_id, Value : integer);
begin
  with Main.HovedV.IBQuery do begin
    Close;
    SQL.Clear;
    SQL.Add('SELECT point_id FROM Point WHERE point_id 
             = :Pt_id');
    Prepare;
    Params[0].AsInteger := Po_id;
    Open;
    if RecordCount > 0 then begin
      FieldValues['point_id'] := Po_id;
      FieldValues['value']    := Value;
    end;
  end; // with
end;   // DBUpdatePoint
end.

----
thanks for hanging on :) !!!


Related Articles and Replies


[ DelphiLand FAQ ] [ Delphi Tutorials ]