⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 很优秀的公交查询软件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
end;

procedure TForm1.FillRecord();
var
  iSpacePos, iStarPos: Integer;
  i: Integer;
  sLine, sCmdLine, sStation: String;
  sUpLine, sDownLine: String;
  pStation: ^StationRecordType;
  pLine: ^LineRecordType;
  iLineIndex, iStationIndex: Integer;
  iStationIndexInLine: Integer;
begin
//now analyze the line one by one
  lstStation.Clear;
  lstLine.Clear;
  meoResult.Clear;
  for i := 0 to meoLines.Lines.Count - 1 do
  begin
//trim the space
    sCmdLine := Trim(meoLines.Lines[i]);
//get line name
    iSpacePos := Pos(' ', sCmdLine);
    sLine := Copy(sCmdLine, 1, iSpacePos - 1);
    meoResult.Lines.Add(sLine);
//add the line to the lstLine, and got the line index
    New(pLine);
    pLine^.Line := sLine;
    pLine^.Dir := DIRUP;
    pLine^.Count := 0;
    iLineIndex := lstLine.Add(pLine);
//get up+down line string
    sCmdLine := Copy(sCmdLine, iSpacePos + 1, Length(sCmdLine));
    iSpacePos := Pos(' ', sCmdLine);
//split the string to Up and Down line string    
    sUpLine := Copy(sCmdLine, 1, iSpacePos - 1);
    sUpLine := Trim(sUpLine);
    sUpLine := sUpLine + '*';
    sDownLine := Copy(sCmdLine, iSpacePos + 1, Length(sCmdLine));
    sDownLine := Trim(sDownLine);
    sDownLine := sDownLine + '*';
    meoResult.Lines.Add(sUpLine);
    meoResult.Lines.Add(sDownLine);
//analyze the Up line
    iStationIndexInLine := -1;
    iStarPos := Pos('*', sUpLine);
    while (0 <> iStarPos) do
    begin
      Inc(iStationIndexInLine);
      sStation := Copy(sUpLine, 1, iStarPos - 1);
      sUpLine := Copy(sUpLine, iStarPos + 1, Length(sUpLine));
      meoResult.Lines.Add(sStation);
      iStarPos := Pos('*', sUpLine);

//now we got station in sStation var, do with it
      iStationIndex := getStationIndexFromlst(lstStation, sStation);
      if ($FFFF = iStationIndex) then
      begin
//no found the station, insert one, and got the index
        New(pStation);
        pStation^.Station := sStation;
        pStation^.Count := 0;
        iStationIndex := lstStation.Add(pStation);
      end else begin
//found the station
      end;
//add data to Station table      
      pStation := lstStation.Items[iStationIndex];
      pStation^.Count := pStation^.Count + 1;
      pStation^.LineData[pStation^.Count - 1].Index := iLineIndex;
      pStation^.LineData[pStation^.Count - 1].Dir := DIRUP;
      pStation^.LineData[pStation^.Count - 1].StationIndex := iStationIndexInLine;
//now add the line table
      pLine^.Count := iStationIndexInLine + 1;
      pLine^.LineData[pLine^.Count - 1] := iStationIndex;
    end;
  pLine^.Count := iStationIndexInLine + 1;
  
//analyze the Down line
//add the line to the lstLine, and got the line index
    New(pLine);
    pLine^.Line := sLine;
    pLine^.Dir := DIRDOWN;
    pLine^.Count := 0;
    iLineIndex := lstLine.Add(pLine);
    iStationIndexInLine := -1;
    iStarPos := Pos('*', sDownLine);
    while (0 <> iStarPos) do
    begin
      Inc(iStationIndexInLine);
      sStation := Copy(sDownLine, 1, iStarPos - 1);
      sDownLine := Copy(sDownLine, iStarPos + 1, Length(sDownLine));
      meoResult.Lines.Add(sStation);
      iStarPos := Pos('*', sDownLine);

//now we got station in sStation var, do with it
      iStationIndex := getStationIndexFromlst(lstStation, sStation);
      if ($FFFF = iStationIndex) then
      begin
//no found the station, insert one, and got the index
        New(pStation);
        pStation^.Station := sStation;
        pStation^.Count := 0;
        iStationIndex := lstStation.Add(pStation);
      end else begin
//found the station
      end;
//add data to Station table      
      pStation := lstStation.Items[iStationIndex];
      pStation^.Count := pStation^.Count + 1;
      pStation^.LineData[pStation^.Count - 1].Index := iLineIndex;
      pStation^.LineData[pStation^.Count - 1].Dir := DIRDOWN;
      pStation^.LineData[pStation^.Count - 1].StationIndex := iStationIndexInLine;
//now add the line table
      pLine^.Count := iStationIndexInLine + 1;
      pLine^.LineData[pLine^.Count - 1] := iStationIndex;
    end;
    pLine^.Count := iStationIndexInLine + 1;



  end;
end;

//load all record offset to list
procedure TForm1.LoadRecordEntryOffsetList;
var
  i: LongWord;
  iStartOffset, iOffset: Integer;
  pRecordEntryType: ^RecordEntryType;
  pStation: ^StationRecordType;
  pLine: ^LineRecordType;
  iRecordIndex: Integer;
begin
  lstRecordEntryOffset.Clear;
  iStartOffset := SizeOf(DatabaseHdrType) +
//SizeOf RecordListType
                    SizeOf(LongWord) + SizeOf(Word) +
                    SizeOf(RecordEntryType) * (1 + lstStation.Count + lstLine.Count) +
//                    SizeOf(Word);
                    0;
  iOffset := iStartOffset;
//这里可能id重复了
  iRecordIndex := $1001;

  New(pRecordEntryType);
  pRecordEntryType^.localChunkID := iOffset;
  pRecordEntryType^.attributes := $8E40;
  pRecordEntryType^.uniqueID := iRecordIndex;
  Inc(iRecordIndex);
  lstRecordEntryOffset.Add(pRecordEntryType);
//在这里把BaseRecordType的长度加上
  iOffset := iOffset + Length(brtDatabaseInfo.CityName) + 1
                     + Length(brtDatabaseInfo.ProviderID) + 1
                     + Length(brtDatabaseInfo.ProviderUpdateTime) + 1
                     + Length(brtDatabaseInfo.CreatorID) + 1
                     + Length(brtDatabaseInfo.CreatorUpdateTime) + 1
                     + Length(brtDatabaseInfo.CreatorMemo) + 1
                     + SizeOf(brtDatabaseInfo.Station)
                     + SizeOf(brtDatabaseInfo.Line);

  for i := 0 to lstStation.Count - 1 do
  begin
    New(pRecordEntryType);
    pRecordEntryType^.localChunkID := iOffset;
    pRecordEntryType^.attributes := $8E40;
    pRecordEntryType^.uniqueID := iRecordIndex;
    Inc(iRecordIndex);
    lstRecordEntryOffset.Add(pRecordEntryType);
    pStation := lstStation.Items[i];
    iOffset := iOffset
                  + Length(pStation^.Station) + 1
                  + SizeOf(pStation^.Count)
                  + pStation^.Count * SizeOf(LineData);
  end;
  for i := 0 to lstLine.Count - 1 do
  begin
    New(pRecordEntryType);
    pRecordEntryType^.localChunkID := iOffset;
    pRecordEntryType^.attributes := $8E40;
    pRecordEntryType^.uniqueID := iRecordIndex;
    Inc(iRecordIndex);
    lstRecordEntryOffset.Add(pRecordEntryType);
    pLine := lstLine.Items[i];
    iOffset := iOffset
                  + Length(pLine^.Line) + 1
                  + SizeOf(pLine^.Dir)
                  + SizeOf(pLine^.Count)
                  + pLine^.Count * SizeOf(Word);
  end;
end;


procedure TForm1.AllTablesSaveToFile;
var
  i, j: LongWord;
  pStation: ^StationRecordType;
  pLine: ^LineRecordType;
  iSize: LongWord;
  pRecordEntryType: ^RecordEntryType;
  t: Word;
  tempC: Char;
begin
  tempC := Chr(0);
//write the offset
  for i := 0 to lstRecordEntryOffset.Count - 1 do
  begin
    pRecordEntryType := lstRecordEntryOffset.Items[i];
    pRecordEntryType^.localChunkID := htonl(pRecordEntryType^.localChunkID);
    pRecordEntryType^.attributes := pRecordEntryType^.attributes;
    pRecordEntryType^.uniqueID := htons(pRecordEntryType^.uniqueID);
    iSize := SizeOf(RecordEntryType);
    msFile.Write(pRecordEntryType^, iSize);
  end;

//把BaseRecordType数据写入
  msFile.Write(brtDatabaseInfo.CityName[1], Length(brtDatabaseInfo.CityName));
  msFile.Write(tempC, 1);
  msFile.Write(brtDatabaseInfo.ProviderID[1], Length(brtDatabaseInfo.ProviderID));
  msFile.Write(tempC, 1);
  msFile.Write(brtDatabaseInfo.ProviderUpdateTime[1], Length(brtDatabaseInfo.ProviderUpdateTime));
  msFile.Write(tempC, 1);
  msFile.Write(brtDatabaseInfo.CreatorID[1], Length(brtDatabaseInfo.CreatorID));
  msFile.Write(tempC, 1);
  msFile.Write(brtDatabaseInfo.CreatorUpdateTime[1], Length(brtDatabaseInfo.CreatorUpdateTime));
  msFile.Write(tempC, 1);
  msFile.Write(brtDatabaseInfo.CreatorMemo[1], Length(brtDatabaseInfo.CreatorMemo));
  msFile.Write(tempC, 1);

  brtDatabaseInfo.Station := htons(lstStation.Count);
  brtDatabaseInfo.Line := htons(lstLine.Count);

  msFile.Write(brtDatabaseInfo.Station, SizeOf(brtDatabaseInfo.Station));
  msFile.Write(brtDatabaseInfo.Line, SizeOf(brtDatabaseInfo.Line));

//写完
  meoResult.Clear;
  meoResult.Lines.Add(Format('%10s %16s %10s', ['Index', 'StationName', 'Count']));
  for i := 0 to lstStation.Count - 1 do
  begin
    pStation := lstStation.Items[i];
    meoResult.Lines.Add(Format('%10d %16s %10d', [i, pStation^.Station, pStation^.Count]));
    msFile.Write(pStation^.Station[1], Length(pStation^.Station));
    msFile.Write(tempC, 1);
    msFile.Write(pStation^.Count, SizeOf(pStation^.Count));
    for j := 0 to pStation^.Count - 1 do
    begin
      t := htons(pStation^.LineData[j].Index);
      msFile.Write(t, Sizeof(pStation^.LineData[j].Index));
      msFile.Write(pStation^.LineData[j].Dir, Sizeof(pStation^.LineData[j].Dir));
      msFile.Write(pStation^.LineData[j].StationIndex, Sizeof(pStation^.LineData[j].StationIndex));
    end;
  end;

  meoResult.Lines.Add(Format('%10s %16s %10s %10s', ['Index', 'Line', 'Dir', 'Count']));
  for i := 0 to lstLine.Count - 1 do
  begin
    pLine := lstLine.Items[i];
    meoResult.Lines.Add(Format('%10d %16s %10d %10d', [i, pLine^.Line, pLine^.Dir, pLine^.Count]));
    msFile.Write(pLine^.Line[1], Length(pLine^.Line));
    msFile.Write(tempC, 1);
    msFile.Write(pLine^.Dir, SizeOf(pLine^.Dir));
    msFile.Write(pLine^.Count, SizeOf(pLine^.Count));
    for j := 0 to pLine^.Count - 1 do
    begin
      t := htons(pLine^.LineData[j]);
      msFile.Write(t, Sizeof(Word));
    end;

  end;

end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -