我现在有个.lib文件里面存了公交查询系统的数据
数据表的形式是这样的:
1)线路序号:第0,1字节,0~19,超过20,说明此线路空。
2)线路名:第1,25字节:长度1字节,24字节名。
3)上行站的数量:第26,1字节,最多120个站。
4)下行站的数量:第27,1字节,最多120个站。
5)GPRS线路号:第28~31。4字节。前2字节为实际GPRS线路号,低位在前;后2字节作为扩展用
6)保留:第32~63,32字节。
7)上行站列表:第64~5823。每站48字节,120个站点,120*48=5760字节。
8)下行站列表:第5824~11583。5760字节。
上下行站列表记录结构:48字节
a.站名: 25字节:长度1字节,24字节名。
b.距离下站的距离: 2字节,单位米。低位在前。
c.进站经度坐标: 4字节。低位在前,最高字节方位角;剩余3字节是整数,实际数值为0.1秒。
d.进站纬度坐标: 4字节。低位在前,最高字节方位角;剩余3字节是整数,实际数值为0.1秒。
e.出站经度坐标: 4字节。低位在前,最高字节方位角;剩余3字节是整数,实际数值为0.1秒。
f.出站纬度坐标: 4字节。低位在前,最高字节方位角;剩余3字节是整数,实际数值为0.1秒。
g保留: 5字节。
我试过将文件里的内容读到缓冲区,但是里面却是一个二进制的数据流;
因为对这类文件的操作不了解,不知道里面的数据到底是什么形式,所以没法处理数据并存库(因为解析后的数据不可能只有1条记录,目前我遇到的麻烦就是怎样把文件里的数据解析成多记录的形式,这样才能处理数据),请高人指点.

解决方案 »

  1.   

    讀二進制或流文件操作(TMemoryStream),參考以下代碼procedure TRES_SOP_F.btnSB_SaveClick(Sender: TObject);
    var
      mss:TMemoryStream;
      imgg:TJPEGImage;
      Bmp:Tbitmap;
      Blob:TBlobField;
      iLoop,SopID:Integer;
      ss:TStrings;
    begin
      inherited;
      if qry_main.State in[dsinsert,dsedit] then
      begin
        IsRightSave:=True;
        ss:=TStringlist.Create;
        ss.Delimiter:=';';
        if cbb_Type.ItemIndex=0 then
        begin
          if FrmMsgBox('保存提示','你選擇的"制程類別"為共用料號,所以"機種編號"中的所有選擇料號將會新增,確定要保存嗎?',MsgBox_YESNO)=0 then
            Exit;
          Application.ProcessMessages;
          if IsGroupNoJZ then
            ss.DelimitedText:=cbb_Model_no.Text
          else
            ss.DelimitedText:=cbb_Model_nos.Text;
          qry_main.FieldByName('Model_no').AsString:=ss.Strings[0];
        end;    try
          if not IsSaveNew then
          begin
            RES_LOADING_F:=TRES_LOADING_F.Create(Self);
            RES_LOADING_F.Label1.Caption:='正在保存所有生成的數據......';
            RES_LOADING_F.Show;
            RES_LOADING_F.Update;
          end;
          if img1.Picture.Graphic<>nil then
          begin
            mss:=TMemoryStream.Create;
            imgg:=TJPEGImage.Create;
            Bmp:=TBitmap.Create;
            Blob:=TBlobField(qry_img.FieldByName('Images'));
            try
              Bmp.Assign(img1.Picture.Graphic);
              Bmp.Width:=640;
              Bmp.Height:=480;
              Bmp.PixelFormat:=pf32bit;
              Bmp.Canvas.StretchDraw(Bmp.Canvas.ClipRect,img1.Picture.Graphic);
              imgg.Assign(Bmp);
              imgg.SaveToStream(mss);
              //CompressBitmap(mss,clMax);
              Blob.LoadFromStream(mss);
            finally
              mss.Free;
              imgg.Free;
              Bmp.Free;
            end;
          end;
          SopID:=qry_main.fieldbyname('Sop_ID').AsInteger;
          qry_main.Post;
          if img1.Picture.Graphic<>nil then
          begin
            if qry_img.State in[dsinsert,dsedit] then
              qry_img.Post;
          end else
            qry_img.Cancel;
          if not qry_pn.IsEmpty then
          begin
            if (qry_pn.FieldByName('Seq').AsString<>'')and(qry_pn.FieldByName('PN').AsString<>'') then
            begin
              if qry_pn.State in[dsinsert,dsedit] then
                qry_pn.Post;
            end else
              qry_pn.Delete;
          end else
            qry_pn.Cancel;
          if cbb_Type.ItemIndex=0 then
          begin
            for iLoop:=0 to ss.Count-1 do
            begin
              if iLoop>0 then
              begin
                Inc(SopID);
                qry_op.Close;
                qry_op.SQL.Text:='insert into SOP_Main([SOP_ID],[Ver],[Model_no],[Model],[Routing_no],[Description],[Routing],[Process],[Station],[Type],[Owner]) select';
                qry_op.SQL.Add(''''+ IntToStr(SopID)+''' as [SOP_ID],[Ver],'''+ Trim(ss.Strings[iloop])+''' as [Model_no],[Model],[Routing_no],[Description]');
                qry_op.SQL.Add(',[Routing],[Process],[Station],[Type],[Owner] from SOP_Main where SOP_ID='''+qry_main.fieldbyname('SOP_ID').AsString+'''');
                qry_op.ExecSQL;
                qry_op.Close;
                qry_op.SQL.Text:='insert into SOP_IMG select '''+inttostr(SopID)+''' as SOP_ID,[Images] from SOP_IMG where SOP_ID='''+qry_main.fieldbyname('SOP_ID').AsString+'''';
                qry_op.ExecSQL;
                qry_op.Close;
                qry_op.SQL.Text:='insert into SOP_PN select '''+inttostr(SopID)+''' as SOP_ID,[Seq],[PN],[Description],[Pin_Count],[Qty],[YL],[Loc],[Std_Hr],[Tools],[Para],[PHRS],[Owner],[Valid_Date],[Void_Date],[ECN_no],[Nodes] from SOP_PN where SOP_ID='''+qry_main.fieldbyname('SOP_ID').AsString+'''';
                qry_op.ExecSQL;
              end;
            end;
          end;
          QryPNchangeDS(True,'');
          qry_main.Close;
          qry_main.Open;
          ChangeStatus(sBrowse);
        finally
          if not IsSaveNew then
            RES_LOADING_F.Close;
        end;
      end;
    end;
      

  2.   

    type
      FCardRec = Record
        ID : Word;
        Name : array[1..25] of AnsiChar;
        hQty : Byte;
        lQty : Byte;
        GPRSID : array[0..3] of ansichar;
        ..........
      end;這樣一個BUFFER就一個RECORD大小的去讀
      

  3.   

    用文件流读出,写入Access 的BOLB 字段里
      

  4.   

    注意从二进制文件定位读到缓冲区的时候,类型不要搞错,就是Long,Double,String这些,要不然读出的数据是错的
    分记录每条存入数据表,那就用循环了