Registriert seit: 26. Nov 2007
14 Beiträge
|
Problem mit dem Speichern von Records
26. Nov 2007, 20:23
Hallo Leute!
Ich sitze schon fast den ganzen Mittag an meinem Programm zur Verwaltung von Kontakten. Hedoch komm ich mit dem Speichern und VORALLEM mit dem auslesen nicht klar. Wenn ich auslese und versuche den ausgelesenen Inhalt anzuzeigen passiert nichts.
Hier mal der code:
Delphi-Quellcode:
type TMensch= record name,vname,tel,handy,email,ort,strasse,post,icq:string[100];
end;
var typ:array of TMensch;
i:integer;
procedure LoadFromFile(Source: string);
var f: file of TMensch;
m: Cardinal;
begin
m := 0;
try
assignFile(f, Source);
reset(f);
SetLength(typ, FileSize(f));
while not eof(f) do
begin
read(f, Typ[m]);
Inc(m);
end;
finally
closeFile(f);
i:=m;
end;
end;
procedure SaveToFile(Dest: string);
var f: file of TMensch;
m: Cardinal;
begin
try
assignFile(f, Dest);
reWrite(f); //oder reset(f)
for m := low(typ) to high(typ) do
write(f, typ[m]);
finally
closeFile(f);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Loadfromfile('Kontakte.dat');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
d,a:integer;
begin
a:=0;
if i=0 then i:=1;
setlength(typ,i);
with typ[i-1] do begin
name:=Edit2.text;
vname:=Edit1.text;
Ort:=Edit4.text;
Handy:=Edit9.text;
Tel:=Edit8.text;
icq:=Edit7.text;
Strasse:=Edit5.text;
Post:=Edit3.text;
email:=Edit6.text;
end;
inc(i);
Form1.Leeren;
Edit1.SetFocus;
end;
procedure TForm1.Button2Click(Sender: TObject);
var s:integer;
begin
Listbox1.clear;
for s:=1 to i-1 do begin
with typ[s-1] do begin
with listbox1.Items do begin
add('Vorname: '+vname);
add('Name: '+name);
add('Adresse: ');
add('Postleitzahl: '+post);
add('Ort: '+ort);
add('Straße: '+strasse);
add('Kontaktinformationen: ');
add('E-Mail: '+email);
add('ICQ: '+icq);
add('Telefon: '+tel);
add('Handy: '+handy);
add('------------------------------------------------------');
end;
end;
end;
end;
procedure TForm1.Leeren;
var a:integer;
begin
for a := 1 to 9 do begin
with TEdit(findcomponent('Edit'+inttostr(a))) do
text := '';
end;
end;
procedure TForm1.Restart1Click(Sender: TObject);
var t:file of TMensch;
k:file;
g:integer;
begin
Listbox1.clear;
Form1.Leeren;
Edit1.SetFocus;
i:=1;
assignfile(t,'Kontakte.dat');
rewrite(t);
try
for g:=low(typ) to high(typ) do
write(t,typ[g]);
finally Closefile(t);
end;
assignfile(k,'Anzahl.dat');
rewrite(k,inttostr(i));
closefile(k);
end;
procedure TForm1.Ende1Click(Sender: TObject);
var t:file of Tmensch;
g:integer;
begin
savetofile('Kontakte.dat');
close;
end;
procedure TForm1.Button3Click(Sender: TObject);
var a:integer;
begin
Listbox1.clear;
if radiobutton1.Checked then for a:=low(typ) to high(typ) do
if typ[a].name=Edit10.Text then
begin
with typ[a] do begin
with listbox1.Items do begin
...
end;
end;
end;
if radiobutton2.Checked then for a:=low(typ) to high(typ) do
if typ[a].vname=Edit10.Text then
begin
with typ[a] do begin
with listbox1.Items do begin
...
end;
end;
end;
if radiobutton3.Checked then for a:=low(typ) to high(typ) do
if typ[a].post=Edit10.Text then
begin
with typ[a] do begin
with listbox1.Items do begin
...
end;
end;
end;
end;
Was mach ich da falsch?
mfg
Damaster
|
|
Zitat
|