int iFileHandle;
  int iFileLength;
  char *pszBuffer;
  Lines->Clear();
  try
    { //=======将文件读入pszBuffer字符串中
      iFileHandle = FileOpen(FileName, fmOpenRead);
      iFileLength = FileSeek(iFileHandle,0,2);
      FileSeek(iFileHandle,0,0);
      pszBuffer = new char[iFileLength+1];
      FileRead(iFileHandle, pszBuffer, iFileLength);
      FileClose(iFileHandle);
      //=======查找标志
      for( int i=0;i<=iFileLength+1;i++ )
        {
        if( pszBuffer[i] == 0x0b && \
            pszBuffer[i+1] == 0x00 && \
            pszBuffer[i+2] == 0x00 && \
            pszBuffer[i+3] == 0x00 && \
            pszBuffer[i+4] == 0x00 && \
            pszBuffer[i+5] == 0x00 && \
            pszBuffer[i+6] == 0x00 && \
            pszBuffer[i+7] == 0x00 && \
            pszBuffer[i+8] == 0x1e && \
            pszBuffer[i+9] == 0x10 && \
            pszBuffer[i+10] == 0x00 && \
            pszBuffer[i+11] == 0x00 )
                {
                int h=(int)pszBuffer[i+12]; 
                i=i+16;  
                for( int j=1;j<=h;j++)
                        {
                        char *TableName=new char[i];
                        strncpy(TableName,&pszBuffer[i+4],(int)pszBuffer[i]);
                        Lines->Add(TableName);
                        delete [] TableName;
                        i=i+(int)pszBuffer[i]+4;   
                        }
                }
        }        delete [] pszBuffer;
   }

解决方案 »

  1.   

    function GetTableName(strFileName: String):TStringList;
    var
    i: Integer;
      S: TStringList;
      tmp: String;
      h,j: Integer;
      TableName: String;
    begin
      try
       try
        Result := TStringList.Create;
         S := TStringList.Create;
         S.LoadFromFile(strFileName);
          i := 0;
          while i <= Length(S.Text) do begin
           tmp := S.Text;
            if( Word(tmp[i]) = $B ) and
               ( Word(tmp[i+1]) = $00 ) and
               ( Word(tmp[i+2]) = $00 ) and
               ( Word(tmp[i+3]) = $00 ) and
               ( Word(tmp[i+4]) = $00 ) and
               ( Word(tmp[i+5]) = $00 ) and
               ( Word(tmp[i+6]) = $00 ) and
               ( Word(tmp[i+7]) = $00 ) and
               ( Word(tmp[i+8]) = $1e ) and
               ( Word(tmp[i+9]) = $10 ) and
               ( Word(tmp[i+10]) = $00 ) and
               ( Word(tmp[i+11]) = $00  )
             then begin // found flag
    h := Word(tmp[i+12]);
                i := i + 16;
                for j:=1 to h do begin
                  TableName := Copy(tmp,i+4,Word(tmp[i]));
                  Result.Add(TableName);
                  i := i + Word(tmp[i]) + 4;
                end;
    end
            else
             Inc(i);
          end;
       finally
         if Assigned(S) then S.Free;
          if Assigned(Result) then Result.Free;
       end;
    except
       Result := nil;
      end;
    end;
      

  2.   

    对了把这句:
    while i <= Length(S.Text) do begin
           tmp := S.Text;
    换成这句:
           tmp := S.Text;
    while i <= Length(S.Text) do begin