//头文件
//---------------------------------------------------------------------------
#ifndef uAutoFireH
#define uAutoFireH
//---------------------------------------------------------------------------
class PACKAGE TAutoFire{
protected:
virtual void __fastcall Constructor(void);
virtual void __fastcall Destructor(void);
public:
TAutoFire();
virtual ~TAutoFire();
};
class PACKAGE TPerformanceLogger : public TAutoFire{
private:
TFileStream *m_pFileStream;
protected:
virtual void __fastcall Constructor(void);
virtual void __fastcall Destructor(void);
public:
TPerformanceLogger(const AnsiString FileName = "c:\\PerformanceLogger.log");
virtual ~TPerformanceLogger();
};
#endif
//实现
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "uAutoFire.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
TAutoFire::TAutoFire()
{
Constructor();
}
TAutoFire::~TAutoFire()
{
Destructor();
}
void __fastcall TAutoFire::Constructor(void)
{
}
void __fastcall TAutoFire:
estructor()
{
}
TPerformanceLogger::TPerformanceLogger(const AnsiString FileName)
{
m_pFileStream = new TFileStream(FileName, fmCreate|fmOpenReadWrite);
TAutoFire::TAutoFire();
}
TPerformanceLogger::~TPerformanceLogger()
{
delete m_pFileStream;
}
void __fastcall TPerformanceLogger::Constructor()
{
m_pFileStream->Seek(0, soFromEnd);
AnsiString sTemp = AnsiString().sprintf("%s - Begin.\r\n", FormatDateTime("yyyy-MM-dd hh:nn:ss.zzz", Now()));
m_pFileStream->Write(sTemp.c_str(), sTemp.Length());
}
void __fastcall TPerformanceLogger:
estructor()
{
AnsiString sTemp = AnsiString().sprintf("%s - End.\r\n", FormatDateTime("yyyy-MM-dd hh:nn:ss.zzz", Now()));
m_pFileStream->Write(sTemp.c_str(), sTemp.Length());
}
上面的virtual使用上有问题吗?为什么不会调用TPerformanceLogger的Constructor和Destructor?