Autor Beitrag
z1dirk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Di 30.09.03 15:39 
Hi ich möchte einträge ungeordnet in einer ...dat abspeichern und die geordnete Reinfolge in einer ...idx. Doch es kommen imer wieder fehler auf. Schaut euch das mal an und gibt mir einen tip. danke.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
type
  Tindex=record
      nr:integer;
      end;
  Ttest=record
      name:string[30];
      end;

procedure TForm1.Button1Click(Sender: TObject);
var
test: file of Ttest;
artikel1,artikel2:Ttest;
index:file of Tindex;
indexartikel:Tindex;
i,erg,a:integer ;

begin
assignfile(test,'test.dat');
assignfile(index,'index.idx');

if not fileexists('test.dat') then rewrite(test)else reset(test);
if not fileexists('index.idx') then rewrite(index)else reset(index);

seek(test,filesize(test));
artikel1.name:=edit1.text;
write(test,artikel1);

if filesize(index)=0 then begin
indexartikel.nr:=0;
write(index,indexartikel);
end else begin



 i:=0;
 repeat
 seek(index,i);
 read(index,indexartikel);
 seek(test,indexartikel.nr);
 read(test,artikel2);
 i:=i+1;
 erg := ansicomparestr(artikel1.name,artikel2.name);
 until (erg<=0) or (i=filesize(index));

 if i=filesize(index) then begin
  seek(index,filesize(index));
  indexartikel.nr:=filesize(test)-1;
  write(index,indexartikel);
 end else begin
  a:=filesize(index)-1;
  i:=i-1;
  repeat
  seek(index,a);
  read(index,indexartikel);
  write(index,indexartikel);
  a:=a-1;
  until a=i;
  seek(index,i);
  indexartikel.nr:=filesize(test)-1;
  write(index,indexartikel);
 end;

end;

closefile(index);
closefile(test);

end;


Die Einträge sollen immer gleich richtig sortiert werden.
maze2k
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 252

WIN 95, WIN NT 4.0, WIN 98, WIN 98SE, WIN 2000, RedHat Linux 7.3, Mandrake Linux 9.2, Knoppix Linux 3.3
D6 Pers
BeitragVerfasst: Di 30.09.03 17:34 
Wäre hilfreich, wenn du uns sagen könntest, was für Fehler auftreten...

_________________
Wer das Konzept der Unendlichkeit verstehen will, muss nur das Ausmaß menschlicher Dummheit betrachten. (Voltaire)
z1dirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Di 30.09.03 18:46 
Hi, die fehler sind das manche einträge zweimal drin sind in der index und dafür ein anderer fehlt. so in dieser art.
(test.dat : a,b,e,h,d ; nach index a,b,d,d,h) nur mal so zum beispiel