Delphi文件文件为空

时间:2010-11-19 15:47:05

标签: delphi sudoku delphi-6

我最近开始在delphi中编程。

现在,我有一个练习。

我必须在文本文件中保存最高分。 我有这个功能:

{Voeg topscore toe aan het goede bestand.}
function addTopScore(sudokuNumber : Integer; naam : String; tijd : Integer; fouten : Integer):boolean;
var
  buffer : TStringList;
  aantal, aantal2, aantal3, i, i2, i3 : Integer;
  scoreArray : array of TArray;
  sameScoreArray : array of TArray;
  plaatsScoreArray : array of Integer;
  inputS1 : String;
  zelfde, stopChecking : boolean;
  insertBefore : Integer;
  outputSL : TStringList;
  outputNR : Integer;
begin
  {Haal de topscores op}
  buffer := TStringList.Create;
  buffer.LoadFromFile('scorelijst/lijst' + IntToStr(sudokuNumber));
  {Initialiseer variabelen}
  aantal  := 0;
  aantal3 := 0;
  aantal  := (buffer.Count - 1);
  zelfde := False;
  result := True;
  {Vul de score array (TStringList to Array)}
  for i := 0 to aantal do
  begin
    SetLength(scoreArray, i + 1);
    inputS1 := buffer[i];
    scoreArray[i] := Unit2.explode(',', inputS1, 0);
  end;

  {Controleer waar hij moet worden ingevoerd}
  insertBefore := 0;
  stopChecking := False;
  for i2 := 0 to aantal do
  begin
    {Als er al een punt is gevonden, hoeft niet meer gecontroleerd te worden}
    if(stopChecking = False) then
    begin
      {Als er een score van dezelfde persoon beter is, moet het result false zijn}
      if (StrToInt(scoreArray[i2][1]) < fouten) AND (scoreArray[i2][1] = naam) then
      begin
        result := False;
      end;

      {Als het aantal fouten, hetzelfde is als de huidige waarde, sla de positie op}
      if ( StrToInt(scoreArray[i2][1]) = fouten) then
      begin
        {aantal zelfde waarden + 1}
        aantal3 := aantal3 + 1;

        {Geef de arrays de goede lengte}
        SetLength(sameScoreArray, aantal3);
        SetLength(plaatsScoreArray, aantal3);

        {Vul de arrays}
        sameScoreArray[(aantal3 - 1)] := scoreArray[i2];
        plaatsScoreArray[(aantal3 - 1)] := i2;

        {Er is een zelfde waarde gevonden.}
        zelfde := True;
      end;

      {Als het aantal fouten groter is, dan de nieuwe}
      if ( (StrToInt(scoreArray[i2][1]) > fouten ) = True)  then
      begin
        {Stop de for loop checking}
        stopChecking := True;

        {Als er geen zelfde waarde is gevonden, moet hij voor deze i2 worden ingevoerd}
        if (zelfde = False) then
          insertBefore := i2;
      end;
    end;
  end;

  outputSL := TStringList.Create;
  if (insertBefore > 0) then
  begin
    outputNR := 0;
    for i3 := 0 to aantal do
    begin
      if ( i3 = insertBefore ) then
      begin
        outputSL[outputNR] := naam + ',' + IntToStr(fouten) + ',' + IntToStr(tijd);
        outputNR := outputNR + 1;
      end;

      outputSL[outputNR] := scoreArray[i3][0] + ',' + scoreArray[i3][1] + ',' + scoreArray[i3][2];
      outputNR := outputNR + 1;
    end;
  end
  else if (zelfde = True) then
  begin
    //Not finished.
  end;

  outputSL.SaveToFile('scorelijst/lijst' + IntToStr(sudokuNumber));
end;

输入(scorelijst / lijst1):

test,2,10
test,3,11

现在,我想在文本文件的正确位置对新的最高分进行排序。 但是,输出是空的...... 我做错了什么?

评论是荷兰语,对不起。

TArray = array of string;

2 个答案:

答案 0 :(得分:2)

Delphi 6是否有TStringList.CustomSort?如果是这样,创建自己的排序例程并使用它来对StringList进行排序。

答案 1 :(得分:0)

你应该简单地让TStringList自行排序。即:

outputSL.Sorted:= true;

相关问题