| 『第 287 楼』:
 
 
使用 LLM 解释/回答一下 
 
 
//下面文件是Foxpro.Cpp文件#include <math.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <dos.h>
 #include <bios.h>
 #include <dir.h>
 #include <conio.h>
 #include <string.h>
 #include <sys\\stat.h>
 #include <io.h>
 
 #include "symbol2.h"
 #include "Foxpro.h"
 
 
 //#include <Myframe.h>
 
 void CFoxpro::CoFoxpro()
 {
 m_bNew          = FALSE;
 m_lRecordPoint  = 0;
 m_pRecordBuf    = NULL;
 m_pFile         = NULL;
 m_pFoxproFields = NULL;
 _fmemset(&m_FoxproHead  ,0,sizeof(FOXPRO_HEAD));
 _fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
 _fmemset(&m_strFile,0,256);
 }
 
 CFoxpro::CFoxpro()
 {
 this->CoFoxpro();
 }
 
 CFoxpro::CFoxpro(char* strFile)
 {
 
 this->CoFoxpro();
 this->OpenFoxpro(strFile);
 }
 
 CFoxpro::~CFoxpro()
 {
 if (m_pFile != NULL)
 {
 fclose(m_pFile);
 }
 m_pFile = NULL;
 
 DELETE(m_pRecordBuf);
 DELETE(m_pFoxproFields);
 
 }
 
 void CFoxpro::Debug()
 {
 char buf;
 if(!m_pRecordBuf) return;
 
 int nFields = this->GetFieldsCount();
 printf("\n-------------------------------------------------");
 for(int i=0;i<nFields;i++)
 {
 m_FoxproFields = *(this->GetFoxproFields(i));
 
 printf("\n%10s--",m_FoxproFields.strName);
 if(m_FoxproFields.byStyle=='C')
 {
 this->GetFieldsString(i,buf);
 this->TrimLeft(buf);
 this->TrimRight(buf);
 printf("%s",buf);
 }
 else if(m_FoxproFields.byStyle=='L')
 {
 BOOL bLogic = this->GetFieldsLogic(i);
 printf("%d",bLogic);
 }
 else if(m_FoxproFields.byStyle=='D')
 {
 int nYear,nMonth,nDay;
 this->GetFieldsDate(i,&nYear,&nMonth,&nDay);
 printf("%04d-%02d-%02d",nYear,nMonth,nDay);
 }
 else if(m_FoxproFields.byStyle=='N')
 {
 float fValue = this->GetFieldsNumber(i);
 if(m_FoxproFields.byDotCount==0)      printf("%.0f",fValue);
 else if(m_FoxproFields.byDotCount==1) printf("%.1f",fValue);
 else if(m_FoxproFields.byDotCount==2) printf("%.2f",fValue);
 else if(m_FoxproFields.byDotCount==3) printf("%.3f",fValue);
 else if(m_FoxproFields.byDotCount==4) printf("%.4f",fValue);
 else if(m_FoxproFields.byDotCount==5) printf("%.5f",fValue);
 else                                  printf("%.6f",fValue);
 
 }
 else if(m_FoxproFields.byStyle=='M')
 {
 }
 if(i&& !(i%24))
 {
 getch();
 }
 
 }
 }
 
 BOOL  CFoxpro::CreateFoxpro(const char *pStr)
 {
 if(m_pFile) return(FALSE);
 
 m_pFile = NULL;
 
 CoFoxpro();
 
 int nFields = 0;
 
 date mDate;
 ::getdate(&mDate);
 
 m_FoxproHead.byFlags        = 0x03;
 m_FoxproHead.byDay          = (BYTE)mDate.da_day;
 m_FoxproHead.byMonth        = (BYTE)mDate.da_mon;
 m_FoxproHead.byYear         = (BYTE)(WORD)(mDate.da_year-1900);
 m_FoxproHead.dwRecordCount  = 0x00;
 m_FoxproHead.wRecordAddress = sizeof(FOXPRO_HEAD)+1;
 m_FoxproHead.wRecordLength  = 0x01;
 m_FoxproHead.dwReserve1     = 0x00;
 m_FoxproHead.dwReserve2     = 0x00;
 m_FoxproHead.dwReserve3     = 0x00;
 m_FoxproHead.dwReserve4     = 0x00;
 m_FoxproHead.dwReserve5     = 0x00;
 
 _fmemset(&m_FoxproFields.strName,0,10);
 m_FoxproFields.byFill        = 0;
 m_FoxproFields.byStyle       = (BYTE)'C';
 m_FoxproFields.dwDataAddress = 0;
 m_FoxproFields.byLength      = 0;
 m_FoxproFields.byDotCount    = 0;
 m_FoxproFields.wReserve1     = 0;
 m_FoxproFields.byFlags       = 0;
 _fmemset(&m_FoxproFields.wsReserve,0,11);
 
 if(!(m_pFile=fopen(pStr,"w+b")))
 {
 return(FALSE);
 }
 
 fwrite(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
 fwrite(&m_FoxproFields,sizeof(FOXPRO_FIELDS),nFields,m_pFile);
 fwrite("\x0D",1,1,m_pFile);
 fwrite("\x1A",1,1,m_pFile);
 
 //File Name
 _fstrcpy(m_strFile,pStr);
 //Malloc RecordBuf
 m_pRecordBuf = new BYTE;
 _fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
 //Malloc  Foxpro_Fields
 m_pFoxproFields = new FOXPRO_FIELDS;
 _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
 //Fill FoxproFields
 ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
 nFields = this->GetFieldsCount();
 for(int i=0;i<nFields;i++)
 {
 ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 }
 return(TRUE);
 }
 
 
 BOOL  CFoxpro::OpenFoxpro(const char* pStr)
 {
 if (m_pFile != NULL)
 {
 return(FALSE);
 }
 
 CoFoxpro();
 
 if (!(m_pFile = fopen(pStr,"r+b")))
 {
 return(FALSE);
 }
 
 long  lFileLength = filelength(fileno(m_pFile));
 if(lFileLength<1L*sizeof(FOXPRO_HEAD)+2)
 {
 ::fclose(m_pFile);
 m_pFile=NULL;
 return(FALSE);
 }
 
 rewind(m_pFile);
 fread(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
 //Flags
 if(m_FoxproHead.byFlags!=0x03 && m_FoxproHead.byFlags!=0xF5)
 {
 ::fclose(m_pFile);
 m_pFile=NULL;
 return(FALSE);
 }
 
 BYTE nCh=0;
 fseek(m_pFile,-1,SEEK_END);
 fread(&nCh,1,1,m_pFile);
 // End Is 0x1A?
 if(nCh!=0x1A)
 {
 fclose(m_pFile);
 m_pFile=NULL;
 return(FALSE);
 }
 //---------------------------
 //File Name
 _fstrcpy(m_strFile,pStr);
 //Malloc Record Buffer
 m_pRecordBuf = new BYTE;
 if (m_pRecordBuf == NULL)
 {
 fclose(m_pFile);
 m_pFile=NULL;
 
 return (FALSE);
 }
 _fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
 //Malloc  Foxpro_Fields
 m_pFoxproFields = new FOXPRO_FIELDS;
 if (m_pFoxproFields == NULL)
 {
 delete m_pRecordBuf;
 m_pRecordBuf = NULL;
 
 fclose(m_pFile);
 m_pFile=NULL;
 
 return (FALSE);
 }
 
 _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
 //Fill FoxproFields
 ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
 int nFields = this->GetFieldsCount();
 for(int i=0;i<nFields;i++)
 {
 ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 }
 return(TRUE);
 }
 
 BOOL  CFoxpro::CloseFoxpro()
 {
 if (NULL != m_pFile)
 {
 fclose(m_pFile);
 }
 m_pFile = NULL;
 
 DELETE(m_pRecordBuf);
 DELETE(m_pFoxproFields);
 
 return(TRUE);
 }
 
 BOOL  CFoxpro::AddFields(const char* strName,BYTE byStyle,int nLength,int nDot)
 {
 if(!m_pFile) return(FALSE);
 
 if(byStyle=='C')      {nDot = 0;}
 else if(byStyle=='N') {}
 else if(byStyle=='D') {nLength = 8;nDot    = 0;}
 else if(byStyle=='L') {nLength=1;nDot   =0;}
 else if(byStyle=='M') {nLength = 10;nDot    = 0;}
 else {return(0);}
 
 _fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
 //----------------------------------------------------
 if(byStyle=='M')
 {
 m_FoxproHead.byFlags=0xF5;
 fseek(m_pFile,0,SEEK_SET);
 fwrite(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
 }
 //Calc Fields
 int nFields=(m_FoxproHead.wRecordAddress-sizeof(FOXPRO_HEAD))/sizeof(FOXPRO_FIELDS);
 //Modify Head
 date mDate;
 ::getdate(&mDate);
 m_FoxproHead.byDay          = (BYTE)mDate.da_day;
 m_FoxproHead.byMonth        = (BYTE)mDate.da_mon;
 m_FoxproHead.byYear         = (BYTE)(WORD)(mDate.da_year-1900);
 m_FoxproHead.wRecordAddress+= sizeof(FOXPRO_FIELDS);
 m_FoxproHead.wRecordLength += (WORD)nLength;
 //Write Head Again
 fseek(m_pFile,0,SEEK_SET);
 fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
 //
 int nFieldsAddress = 1;
 fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
 for(int i=0;i<nFields;i++)
 {
 ::fread(&m_FoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 nFieldsAddress+=m_FoxproFields.byLength;
 }
 //Fill in Field
 if (::_fstrlen(strName) < 10)
 {
 ::_fstrcpy((char*)&m_FoxproFields.strName,(char*)strName);
 }
 else
 {
 ::_fmemcpy((BYTE*)&m_FoxproFields.strName, (char*)strName, 10);
 }
 
 m_FoxproFields.byStyle       = (BYTE)byStyle;
 m_FoxproFields.dwDataAddress = nFieldsAddress;
 m_FoxproFields.byLength      = (BYTE)nLength;
 m_FoxproFields.byDotCount    = nDot;
 //Write Field
 ::fseek(m_pFile,sizeof(FOXPRO_HEAD)+nFields*sizeof(FOXPRO_FIELDS),SEEK_SET);
 ::fwrite(&m_FoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 //Write End
 fwrite("\x0D",1,1,m_pFile);
 fwrite("\x1A",1,1,m_pFile);
 
 //Malloc Record BUf
 DELETE(m_pRecordBuf);
 m_pRecordBuf = new BYTE;
 _fmemset(m_pRecordBuf,' ',this->GetRecordLength()+1024);
 m_pRecordBuf='\0';
 //Reset Record Point
 m_lRecordPoint=0;
 //Malloc Foxpro Fields
 DELETE(m_pFoxproFields);
 m_pFoxproFields = new FOXPRO_FIELDS;
 _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
 //Fill FoxproFields
 ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
 nFields = this->GetFieldsCount();
 for(i=0;i<nFields;i++)
 {
 ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 }
 
 return(TRUE);
 }
 
 char*  CFoxpro::TrimLeft(char  *pStr)
 {
 //if(_fstrlen(pStr)>=256) return(pStr);
 while(pStr==' '||pStr=='\x9')
 {
 int nLength=_fstrlen(pStr);
 if(!nLength) break;
 if(nLength) _fmemcpy(&pStr,&pStr,nLength);
 }
 return(pStr);
 }
 
 char*  CFoxpro::TrimRight(char *pStr)
 {
 //if(_fstrlen(pStr)>=256) return(pStr);
 int nLength=_fstrlen(pStr);
 if(!nLength) return(pStr);
 for(int i=nLength-1;i>=0;i--)
 {
 if(pStr!=' '&&pStr!='\x9') break;
 pStr='\0';
 }
 
 return(pStr);
 }
 
 FOXPRO_FIELDS*  CFoxpro::GetFoxproFields(int nIndex)
 {
 ::_fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
 //----------------------------------------------------
 //Calc Fields
 int nFields=this->GetFieldsCount();
 if(nIndex>=nFields||nFields<0) return(&m_FoxproFields);
 return(&m_pFoxproFields);
 }
 
 BOOL  CFoxpro::GetFieldsString(int nIndex,char* pStr)
 {
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 if(m_FoxproFields.byStyle!='C') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 _fmemcpy(pStr,&m_pRecordBuf,m_FoxproFields.byLength);
 if(m_FoxproFields.byLength)
 {
 pStr = '\0';
 }
 this->TrimRight(pStr);
 
 return(TRUE);
 }
 
 float  CFoxpro::GetFieldsNumber(int nIndex)
 {
 char buf;
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='N') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 _fmemcpy(buf,&m_pRecordBuf,m_FoxproFields.byLength);
 buf = '\0';
 return(atof(buf));
 }
 
 BOOL  CFoxpro::GetFieldsDate(int nIndex,int* pnYear,int* pnMonth,int* pnDay)
 {
 char buf1,buf2;
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='D') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 _fmemcpy(buf1,&m_pRecordBuf,m_FoxproFields.byLength);
 buf1 = '\0';
 
 buf2=buf1;
 buf2=buf1;
 buf2=buf1;
 buf2=buf1;
 buf2='\0';
 *pnYear =(int)(atof(buf2)+0.5f);
 
 buf2=buf1;
 buf2=buf1;
 buf2='\0';
 *pnMonth =(int)(atof(buf2)+0.5f);
 
 buf2=buf1;
 buf2=buf1;
 buf2='\0';
 *pnDay =(int)(atof(buf2)+0.5f);
 
 return(TRUE);
 }
 
 BOOL  CFoxpro::GetFieldsLogic(int nIndex)
 {
 char buf;
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='L') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 _fmemcpy(buf,&m_pRecordBuf,m_FoxproFields.byLength);
 buf = '\0';
 if(buf=='T')  return(TRUE);
 return(FALSE);
 }
 
 BOOL  CFoxpro::GetFieldsMemo(int /*nIndex*/,char* /*pStr*/)
 {
 return(TRUE);
 }
 
 BOOL  CFoxpro::SetFieldsString(int nIndex, const char* pStr)
 {
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='C') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 int nLength1 = _fstrlen(pStr);
 int nLength2 = (WORD)m_FoxproFields.byLength;
 for(int i=0;i<nLength2;i++)
 {
 if(i>=nLength1)
 {
 m_pRecordBuf=' ';
 }
 else
 {
 m_pRecordBuf=*(pStr+i);
 }
 }
 
 
 //::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
 //::fseek(m_pFile,m_lRecordPoint*GetRecordLength(),SEEK_CUR);
 //::fseek(m_pFile,nAddress,SEEK_CUR);
 return(TRUE);
 }
 BOOL  CFoxpro::SetFieldsNumber(int nIndex,float fValue)
 {
 char buf;
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='N') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 
 if(m_FoxproFields.byDotCount==0) sprintf(buf,"%.0f",fValue);
 else if(m_FoxproFields.byDotCount==1) sprintf(buf,"%.1f",fValue);
 else if(m_FoxproFields.byDotCount==2) sprintf(buf,"%.2f",fValue);
 else if(m_FoxproFields.byDotCount==3) sprintf(buf,"%.3f",fValue);
 else if(m_FoxproFields.byDotCount==4) sprintf(buf,"%.4f",fValue);
 else if(m_FoxproFields.byDotCount==5) sprintf(buf,"%.5f",fValue);
 else  sprintf(buf,"%.6f",fValue);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 int nLength1 = _fstrlen(buf);
 int nLength2 = (WORD)m_FoxproFields.byLength;
 for(int i=0;i<nLength2;i++)
 {
 if(i>=nLength1)
 {
 m_pRecordBuf=' ';
 }
 else
 {
 m_pRecordBuf=buf;
 }
 }
 
 return(TRUE);
 }
 BOOL  CFoxpro::SetFieldsDate(int nIndex,int nYear,int nMonth,int nDay)
 {
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='D') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 //sprintf((char *)&m_pRecordBuf,"%4d%2d%2d%",nYear,nMonth,nDay);
 //m_pRecordBuf=' ';
 char buf;
 sprintf(buf,"%4d%2d%2d",nYear,nMonth,nDay);
 for(int i=0;i<8;i++)
 {
 m_pRecordBuf = buf;
 }
 
 
 return(TRUE);
 }
 BOOL  CFoxpro::SetFieldsLogic(int nIndex,BOOL bLogic)
 {
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='L') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 if(bLogic) m_pRecordBuf='T';
 else m_pRecordBuf='F';
 
 return(TRUE);
 }
 BOOL  CFoxpro::SetFieldsMemo(int nIndex, const char* /*pStr*/)
 {
 int nFields=this->GetFieldsCount();
 if(nIndex<0||nIndex>=nFields||nFields<0) return(FALSE);
 
 m_FoxproFields = *(this->GetFoxproFields(nIndex));
 
 if(m_FoxproFields.byStyle!='M') return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 //int nAddress = (WORD)m_FoxproFields.dwDataAddress;
 //((DWORD *)&m_pRecordBuf)=(BYTE)chLogic;
 
 return(TRUE);
 }
 
 BOOL  CFoxpro::Seek(long nIndex,int nMode)
 {
 if(!m_pFile) return(FALSE);
 
 if(nMode==SEEK_SET)      m_lRecordPoint = nIndex;
 else if(nMode==SEEK_CUR) m_lRecordPoint+= nIndex;
 else if(nMode==SEEK_END)
 {
 m_lRecordPoint = GetRecordCount();
 m_lRecordPoint+= nIndex;
 }
 ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
 ::fseek(m_pFile,m_lRecordPoint*GetRecordLength(),SEEK_CUR);
 
 if(m_lRecordPoint<this->GetRecordCount())
 {
 ::fread(m_pRecordBuf,this->GetRecordLength(),1,m_pFile);
 m_pRecordBuf='\0';
 ::fseek(m_pFile,0L-GetRecordLength(),SEEK_CUR);
 }
 
 return(TRUE);
 }
 
 BOOL  CFoxpro::Delete()
 {
 if(!m_pFile) return(FALSE);
 if(!m_pRecordBuf) return(FALSE);
 
 if(m_lRecordPoint>=this->GetRecordCount()) return(FALSE);
 
 this->Edit();
 m_pRecordBuf='*';
 this->Update();
 
 return(TRUE);
 }
 
 BOOL  CFoxpro::Zap()
 {
 if(!m_pFile) return(FALSE);
 if(!this->GetRecordCount()) return(TRUE);
 
 
 long lRecordCount  = this->GetRecordCount();
 long lRecordLength = this->GetRecordLength();
 
 long lLocation=0;
 for(long i=0;i<lRecordCount;i++)
 {
 ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
 ::fseek(m_pFile,i*lRecordLength,SEEK_CUR);
 
 ::fread(m_pRecordBuf,lRecordLength,1,m_pFile);
 if(m_pRecordBuf != '*')
 {
 ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
 ::fseek(m_pFile,lLocation*lRecordLength,SEEK_CUR);
 ::fwrite(m_pRecordBuf,lRecordLength,1,m_pFile);
 lLocation++;
 }
 }
 this->m_FoxproHead.dwRecordCount=lLocation;
 
 ::fseek(m_pFile,0,SEEK_SET);
 ::fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
 
 long lFileLength = sizeof(FOXPRO_HEAD)+
 1L*sizeof(FOXPRO_FIELDS)*this->GetFieldsCount()+
 1L+
 1L*this->m_FoxproHead.dwRecordCount*lRecordLength;
 
 
 ::chsize(fileno(m_pFile),lFileLength);
 ::fseek(m_pFile,0,SEEK_END);
 ::fwrite("\x1A",1,1,m_pFile);
 
 m_lRecordPoint=0L;
 
 this->Seek(m_lRecordPoint,SEEK_SET);
 this->Edit();
 return(TRUE);
 }
 
 BOOL  CFoxpro::DeleteEx()
 {
 if(!m_pFile) return(FALSE);
 
 if(m_lRecordPoint>=this->GetRecordCount()) return(FALSE);
 
 
 long lRecordCount  = this->GetRecordCount();
 long lRecordLength = this->GetRecordLength();
 
 for(long i=m_lRecordPoint+1;i<lRecordCount;i++)
 {
 ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
 ::fseek(m_pFile,i*lRecordLength,SEEK_CUR);
 
 ::fread(m_pRecordBuf,lRecordLength,1,m_pFile);
 
 ::fseek(m_pFile,-2L*lRecordLength,SEEK_CUR);
 ::fwrite(m_pRecordBuf,lRecordLength,1,m_pFile);
 }
 
 this->m_FoxproHead.dwRecordCount-=1;
 ::fseek(m_pFile,0,SEEK_SET);
 ::fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
 long lFileLength = sizeof(FOXPRO_HEAD)+
 1L*sizeof(FOXPRO_FIELDS)*this->GetFieldsCount()+
 1L+
 1L*this->m_FoxproHead.dwRecordCount*lRecordLength;
 
 
 ::chsize(fileno(m_pFile),lFileLength);
 ::fseek(m_pFile,0,SEEK_END);
 ::fwrite("\x1A",1,1,m_pFile);
 
 if(m_lRecordPoint && m_lRecordPoint==this->GetRecordCount())
 {
 m_lRecordPoint-=1;
 }
 //------------------------------------------------------------
 this->Seek(m_lRecordPoint,SEEK_SET);
 this->Edit();
 return(TRUE);
 }
 
 BOOL  CFoxpro::Insert()
 {
 return(TRUE);
 }
 
 BOOL  CFoxpro::AddNew()
 {
 if (NULL == m_pFile)
 {
 return(FALSE);
 }
 m_lRecordPoint = this->GetRecordCount();
 _fmemset(m_pRecordBuf,' ',this->GetRecordLength()+1024);
 this->Seek(0,SEEK_END);
 m_bNew = TRUE;
 
 return(TRUE);
 }
 
 BOOL  CFoxpro::Edit()
 {
 if(NULL == m_pFile)
 {
 return(FALSE);
 }
 if (m_bNew)
 {
 return(TRUE);
 }
 
 this->Seek(m_lRecordPoint,SEEK_SET);
 ::fread(m_pRecordBuf,this->GetRecordLength(),1,m_pFile);
 m_pRecordBuf='\0';
 
 return(TRUE);
 }
 BOOL  CFoxpro::Update()
 {
 if (NULL == m_pFile) return(FALSE);
 
 if(m_bNew)
 {
 m_lRecordPoint = this->GetRecordCount();
 }
 
 ::fseek(m_pFile,this->GetRecordAddress(),SEEK_SET);
 ::fseek(m_pFile,m_lRecordPoint*GetRecordLength(),SEEK_CUR);
 ::fwrite(m_pRecordBuf,this->GetRecordLength(),1,m_pFile);
 
 if (m_bNew)
 {
 //::fseek(m_pFile, 0, SEEK_END);
 fwrite("\x1A",1,1,m_pFile);
 
 rewind(m_pFile);
 m_FoxproHead.dwRecordCount += 1;
 ::fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
 }
 m_bNew = FALSE;
 return(TRUE);
 }
 
 BOOL  CFoxpro::IsOpen()
 {
 return(((m_pFile)?TRUE:FALSE));
 }
 
 BOOL CFoxpro::Flush()
 {
 if (NULL == m_pFile)
 {
 return(FALSE);
 }
 ::fflush(m_pFile);
 
 int duphandle = ::dup(fileno(m_pFile));
 
 ::close(duphandle);
 
 return(TRUE);
 }
 
 Last edited by firstsail on 2018-7-14 at 12:38 ]
 
```cpp// The following file is the Foxpro.Cpp file
 #include <math.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <dos.h>
 #include <bios.h>
 #include <dir.h>
 #include <conio.h>
 #include <string.h>
 #include <sys\\stat.h>
 #include <io.h>
 
 #include "symbol2.h"
 #include "Foxpro.h"
 
 
 //#include <Myframe.h>
 
 void CFoxpro::CoFoxpro()
 {
 m_bNew          = FALSE;
 m_lRecordPoint  = 0;
 m_pRecordBuf    = NULL;
 m_pFile         = NULL;
 m_pFoxproFields = NULL;
 _fmemset(&m_FoxproHead  ,0,sizeof(FOXPRO_HEAD));
 _fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
 _fmemset(&m_strFile,0,256);
 }
 
 CFoxpro::CFoxpro()
 {
 this->CoFoxpro();
 }
 
 CFoxpro::CFoxpro(char* strFile)
 {
 
 this->CoFoxpro();
 this->OpenFoxpro(strFile);
 }
 
 CFoxpro::~CFoxpro()
 {
 if (m_pFile != NULL)
 {
 fclose(m_pFile);
 }
 m_pFile = NULL;
 
 DELETE(m_pRecordBuf);
 DELETE(m_pFoxproFields);
 
 }
 
 void CFoxpro::Debug()
 {
 char buf;
 if(!m_pRecordBuf) return;
 
 int nFields = this->GetFieldsCount();
 printf("\n-------------------------------------------------");
 for(int i=0;i<nFields;i++)
 {
 m_FoxproFields = *(this->GetFoxproFields(i));
 
 printf("\n%10s--",m_FoxproFields.strName);
 if(m_FoxproFields.byStyle=='C')
 {
 this->GetFieldsString(i,buf);
 this->TrimLeft(buf);
 this->TrimRight(buf);
 printf("%s",buf);
 }
 else if(m_FoxproFields.byStyle=='L')
 {
 BOOL bLogic = this->GetFieldsLogic(i);
 printf("%d",bLogic);
 }
 else if(m_FoxproFields.byStyle=='D')
 {
 int nYear,nMonth,nDay;
 this->GetFieldsDate(i,&nYear,&nMonth,&nDay);
 printf("%04d-%02d-%02d",nYear,nMonth,nDay);
 }
 else if(m_FoxproFields.byStyle=='N')
 {
 float fValue = this->GetFieldsNumber(i);
 if(m_FoxproFields.byDotCount==0)      printf("%.0f",fValue);
 else if(m_FoxproFields.byDotCount==1) printf("%.1f",fValue);
 else if(m_FoxproFields.byDotCount==2) printf("%.2f",fValue);
 else if(m_FoxproFields.byDotCount==3) printf("%.3f",fValue);
 else if(m_FoxproFields.byDotCount==4) printf("%.4f",fValue);
 else if(m_FoxproFields.byDotCount==5) printf("%.5f",fValue);
 else                                  printf("%.6f",fValue);
 
 }
 else if(m_FoxproFields.byStyle=='M')
 {
 }
 if(i&& !(i%24))
 {
 getch();
 }
 
 }
 }
 
 BOOL  CFoxpro::CreateFoxpro(const char *pStr)
 {
 if(m_pFile) return(FALSE);
 
 m_pFile = NULL;
 
 CoFoxpro();
 
 int nFields = 0;
 
 date mDate;
 ::getdate(&mDate);
 
 m_FoxproHead.byFlags        = 0x03;
 m_FoxproHead.byDay          = (BYTE)mDate.da_day;
 m_FoxproHead.byMonth        = (BYTE)mDate.da_mon;
 m_FoxproHead.byYear         = (BYTE)(WORD)(mDate.da_year-1900);
 m_FoxproHead.dwRecordCount  = 0x00;
 m_FoxproHead.wRecordAddress = sizeof(FOXPRO_HEAD)+1;
 m_FoxproHead.wRecordLength  = 0x01;
 m_FoxproHead.dwReserve1     = 0x00;
 m_FoxproHead.dwReserve2     = 0x00;
 m_FoxproHead.dwReserve3     = 0x00;
 m_FoxproHead.dwReserve4     = 0x00;
 m_FoxproHead.dwReserve5     = 0x00;
 
 _fmemset(&m_FoxproFields.strName,0,10);
 m_FoxproFields.byFill        = 0;
 m_FoxproFields.byStyle       = (BYTE)'C';
 m_FoxproFields.dwDataAddress = 0;
 m_FoxproFields.byLength      = 0;
 m_FoxproFields.byDotCount    = 0;
 m_FoxproFields.wReserve1     = 0;
 m_FoxproFields.byFlags       = 0;
 _fmemset(&m_FoxproFields.wsReserve,0,11);
 
 if(!(m_pFile=fopen(pStr,"w+b")))
 {
 return(FALSE);
 }
 
 fwrite(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
 fwrite(&m_FoxproFields,sizeof(FOXPRO_FIELDS),nFields,m_pFile);
 fwrite("\x0D",1,1,m_pFile);
 fwrite("\x1A",1,1,m_pFile);
 
 //File Name
 _fstrcpy(m_strFile,pStr);
 //Malloc RecordBuf
 m_pRecordBuf = new BYTE;
 _fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
 //Malloc  Foxpro_Fields
 m_pFoxproFields = new FOXPRO_FIELDS;
 _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
 //Fill FoxproFields
 ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
 nFields = this->GetFieldsCount();
 for(int i=0;i<nFields;i++)
 {
 ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 }
 return(TRUE);
 }
 
 
 BOOL  CFoxpro::OpenFoxpro(const char* pStr)
 {
 if (m_pFile != NULL)
 {
 return(FALSE);
 }
 
 CoFoxpro();
 
 if (!(m_pFile = fopen(pStr,"r+b")))
 {
 return(FALSE);
 }
 
 long  lFileLength = filelength(fileno(m_pFile));
 if(lFileLength<1L*sizeof(FOXPRO_HEAD)+2)
 {
 ::fclose(m_pFile);
 m_pFile=NULL;
 return(FALSE);
 }
 
 rewind(m_pFile);
 fread(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
 //Flags
 if(m_FoxproHead.byFlags!=0x03 && m_FoxproHead.byFlags!=0xF5)
 {
 ::fclose(m_pFile);
 m_pFile=NULL;
 return(FALSE);
 }
 
 BYTE nCh=0;
 fseek(m_pFile,-1,SEEK_END);
 fread(&nCh,1,1,m_pFile);
 // End Is 0x1A?
 if(nCh!=0x1A)
 {
 fclose(m_pFile);
 m_pFile=NULL;
 return(FALSE);
 }
 //---------------------------
 //File Name
 _fstrcpy(m_strFile,pStr);
 //Malloc Record Buffer
 m_pRecordBuf = new BYTE;
 if (m_pRecordBuf == NULL)
 {
 fclose(m_pFile);
 m_pFile=NULL;
 
 return (FALSE);
 }
 _fmemset(m_pRecordBuf,0,this->GetRecordLength()+1024);
 //Malloc  Foxpro_Fields
 m_pFoxproFields = new FOXPRO_FIELDS;
 if (m_pFoxproFields == NULL)
 {
 delete m_pRecordBuf;
 m_pRecordBuf = NULL;
 
 fclose(m_pFile);
 m_pFile=NULL;
 
 return (FALSE);
 }
 
 _fmemset(m_pFoxproFields,0,sizeof(FOXPRO_FIELDS)*(1+this->GetFieldsCount()));
 //Fill FoxproFields
 ::fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
 int nFields = this->GetFieldsCount();
 for(int i=0;i<nFields;i++)
 {
 ::fread(&m_pFoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 }
 return(TRUE);
 }
 
 BOOL  CFoxpro::CloseFoxpro()
 {
 if (NULL != m_pFile)
 {
 fclose(m_pFile);
 }
 m_pFile = NULL;
 
 DELETE(m_pRecordBuf);
 DELETE(m_pFoxproFields);
 
 return(TRUE);
 }
 
 BOOL  CFoxpro::AddFields(const char* strName,BYTE byStyle,int nLength,int nDot)
 {
 if(!m_pFile) return(FALSE);
 
 if(byStyle=='C')      {nDot = 0;}
 else if(byStyle=='N') {}
 else if(byStyle=='D') {nLength = 8;nDot    = 0;}
 else if(byStyle=='L') {nLength=1;nDot   =0;}
 else if(byStyle=='M') {nLength = 10;nDot    = 0;}
 else {return(0);}
 
 _fmemset(&m_FoxproFields,0,sizeof(FOXPRO_FIELDS));
 //----------------------------------------------------
 if(byStyle=='M')
 {
 m_FoxproHead.byFlags=0xF5;
 fseek(m_pFile,0,SEEK_SET);
 fwrite(&m_FoxproHead  ,sizeof(FOXPRO_HEAD)  ,1,m_pFile);
 }
 //Calc Fields
 int nFields=(m_FoxproHead.wRecordAddress-sizeof(FOXPRO_HEAD))/sizeof(FOXPRO_FIELDS);
 //Modify Head
 date mDate;
 ::getdate(&mDate);
 m_FoxproHead.byDay          = (BYTE)mDate.da_day;
 m_FoxproHead.byMonth        = (BYTE)mDate.da_mon;
 m_FoxproHead.byYear         = (BYTE)(WORD)(mDate.da_year-1900);
 m_FoxproHead.wRecordAddress+= sizeof(FOXPRO_FIELDS);
 m_FoxproHead.wRecordLength += (WORD)nLength;
 //Write Head Again
 fseek(m_pFile,0,SEEK_SET);
 fwrite(&m_FoxproHead,sizeof(FOXPRO_HEAD),1,m_pFile);
 //
 int nFieldsAddress = 1;
 fseek(m_pFile,sizeof(FOXPRO_HEAD),SEEK_SET);
 for(int i=0;i<nFields;i++)
 {
 ::fread(&m_FoxproFields,sizeof(FOXPRO_FIELDS),1,m_pFile);
 nFieldsAddress+=m_FoxproFields.byLength;
 }
 //Fill in Field
 if (::_fstrlen(strName) < 10)
 {
 ::_fstrcpy((char*)&m_FoxproFields.strName,(char*)strName);
 }
 else
 {
 ::_fmemcpy((BYTE*)&m_FoxproFields.strName, (char*)strName,
 
 
 
 |