Autor Beitrag
SiH
Hält's aus hier
Beiträge: 8



BeitragVerfasst: Mo 17.09.07 17:57 
Hallöchen!

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:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
unit Unit1;


interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    ed_e_album: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    ed_e_int: TEdit;
    Label4: TLabel;
    ed_e_preis: TEdit;
    bt1_speichern: TButton;
    bt2_add: TButton;
    ListBox1: TListBox;
    bt3_laden: TButton;
    procedure FormCreate(Sender: TObject);
    procedure bt1_speichernClick(Sender: TObject);
    procedure bt2_addClick(Sender: TObject);
    procedure bt3_ladenClick(Sender: TObject);
  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const n = 10;

type Tcd = record
     album,int,preis:string[200];

     end;
Type Tfeld = array[1..n] of Tcd;

var cd:Tfeld;
     y:integer;

procedure TForm1.FormCreate(Sender: TObject);
var x: integer;
begin
for x:=1 to n do
cd[x].album:='';
cd[x].int:='';
cd[x].preis:='';
y:=0;
end;

procedure TForm1.bt1_speichernClick(Sender: TObject);
var i:integer;
    cddatei: File of Tcd;
    s:string;

begin
if inputquery('Dateiname','Dateiname',s) = true then
   begin
   assignfile(cddatei,s);
   rewrite(cddatei,s);
    for i:=1 to n do
    write(cddatei,cd[i])
    end
    else
    closefile(cddatei);
end;
   procedure TForm1.bt2_addClick(Sender: TObject);
begin
inc(y);
cd[y].album:=ed_e_album.text;
cd[y].int:=ed_e_int.text;
cd[y].preis:=ed_e_preis.text;
ListBox1.items.add(inttostr(y)+' '+ed_e_album.text);
end;

procedure TForm1.bt3_ladenClick(Sender: TObject);
var cddatei: File of Tfeld;
        cd2: Tfeld;
          i,b:integer;
          s:string;
begin
if inputquery('Dateiname angeben','Dateiname angeben',s) = true then
 begin
 i:=0;
 assignfile(cddatei,s);
  repeat
  inc(i);
  read(cddatei,cd2);
  until EOF(cddatei);
  closefile(cddatei);
 end
else
exit;
end;
end.


Ich sitze schon ne ganze Weile an diesem Programm.
Wenn ich eine Datei Laden möchte, kommt in der Zeile "closefile(cddatei);" die Fehlermeldung

user defined image

Das "Warum" versteh ich bloß nicht so ganz...
Hoffentlich kann mir jemand helfen!
MfG SiH

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Mo 17.09.07 18:46 
Alte Inka-Weisheit:
Wo nix Assigned da nix zu close :zwinker:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
if inputquery('Dateiname','Dateiname',s) = true then 
   begin 
   assignfile(cddatei,s); 
   rewrite(cddatei,s); 
    for i:=1 to n do 
    write(cddatei,cd[i]) 
    end 
    else 
    closefile(cddatei); 
end;


Wäre dir vielleicht aufgefallen, wenn du besser einrücken würdest:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if inputquery('Dateiname','Dateiname',s) = true then 
   begin 
     assignfile(cddatei,s); 
     rewrite(cddatei,s); 
       for i:=1 to n do 
         write(cddatei,cd[i]) 
   end else closefile(cddatei);


Gruß

Calculon
--