怎样用子类的函数代替父类的函数 想了两天也想不明白,只差那么一点点,唉....
#ifndef Unit12H
#define Unit12H
class TForm12 : public TForm
{
__published:
void __fastcall Table1costChange(TField *Sender);//这是一个数据库中固定字段的事件函数
...............
}
//unit12.cpp文件
void __fastcall TForm12::Table1costChange(TField *Sender)
{
Table1->Edit();
Table1total->ReadOnly=false;
Table1->FieldByName("total")->AsFloat=Table1->FieldByName("anount")->AsFloat*Table1->FieldByName("cost")->AsFloat;
Table1total->ReadOnly=true;
Table1->Post();
}
以下是;另外一个的文件,是用来继承Form12的
#ifndef Unit20H
#define Unit20H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include "Unit12.h"
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
class TForm20 : public TForm12
{
__published:
void __fastcall Table1costChange(TField *Sender);//这个事件是自己定义的,只是想,代替form12::Table1costChange(TField *Sender)
void __fastcall FormCreate(TObject *Sender);
private:
public:
__fastcall TForm20(TComponent* Owner);
};
//Unit20.cpp文件.........
void __fastcall TForm20::Table1costChange(TField *Sender)
{
TForm12::Table1->Edit();
TForm12::Table1->FieldByName("cost")->AsFloat=-TForm12::Table1->FieldByName("cost")->AsFloat;
TForm12::Table1total->ReadOnly=false;
TForm12::Table1->FieldByName("total")->AsFloat=TForm12::Table1->FieldByName("anount")->AsFloat*TForm12::Table1->FieldByName("cost")->AsFloat;
TForm12::Table1total->ReadOnly=true;
TForm12::Table1->Post();
}
void __fastcall TForm20::FormCreate(TObject *Sender)
{
TForm12::Table1costChange=Table1costChange;//走到这里就不行了就出现了
MeMber function must be called or its address taken的异常语句
}
我想做的是,怎样用Form20::Table1costChange(TField *Sender)这个事件来代替Form12::Table1costChange(TField *Sender)
简单地来说,就是,当Table1cost这个固定字段发生变化的时候,执行的是Form12::Table1costChange(TField *Sender)而不是Form20::Table1costChange(TField *Sender)