OK!
在Capfile.h中
class TCapfile : public TObject
{
private: // User declarations
Longint blen;
int readint(char *buff,Longint *li,int max);
int readln(char *obuff,char *sbuff);
public:
char *Buf;
int errornum;
__fastcall TCapfile(String filename);
__fastcall TCapfile(char *buff,int bufflen);
__fastcall ~TCapfile();
int __fastcall readtgn(Longint position,char *tgn,char *times,char *dates,Longint datas[29]);
int __fastcall readdestid(Longint position,char *destid,char *times,char *dates,Longint datas[15]);
};
在Capfile.cpp中
__fastcall TCapfile::TCapfile(String filename)
{
blen=0;
int RHand=FileOpen(filename, fmOpenRead);
if (RHand==-1)
{
errornum=-1;
return;
}
Longint FLen = FileSeek(RHand,0,2);
Buf = new char[FLen+1];
FileSeek(RHand,0,0);
blen = FileRead(RHand, Buf, FLen);
FileClose(RHand);
errornum=0;
}
__fastcall TCapfile::TCapfile(char *buff,int bufflen)
{
blen=0;
Buf = new char[bufflen+1];
StrCopy(Buf, buff);
blen=bufflen;
errornum=0;
}
在dy.cpp中调用
TCapfile *fff=new TCapfile("D://020223.cap");
Longint i=0,ll;
Longint mb1[29],mb2[15];
char dates1[8],dates2[8],tgn1[4],destid1[8],times1[2],times2[2];
i=fff->readtgn(i,tgn1,times1,dates1,mb1);
i=fff->readdestid(i,destid1,times2,dates2,mb2);
delete fff;
注意在初始化类fff时fff->Buf正常。
调用readtgn结束前Buf也正常,但调用readdestid时Buf指向的内容为????。