J
jbas
Unregistered / Unconfirmed
GUEST, unregistred user!
我想实现自己写一个类来操作数据的读写。下面是那个类:
但我在程序中这样写却总是出现00000000内存读写错误。
procedure TForm1.Button1Click(Sender: TObject);
var
te:TDbDo;
begin
te:=TDbDo.Create;
te.SQL.Add('sdf');
te.Free;
end;
------------------------------
unit MyDbClass;
interface
uses Controls,ADODB,Classes;
Type
TDbType=record
Arrrq:TDate
//录入日期.
Azgxm:string
//职工姓名.
Azgbh:string
//职工编号.
Assbmmc:string
//所属部门名称.
Assbmbh:string
//所属部门编号.
Ajbgz:currency
//基本工资.
Agl:integer
//工龄.
Aglgz:currency
//工龄工资.
Aylbx:currency
//扣养老保险金.
Afdgz:currency
//浮动工资.
Azfgjj:currency
//住房公积金.
Ajj:currency
//奖金.
Ajbf:currency
//加班费.
Aqqts:integer
//缺勤天数.
Aqqkk:currency
//缺勤扣款.
Azwgz:currency
//职务工资.
Asds:currency
//所得税.
Akkhj:currency
//扣款合计.
Asfhj:currency
//实发合计.
Akcjs:currency
//扣除基数.
Asl:single
//税率%.
Asskcs:currency
//速算扣除数.
Asfdsje:currency
//实发到手金额.
end;
TDbDo=class
private
FDbInfo:TDbType;
FConnectionString: WideString;
FADOQueryDbClass:TADOQuery;
FSQL:TStrings;
FADOConnection:TADOConnection;
function GetSql:TStrings;
procedure SetSql(const Value:TStrings);
procedure SetConnStr(AConnStr:WideString);
protected
public
constructor Create;
destructor Destroy
override;
procedure calc;
published
property ConnectionStr:WideString read FConnectionString write SetConnStr;
property SQL:TStrings read GetSql write SetSql;
end;
implementation
{ TDbDo }
procedure TDbDo.calc;
begin
FADOQueryDbClass.SQL.Assign(SQL);
try
FADOQueryDbClass.Open;
except
FADOQueryDbClass.execsql;
end;
end;
constructor TDbDo.Create;
begin
inherited Create;
FADOConnection:=TADOConnection.Create(nil);
FADOQueryDbClass:=TADOQuery.Create(nil);
FADOQueryDbClass.Connection:=FADOConnection;
end;
destructor TDbDo.Destroy;
begin
FADOConnection.Free;
FADOQueryDbClass.Free;
inherited;
end;
function TDbDo.GetSql: TStrings;
begin
result:=FSQL;
end;
procedure TDbDo.SetConnStr(AConnStr: WideString);
begin
if FConnectionString<>AConnStr then
FConnectionString:=AConnStr;
end;
procedure TDbDo.SetSql(const Value: TStrings);
begin
FSQL.Assign(Value);
end;
end.
但我在程序中这样写却总是出现00000000内存读写错误。
procedure TForm1.Button1Click(Sender: TObject);
var
te:TDbDo;
begin
te:=TDbDo.Create;
te.SQL.Add('sdf');
te.Free;
end;
------------------------------
unit MyDbClass;
interface
uses Controls,ADODB,Classes;
Type
TDbType=record
Arrrq:TDate
//录入日期.
Azgxm:string
//职工姓名.
Azgbh:string
//职工编号.
Assbmmc:string
//所属部门名称.
Assbmbh:string
//所属部门编号.
Ajbgz:currency
//基本工资.
Agl:integer
//工龄.
Aglgz:currency
//工龄工资.
Aylbx:currency
//扣养老保险金.
Afdgz:currency
//浮动工资.
Azfgjj:currency
//住房公积金.
Ajj:currency
//奖金.
Ajbf:currency
//加班费.
Aqqts:integer
//缺勤天数.
Aqqkk:currency
//缺勤扣款.
Azwgz:currency
//职务工资.
Asds:currency
//所得税.
Akkhj:currency
//扣款合计.
Asfhj:currency
//实发合计.
Akcjs:currency
//扣除基数.
Asl:single
//税率%.
Asskcs:currency
//速算扣除数.
Asfdsje:currency
//实发到手金额.
end;
TDbDo=class
private
FDbInfo:TDbType;
FConnectionString: WideString;
FADOQueryDbClass:TADOQuery;
FSQL:TStrings;
FADOConnection:TADOConnection;
function GetSql:TStrings;
procedure SetSql(const Value:TStrings);
procedure SetConnStr(AConnStr:WideString);
protected
public
constructor Create;
destructor Destroy
override;
procedure calc;
published
property ConnectionStr:WideString read FConnectionString write SetConnStr;
property SQL:TStrings read GetSql write SetSql;
end;
implementation
{ TDbDo }
procedure TDbDo.calc;
begin
FADOQueryDbClass.SQL.Assign(SQL);
try
FADOQueryDbClass.Open;
except
FADOQueryDbClass.execsql;
end;
end;
constructor TDbDo.Create;
begin
inherited Create;
FADOConnection:=TADOConnection.Create(nil);
FADOQueryDbClass:=TADOQuery.Create(nil);
FADOQueryDbClass.Connection:=FADOConnection;
end;
destructor TDbDo.Destroy;
begin
FADOConnection.Free;
FADOQueryDbClass.Free;
inherited;
end;
function TDbDo.GetSql: TStrings;
begin
result:=FSQL;
end;
procedure TDbDo.SetConnStr(AConnStr: WideString);
begin
if FConnectionString<>AConnStr then
FConnectionString:=AConnStr;
end;
procedure TDbDo.SetSql(const Value: TStrings);
begin
FSQL.Assign(Value);
end;
end.