类:
unit CDSDBCtrl;
interface
uses
ADODB;
type
TCDSDBCtrl = Class
private
Conn : TADOConnection; //定义两个类变量。
StoProc : TADOStoredProc;
public
constructor Create(DBType : Smallint; AOwner : TComponent); //构造函数。
Destructor Destroy(); override; //析构函数。
constructor TCDSDBCtrl.Create(DBType : Smallint; AOwner : TComponent);
var
IniFile : TIniFile;
begin
Conn := TADOConnection.Create(AOwner);
StoProc := TADOStoredProc.Create(AOwner);
end;destructor TCDSDBCtrl.Destroy;
begin
Conn.Free;
StoProc.Free;
inherited;
end;过程调用:
procedure TForm1.Button2Click(Sender: TObject);
var
DBConn : TCDSDBCtrl;
begin
DBConn.Create(0,Self);
DBConn.ConnectDB;
DBConn.DBExecute('delete from downinfo where id =11');
DBConn.Free; //这里出现内存错误,请各位指点。
end;另一种情况:
DBConn : TCDSDBCtrl; //在一个窗体中声鸣全局变量
procedure TForm1.FormShow(Sender: TObject);
begin
DBConn.Create(0,Self); //直接报内存错误。????????
end;
unit CDSDBCtrl;
interface
uses
ADODB;
type
TCDSDBCtrl = Class
private
Conn : TADOConnection; //定义两个类变量。
StoProc : TADOStoredProc;
public
constructor Create(DBType : Smallint; AOwner : TComponent); //构造函数。
Destructor Destroy(); override; //析构函数。
constructor TCDSDBCtrl.Create(DBType : Smallint; AOwner : TComponent);
var
IniFile : TIniFile;
begin
Conn := TADOConnection.Create(AOwner);
StoProc := TADOStoredProc.Create(AOwner);
end;destructor TCDSDBCtrl.Destroy;
begin
Conn.Free;
StoProc.Free;
inherited;
end;过程调用:
procedure TForm1.Button2Click(Sender: TObject);
var
DBConn : TCDSDBCtrl;
begin
DBConn.Create(0,Self);
DBConn.ConnectDB;
DBConn.DBExecute('delete from downinfo where id =11');
DBConn.Free; //这里出现内存错误,请各位指点。
end;另一种情况:
DBConn : TCDSDBCtrl; //在一个窗体中声鸣全局变量
procedure TForm1.FormShow(Sender: TObject);
begin
DBConn.Create(0,Self); //直接报内存错误。????????
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货