类方法 stackoverflow

sgpxd 2007-03-16 08:51:34
请问:
我声明了一个类,其中有对数据库的添加,删除,修改等方法。

在程序中,调用删除运行正常,调用添加和删除后,程序就死了,delphi的cpu占用率变高了。

把这两个方法的实现部分注释掉,提示stack overflow

类声明如下 //添加部分有2个子过程,
type
//员工
TEmployee = class (TObject)
private
Fid : Integer; //id
FCode : string; // 编码
FName : string; // 姓名
FDepID : Integer; //部门id
FMob : string; //移动电话
FTel : string; //电话
FEMail : string; //电子邮件
FOicq : string; //Oicq
FMSN : string; //MSN
FBal : Real; //余额
FRemark : string; //备注
FDepName : string; //部门名称
FQuery : TADOQuery;
public
procedure Setid(const Val : Integer);
procedure SetCode(const Val : string);
procedure SetName(const Val : string);
procedure SetDepID(const Val : Integer);
procedure SetMob(const Val : string);
procedure SetTel(const Val : string);
procedure SetEmail(const Val : string);
procedure SetOicq(const Val : string);
procedure SetMSN(const Val : string);
procedure SetBal(const Val : Real);
procedure SetRemark(const Val : string);
procedure SetDepName(const Val : string);

property id : Integer read Fid write Setid;
property Code : string read FCode write SetCode;
property Name : string read FName write SetName;
property DepID : Integer read FDepID write SetDepID;
property Mob : string read FMob write SetMob;
property Tel : string read FTel write SetTel;
property EMail : string read FEMail write SetEMail;
property Oicq : string read FOicq write SetOicq;
property MSN : string read FMSN write SetMSN;
property Bal : Real read FBal write SetBal;
property Remark : string read FRemark write SetRemark;
property DepName : string read FDepName write SetDepName;

function Insert : Boolean;
function Amend (id : Integer): Boolean;
function Delete (id : Integer) : Boolean;
procedure GetAllField(const xQuery : TADOQuery);

constructor create;
destructor destroy; override;
end;

//初始化
constructor TEmployee.create;
begin
inherited create;
FQuery := TADOQuery.Create(nil);
FQuery.Connection := dm.con1;
end;

//修改
function TEmployee.Amend(id : Integer): Boolean;
begin
Result := False;
if id >0 then
begin
try
with FQuery do
begin
Close;
SQL.Clear;
SQL.Add('insert into dm_yg set ygxm=:ygxm,depid=:depid,stdh=:stdh,');
SQL.Add('ggdh=:ggdh,dzyx=:dzyx,qq=:qq,msn=:msn,bz=:bz,zhje=:zhje where [id]=:id');
Parameters.ParamByName('ygxm').Value := FName;
Parameters.ParamByName('depid').Value := FDepID;
Parameters.ParamByName('stdh').Value := FMob;
Parameters.ParamByName('ggdh').Value := FTel;
Parameters.ParamByName('dzyx').Value := FEMail;
Parameters.ParamByName('qq').Value := FOicq;
Parameters.ParamByName('msn').Value := FMSN;
Parameters.ParamByName('bz').Value := FRemark;
Parameters.ParamByName('zhje').Value := FBal;
Parameters.ParamByName('id').Value := id;
ExecSQL;
end;
Result := True;
except
Application.MessageBox('修改失败,请重新运行程序!', MB_Title, MB_OK +
MB_ICONSTOP + MB_TOPMOST);
Result:= False;
end;
end;
end;


//从数据库删除
function TEmployee.Delete(id : Integer): Boolean;
begin
Result := False;
if ID > 0 then
begin
try
with FQuery do
begin
if Application.MessageBox('是否删除该项数据?', MB_Title, MB_YESNO + MB_ICONQUESTION + MB_TOPMOST) = IDNO then Exit;
with FQuery do
begin
Close;
SQL.Clear;
SQL.Add('select * from dm_yg where [id]=:id');
Parameters.ParamByName('id').Value := ID;
Open;

if RecordCount > 0 then
begin
if Application.MessageBox('该数据项正被其他数据使用,是否删除?', MB_Title, MB_YESNO + MB_ICONWARNING + MB_TOPMOST) = IDNO then Exit;
Close;
SQL.Clear;
SQL.Add('delete from dm_yg where [id]=:id');
Parameters.ParamByName('id').Value := ID;
ExecSQL;
end;
end;
end;
Result := True;
except
Application.MessageBox('无法删除,请重新运行程序!', MB_Title, MB_OK +
MB_ICONSTOP + MB_TOPMOST);
Result:=False;
end;
end;
end;

//析构
destructor TEmployee.destroy;
begin

FQuery.Close;
FreeAndNil(FQuery);
inherited;
end;

...全文
256 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sgpxd 2007-03-16
  • 打赏
  • 举报
回复
没给那么多。。

每人50
lihuasoft 2007-03-16
  • 打赏
  • 举报
回复
结贴图例:http://community.csdn.net/over.htm
lihuasoft 2007-03-16
  • 打赏
  • 举报
回复
点击“管理”-->在“码”后输入你的密码-->在我的回复后面输入 100 ,然后点击“给分”。OK,这就结了。

^_^
sgpxd 2007-03-16
  • 打赏
  • 举报
回复
不知道怎么结,问题已经解决了

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧