2010-11-19 18 views
1

Son zamanlarda delphi'de programlamaya başladım.Delphi textfile boş

Şimdi bir alıştırma programım var.

Metin dosyasında en yüksek puanı kaydetmem gerekiyor. Ben bu işlevi var:

{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; 

girişi (scorelijst/lijst1):

test,2,10 
test,3,11 

Şimdi, metin dosyasında doğru yerde, yeni bir üst puanı sıralamak istiyorum. Ancak çıktı boş ... Neyi yanlış yapıyorum?

Yorumlar bunun için Hollandaca, özür dileriz.

TArray = array of string;

cevap

2

Delphi 6'da TStringList.CustomSort var mı? Öyleyse, kendi sıralama rutini oluşturun ve StringList öğesini sıralamak için bunu kullanın.

0

Sadece TStringList sıralama kendisi bırakmalıyız. i.e:

çıkışSL.Sorted: = true;