Autor Beitrag
roka6803
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50


Delphi 5 Ent. & Delphi 7
BeitragVerfasst: Do 10.11.05 16:32 
Hallo alle zusammen,

ich habe ein Problem ein Array aus Records in eine (typisierte) Datei zu speichern: Es funzt nicht !

Ich habe ein Record und ein Array "getyped" und bei den Variablen ein Array of "getyptes Array" deklariert.

Wenn ich über Button1 das Array "Array[1].Wert" fülle geht das auch, nur bei der Prozedur zum speichern über Button2, zeigt er mir bereits beim compilieren einen Fehler an.

Hier mein gesamter Quelltext meiner ersten und einzigsten Unit:

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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

//---------------------------------------------------> "getyptes" Record
type
  waffen = record
    ID : Integer;
    Klasse : String[10];
    Name : String[50];
    MinDam : Integer;
    MaxDam : Integer;
    LvL_require : Integer;
  end;

//---------------------------------------------------> "getyptes" Array
type
  waffen_array = array[1..1000] of waffen;

var
  Form1: TForm1;
  array_waffen : waffen_array; //--> Array (als Variable)



implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
array_waffen[1].ID := 1;
array_waffen[1].Klasse := 'Schwert';
array_waffen[1].Name := 'Schwert';
array_waffen[1].MinDam := 1;
array_waffen[1].MaxDam := 3;
array_waffen[1].LvL_require := 1;
end;


//----------------------------------------------------------> den Kram speichern
procedure TForm1.Button2Click(Sender: TObject);
var  
  datei : File of waffen;
begin
  AssignFile(datei, (ExtractFilePath(ParamStr(0)) + 'test.dat'));

  {if FileExists('test.dat') then ReSet(datei)
  else ReWrite(datei);}


  ReSet(datei);
  Write(datei, array_waffen); //<--- Hier zeigt er mir den Fehler an, dass
  CloseFile(datei);           //     der 'Bezeichner' 'array_waffen' unbekannt sei

end;

end.


Was muss ich ändern um die Inhalte des Arrays "array_waffen" in eine (typisierte) Datei speichern zu können ?


Ich hoffe meine Erklärungen sind verständlich. Freue mich über jede (hilfreiche) Antwort.

MfG roka6803

_________________
Signatur? Was ist das? Brauch ich nicht...
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Do 10.11.05 17:02 
Da es sich bei Waffenarray vom Typ her um ein Array handelt und nicht um Waffen gibt es natürlich ein Problem.
Du must in einer Schleife dein Array durchlaufen und jede Waffe einzelnt in eine Datei speichern.

Im Übrigen sollten Typen ja mit einem T beginen und OOP lege ich dir auch ans Herz ;)
roka6803 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50


Delphi 5 Ent. & Delphi 7
BeitragVerfasst: Do 10.11.05 17:08 
Ich fände es super, wenn du mal 'nen Code-Beispiel hättest. Pseudo-Code wär auch voll in Ordnung...

mfg roka6803

_________________
Signatur? Was ist das? Brauch ich nicht...
Waldheini
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 32

Win 98SE, XP
D5 St., K3 Prof
BeitragVerfasst: Do 10.11.05 22:49 
Im Grunde eigentlich ganz einfach:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button2Click(Sender: TObject);
var
  datei : File of waffen;
  I: Integer;
begin
  AssignFile(datei, (ExtractFilePath(ParamStr(0)) + 'test.dat'));


  {if FileExists('test.dat') then ReSet(datei)
  else ReWrite(datei);}



  ReWrite(datei);
  for I:= 1 to 1000 do                     // die Schleife so oft durchlaufen, wie
     Write(datei, array_waffen[I]);        // Elemente im Array enthalten sind
  CloseFile(datei);


einfacher ist es allerdings, da Du kein variables Array benutzt, die Dateitypisierung zu ändern:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button2Click(Sender: TObject);
var
  datei : File of waffen_array;
  I: Integer;
begin
  AssignFile(datei, (ExtractFilePath(ParamStr(0)) + 'test.dat'));


  {if FileExists('test.dat') then ReSet(datei)
  else ReWrite(datei);}



  ReWrite(datei);
  Write(datei, array_waffen);
  CloseFile(datei);
roka6803 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50


Delphi 5 Ent. & Delphi 7
BeitragVerfasst: Do 10.11.05 23:37 
Cool, das ist doch mal was "greifbares". Vielen Dank. Werde es ausprobieren.

MfG roka6803

_________________
Signatur? Was ist das? Brauch ich nicht...