Registriert seit: 30. Sep 2006
Ort: Gundelfingen
1.109 Beiträge
Delphi 2007 Professional
|
Re: Problem mit dem Speichern von Records
26. Nov 2007, 21:31
Hi
Du solltest dir mal angewöhnen deinen code zu formatieren (zB einrücken), dann fällt einem das debuggen viel einfacher.
Ich hab mal ein bisschen in deinem Code rumgeschrieben...
Delphi-Quellcode:
type
TMensch = record
name, vname, tel, handy, email,
ort, strasse, post, icq: string[100];
end;
var
typ: array of TMensch;
// ...
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);
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 := 0 to high(typ) do
write(f, typ[m]);
finally
closeFile(f);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
setlength(typ, Succ(Length(typ)));
with typ[high(typ)] 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;
Form1.Leeren;
Edit1.SetFocus;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
s: integer;
begin
Listbox1.clear;
for s := 0 to high(typ) do
with typ[s] and 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;
procedure TForm1.FormCreate(Sender: TObject);
begin
Loadfromfile('Kontakte.dat');
end;
procedure TForm1.Leeren;
var
a: integer;
begin
for a := 1 to 9 do
(FindComponent('Edit'+IntToStr(a)) as TEdit).text := '';
end;
procedure TForm1.Restart1Click(Sender: TObject); // Sinn ?!?
var
t: file of TMensch;
g: integer;
begin
Listbox1.clear;
Form1.Leeren;
Edit1.SetFocus;
try
assignfile(t, 'Kontakte.dat');
rewrite(t);
for g := 0 to high(typ) do
write(t, typ[g]);
finally
Closefile(t);
end;
end;
procedure TForm1.Ende1Click(Sender: TObject);
begin
savetofile('Kontakte.dat');
close;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
a: Integer;
begin
Listbox1.clear;
if radiobutton1.Checked then
for a := 0 to high(typ) do
if typ[a].name = Edit10.Text then
with typ[a] and listbox1.Items do
begin
// ...
end;
if radiobutton2.Checked then
for a := 0 to high(typ) do
if typ[a].vname = Edit10.Text then
with typ[a] and listbox1.Items do
begin
// ...
end;
if radiobutton3.Checked then
for a := 0 to high(typ) do
if typ[a].post = Edit10.Text then
with typ[a] and listbox1.Items do
begin
// ...
end;
end;
Dominik Wer anderen eine Grube gräbt, hat ein Gruben-Grab-Gerät!
|
|
Zitat
|