Einzelnen Beitrag anzeigen

Pitti911

Registriert seit: 28. Jan 2009
22 Beiträge
 
#6

Re: Speichern Von daten aus einem array endet in leerer Date

  Alt 30. Jan 2009, 14:47
mh gleiches Programm neuer Quelltext (leicht abgeändert weil der Bequemlichkeit halber soll ein text aus nem Post der das entsprechende Format hat nur noch in ein Memo kopiert werden müssen)

aber es soll auch ne "botliste erstellt werden" das einlesen in die datei "hunter.dat" funktioniert aus dem Memo raus wunderbar aber das erstellen der botliste liefert immer wieder einen Fehler und zwar sowas: "" ist kein gültiger integer

hier der quelltext der Funktion:
Code:
procedure TForm1.Button1Click(Sender: TObject);
Var users: file Of Thunter;
    hilf: array of Thunter;
    Bots: file of Tbot;
    bot:array of Tbot;
    tmpbot: Tbot;
    tmp: Thunter;
    c:boolean;
    i,j,p:integer;
    s,hs,hs2,hs3:string;
begin
  Button1.Enabled:=false;
  i:=0;
  c:=true;
  Try
  If memo1.Lines.Count=2 then //Beginn einlese algorythmus aus dem Memo
  Begin
    CopyFile('hunter.dat','hunterbackup.dat',False);
    tmp.Score:=0;
    tmp.Acc:='';
    tmp.Bots:='';
    hs:=memo1.lines[0];
    hs:=trim(hs);
    tmp.Acc:=hs;
    hs:=memo1.Lines[1];
    hs:=trim(hs);
    if hs[length(hs)]<>';' then
    hs:=hs+';';
    repeat
      hs:=trim(hs);
      p:=pos(' ',hs);
      hs2:=copy(hs,1,p-1);
      Delete(hs,1,p);
      tmp.Bots:=tmp.Bots+hs2;
      p:=pos(';',hs);
      hs2:=copy(hs,1,p-1);
      Delete(hs,1,p);
      hs2:=trim(hs2);
      tmp.Bots:=tmp.Bots+' '+hs2+';';
      tmp.Bots:=trim(tmp.Bots);
      case strtoint(hs2) of
         0..90:tmp.Score:=tmp.Score+1;
        91..94:tmp.Score:=tmp.Score+2;
        95..96:tmp.Score:=tmp.Score+4;
            97:tmp.Score:=tmp.Score+6;
            98:tmp.Score:=tmp.Score+10;
            99:tmp.Score:=tmp.Score+20;
      end;
    until hs='';
  end;
  //ende des einlese algorythmus in tmp
  Assignfile(Users,'Hunter.dat');
  if Fileexists('Hunter.dat') then
    Begin
      Reset(users);
      Setlength(hilf,Filesize(users)+1);
      seek(users,0);
      while not EOF(users) do
      Begin
        read(users,hilf[i]);
        inc(i);
      END;
      closefile(users);
      for i := 0 to high(hilf) do
      Begin
        hs:='';
        hs2:='';
        if AnsiLowercase(hilf[i].Acc)=AnsiLowercase(tmp.acc) then
          Begin
            c:=false;
            s:=hilf[i].bots;
            hs:=tmp.Bots;
            Repeat
              hs:=trim(hs);
              p:=pos(' ',hs);
              hs2:=copy(hs,1,p-1);
              Delete(hs,1,p);
              p:=pos(';',hs);
              hs3:=copy(hs,1,p-1);
              Delete(hs,1,p);
              hs3:=trim(hs3);
              if pos(hs2+' '+hs3,s)=0 then
              Begin
                s:=s+' '+hs2+' '+hs3+';';
                s:=trim(s);
              end
              Else
              Begin
                case strtoint(hs3) of
                   0..90:tmp.Score:=tmp.Score-1;
                  91..94:tmp.Score:=tmp.Score-2;
                  95..96:tmp.Score:=tmp.Score-4;
                      97:tmp.Score:=tmp.Score-6;
                      98:tmp.Score:=tmp.Score-10;
                      99:tmp.Score:=tmp.Score-20;
                end;
                ShowMessage('Bot: '+hs2+' '+hs3+#13#10+'has been hunted down already');
              end;
            until hs='';
            hilf[i].Bots:=s;
            hilf[i].Score:=hilf[i].Score+tmp.score;
          end
        ELSE
          if (i=high(hilf)) AND c then
          Begin
            hilf[i]:=tmp;
        end;
      end;
    AssignFile(users,'hunter.dat');
    Rewrite(users);
    sortierH(hilf);
    i:=0;
    while (i<=high(hilf)) do
      Begin
        if hilf[i].Acc<>'' then
        Write(users,hilf[i]);
        inc(i);
      end;
    closefile(users);
    end
  ELSE
  Begin
    i:=0;
    Rewrite(users);
    Write(users,tmp);
    Closefile(users);
    Memo1.Text:='';
  end;
  //botliste
  I:=0;
  AssignFile(bots,'bots.dat');
  if Fileexists('Hunter.dat') then
    Begin
      Reset(users);
      Setlength(hilf,Filesize(users));
      seek(users,0);
      while not EOF(users) do
      Begin
        read(users,hilf[i]);
        inc(i);
      END;
      Closefile(users);
    end;

  I:=0;
  if Fileexists('bots.dat') then
    Begin
      Reset(bots);
      Setlength(bot,Filesize(bots)+100);
      seek(bots,0);
      while not EOF(users) do         //DA IS EIN FEHLER -.- da mus bots hin xD
      Begin
        read(bots,bot[i]);
        inc(i);
      END;
      Closefile(bots);
    end
    ELSE Setlength(bot,500);
  I:=0;
  J:=0;
  Repeat
    c:=true;
    p:=pos(' ',hilf[i].Bots);
    tmpbot.Botname:=copy(hilf[i].Bots,1,p-1);
    Delete(hilf[i].Bots,1,p);
    hilf[i].Bots:=trim(hilf[i].bots);
    p:=pos(';',hilf[i].Bots);
    tmpbot.Botlvl:=strtoint(copy(hilf[i].Bots,1,p-1));
    j:=0;
    While (j<=high(bot)) AND c do
      Begin
        if (ansilowercase(bot[j].Botname)=ansilowercase(tmpbot.Botname)) And (Not (bot[j].Botname='')) then
        Begin
          c:=false;
          if tmpbot.Botlvl>bot[j].Botlvl then bot[j].Botlvl:=tmpbot.Botlvl;
        end
        ELSE
        Begin
          if c then
          Begin
            bot[j]:=tmpbot;
          end;
        end;
        inc(j);
      end;
    inc(i);
  until i=high(hilf);
  Application.ProcessMessages;
  Sortierb(bot);
  rewrite(bots);
  i:=0;
  while (i<=high(bot)) do
  Begin
    if bot[i].botname<>'' then Write(bots,bot[i]);
    inc(i);
  end;
  Closefile(bots);
  //ende Botliste
  Button1.Enabled:= true;
  Except
    showMessage('Fehleingabe bei den erlegten Bots! Bitte überprüfe das Format!!'+#13#10+'Es muss lauten:'+#13#10+'Bot1 Botlvl; Bot2 Botlvl;...;');
    CopyFile('hunterbackup.dat','hunter.dat',false);
    button1.enabled:=true;
    memo1.Text:='';
  end;
ich würd mich doch ungemein freuen wenn mir wieder so schnell und kompetent geholfen werden könnte
  Mit Zitat antworten Zitat