2010-11-19 3 views
1

저는 최근 델피에서 programm를 시작했습니다.델파이 텍스트 파일이 비어 있습니다.

이제 운동이 있습니다.

텍스트 파일에 최고 점수를 저장해야합니다. 나는이 기능을 가지고 :

{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

Delphi 6에는 TStringList.CustomSort가 있습니까? 그렇다면, 자신의 정렬 루틴을 작성하고이를 사용하여 StringList를 정렬하십시오.

0

당신은 단순히 TStringList를에게 일종의 자체를 할 수 있어야합니다. 즉 :

outputSL.Sorted : = true;

관련 문제