S
sgpxd
Unregistered / Unconfirmed
GUEST, unregistred user!
请问:<br>我声明了一个类,其中有对数据库的添加,删除,修改等方法。<br><br>在程序中,调用删除运行正常,调用添加和删除后,程序就死了,delphi的cpu占用率变高了。<br><br>把这两个方法的实现部分注释掉,提示stack overflow<br><br>类声明如下 //添加部分有2个子过程,<br>type<br> //员工<br> TEmployee = class (TObject)<br> private<br> Fid : Integer; //id<br> FCode : string; // 编码<br> FName : string; // 姓名<br> FDepID : Integer; //部门id<br> FMob : string; //移动电话<br> FTel : string; //电话<br> FEMail : string; //电子邮件<br> FOicq : string; //Oicq<br> FMSN : string; //MSN<br> FBal : Real; //余额<br> FRemark : string; //备注<br> FDepName : string; //部门名称<br> FQuery : TADOQuery;<br> public<br> procedure Setid(const Val : Integer);<br> procedure SetCode(const Val : string);<br> procedure SetName(const Val : string);<br> procedure SetDepID(const Val : Integer);<br> procedure SetMob(const Val : string);<br> procedure SetTel(const Val : string);<br> procedure SetEmail(const Val : string);<br> procedure SetOicq(const Val : string);<br> procedure SetMSN(const Val : string);<br> procedure SetBal(const Val : Real);<br> procedure SetRemark(const Val : string);<br> procedure SetDepName(const Val : string);<br><br> property id : Integer read Fid write Setid;<br> property Code : string read FCode write SetCode;<br> property Name : string read FName write SetName;<br> property DepID : Integer read FDepID write SetDepID;<br> property Mob : string read FMob write SetMob;<br> property Tel : string read FTel write SetTel;<br> property EMail : string read FEMail write SetEMail;<br> property Oicq : string read FOicq write SetOicq;<br> property MSN : string read FMSN write SetMSN;<br> property Bal : Real read FBal write SetBal;<br> property Remark : string read FRemark write SetRemark;<br> property DepName : string read FDepName write SetDepName;<br><br> function Insert : Boolean;<br> function Amend (id : Integer): Boolean;<br> function Delete (id : Integer) : Boolean;<br> procedure GetAllField(const xQuery : TADOQuery);<br><br> constructor create; overload;<br> destructor destroy; override;<br> end;<br><br>//初始化<br>constructor TEmployee.create;<br>begin<br> inherited create;<br>// FQuery := TADOQuery.Create(nil);<br>// FQuery.Connection := dm.con1;<br>end;<br><br>//修改<br>function TEmployee.Amend(id : Integer): Boolean;<br>begin<br> { Result := False;<br> if id >0 then<br> begin<br> try<br> { with FQuery do<br> begin<br> Close;<br> SQL.Clear;<br> SQL.Add('insert into dm_yg set ygxm=:ygxm,depid=:depid,stdh=:stdh,');<br> SQL.Add('ggdh=:ggdh,dzyx=:dzyx,qq=:qq,msn=:msn,bz=:bz,zhje=:zhje where [id]=:id');<br> Parameters.ParamByName('ygxm').Value := FName;<br> Parameters.ParamByName('depid').Value := FDepID;<br> Parameters.ParamByName('stdh').Value := FMob;<br> Parameters.ParamByName('ggdh').Value := FTel;<br> Parameters.ParamByName('dzyx').Value := FEMail;<br> Parameters.ParamByName('qq').Value := FOicq;<br> Parameters.ParamByName('msn').Value := FMSN;<br> Parameters.ParamByName('bz').Value := FRemark;<br> Parameters.ParamByName('zhje').Value := FBal;<br> Parameters.ParamByName('id').Value := id;<br> ExecSQL;<br> end;<br> Result := True;<br> except<br> Application.MessageBox('修改失败,请重新运行程序!', MB_Title, MB_OK +<br> MB_ICONSTOP + MB_TOPMOST);<br> Result:= False;<br> end;<br> end; }<br>end;<br><br><br>//从数据库删除<br>function TEmployee.Delete(id : Integer): Boolean;<br>begin<br> Result := False;<br> if ID > 0 then<br> begin<br> try<br> with FQuery do<br> begin<br> if Application.MessageBox('是否删除该项数据?', MB_Title, MB_YESNO + MB_ICONQUESTION + MB_TOPMOST) = IDNO then Exit;<br> with FQuery do<br> begin<br> Close;<br> SQL.Clear;<br> SQL.Add('select * from dm_yg where [id]=:id');<br> Parameters.ParamByName('id').Value := ID;<br> Open;<br><br> if RecordCount > 0 then<br> begin<br> if Application.MessageBox('该数据项正被其他数据使用,是否删除?', MB_Title, MB_YESNO + MB_ICONWARNING + MB_TOPMOST) = IDNO then Exit;<br> Close;<br> SQL.Clear;<br> SQL.Add('delete from dm_yg where [id]=:id');<br> Parameters.ParamByName('id').Value := ID;<br> ExecSQL;<br> end;<br> end;<br> end;<br> Result := True;<br> except<br> Application.MessageBox('无法删除,请重新运行程序!', MB_Title, MB_OK +<br> MB_ICONSTOP + MB_TOPMOST);<br> Result:=False;<br> end;<br> end;<br>end;<br><br>//析构<br>destructor TEmployee.destroy;<br>begin<br> inherited;<br> FQuery.Close;<br> FreeAndNil(FQuery);<br>end;