首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

类方法 stackoverflow,该怎么处理

2012-03-01 
类方法 stackoverflow请问:我声明了一个类,其中有对数据库的添加,删除,修改等方法。在程序中,调用删除运行

类方法 stackoverflow
请问:
我声明了一个类,其中有对数据库的添加,删除,修改等方法。

在程序中,调用删除运行正常,调用添加和删除后,程序就死了,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;    



[解决办法]
点击“管理”--> 在“码”后输入你的密码--> 在我的回复后面输入 100 ,然后点击“给分”。OK,这就结了。

^_^
[解决办法]
结贴图例:http://community.csdn.net/over.htm

热点排行