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



BeitragVerfasst: Di 26.08.03 23:30 
Mein Problem: Ich hab meine Unit1, mein normales Program, nun hab ich einen Dialog erzeugt, doch der hat eine eigene Unit2. Ich lass zwar die Unit2 in Unit1 eintragen, doch ich kann einfach auf keine proceduren oder variablen zugreifen. :x

Vieleicht helft ihr mir.

gruß dirk
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 27.08.03 01:03 
Die Prozeduren und Variablen aus Unit2 müssen im public Abschnitt oder global deklariert sein.
z1dirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Mi 27.08.03 19:50 
danke. :D
Mav
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Do 28.08.03 22:16 
Ich hab das Problem auch bei mir und wenn ich die Variablen global oder public deklariere, kann ich trotzdem nicht darauf zugreifen. :?:
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Fr 29.08.03 10:18 
Hast du deine Unit2 auch in die uses-Klausel der Unit1 geschrieben?

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Mav
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Fr 29.08.03 21:03 
Hust... :oops:
Habs heute schon von nem Kumpel erwaren.
Trotzdem danke. :D
eurohasi2
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 31.08.03 13:37 
:?:
also ich bin leider noch ein anfänger, drum versteh ich das noch ned ganz,

bei mir ist ein ähnliches problem, bei unit1 deklinier ich eine variable, und verändere sie in einer procedur, doch dann in unit2 gibt er den anfangswert aus, nicht den den ich der variablen in der procedur gegeben hab!

Könnt ihr mir bitte helfen ???[/delphi]
FeG
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 77

Win XP Home, SuSE Linux 8.2 Prof
D3 Prof, D7 Prof
BeitragVerfasst: So 31.08.03 15:04 
eurohasi2 hat folgendes geschrieben:
bei unit1 deklinier ich eine variable

"Deklarieren" heißt das... nur so nebenbei... :wink:

Bis du sicher, dass die procedure die Variable auch schon verändert hat und nicht erst danach aufgerufen wird??

MfG,
FeG
eurohasi2
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 31.08.03 15:54 
nein erst danach,

wenn ichs in der procedure formCreate machen, dann gehts, nicht aber bei einer prozedure später; meine frage ist: wie ich eine variable, in einer späteren prozedur, verändere und die dann in der unit2 so habe, nicht mit dem anfangswert ...
FeG
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 77

Win XP Home, SuSE Linux 8.2 Prof
D3 Prof, D7 Prof
BeitragVerfasst: So 31.08.03 16:49 
eurohasi2 hat folgendes geschrieben:
nein erst danach,

Ja dann ist klar, dass die Variable in dem Moment noch nicht verändert ist...
Zitat:
meine frage ist: wie ich eine variable, in einer späteren prozedur, verändere und die dann in der unit2 so habe, nicht mit dem anfangswert ...

Wenn du eine Variable veränderst, dann hat sie auch den veränderten Wert... wo ist dabei das Problem?

Bsp.:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var x: integer;

procedure TForm2.OnCreate(Sender: TObject);
begin
x:=1  //Anfangswert von x ist "1"
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
x:=2 //jetzt hat x den Wert "2"
end;

Wo ist da bitte das Problem?

Vielleicht postest du mal den Quellcode oder beschreibst dein Problem etwas genauer...

MfG,
FeG
eurohasi2
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: So 31.08.03 17:09 
Titel: der code:
ausblenden volle Höhe 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:
unit rundenspiel;
interface
uses
  //verkürzt
type
  TForm1 = class(TForm)Image19: TImage;

      private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  
eisen:integer=100;

implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);

begin

// lauter zeug ..

end;

procedure TForm1.Button1Click(Sender: TObject);
begin

eisen:= 200;
end;
end.


code unit2:


ausblenden volle Höhe 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:
unit Unit2;

interface

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

type
  TForm2 = class(TForm);

  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

uses rundenspiel;

{$R *.DFM}

procedure TForm2.FormCreate(Sender: TObject);
begin

label29.caption := inttostr(eisen);

end;
end.


so jetzt wird, wenn unit2 aufgerufen wird, nicht der wert von der 200 sondern 100 ausgegeben, wie mach ich das jetzt??

danke schon im voraus !
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Mo 01.09.03 01:04 
hallo eurohasi2!

das problem liegt darin, dass deine unit2 bereits beim programmstart erzeugt wird und sie in der procedure FormCreate den wert von eisen mit 100 vorbelegt. sie bekommt die änderung in der procedure TForm1.Button1Click gar nicht mit.

ich würde die globale variable eisen in die public-section von form1 übernehmen, denn so 'lose herumliegende variablen' verheissen nix gutes ;)

in unit2 würde ich der Form2 die methoden GetDaten und SetDaten vermachen - schliesslich sollte man OOP nicht aus den augen verlieren

zb rein schematisch, nur des prinzips wegen
ausblenden 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:
{$UNTESTED}
type 
  TForm2 = class(TForm); 

  private 
    { Private-Deklarationen } 
  public 
    { Public-Deklarationen } 
     procedure SetDaten(material: integer);
     function GetDaten: integer;
  end

procedure TForm2.SetDaten(material: integer); 
begin 
  label29.caption:= inttostr(material); 
end


function TForm2.GetDaten: integer; 
begin 
  try
    Result:= StrToInt(Edit1.Text);
  except
    Result:= -1;
  end;
end;


und der aufruf des dialoges könnte man dann so ähnlich gestalten

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  eisen:= 200; (wert zb aus einer berechnung, etc)
  with Form2 do begin
    SetDaten(eisen);
    ShowModal;
    if ModalResult= mrOk then
      eisen:= GetDaten
    else
      eisen:= 0;
    end;
end;


wo zeigst du form2 eigentlich an? ich hab weder ein show, noch ein showmodal entdecken können...

mfg, stefan
eurohasi2
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 01.09.03 10:36 
danke,
ich probiers grad aus ...

es funktion iert noch nicht ...

hier der code, vielleicht kannst du mir weiter helfen:


ausblenden 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:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
var
  Form1: TForm1;
  eisen:integer=100;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
  eisen:= 200; //(wert zb aus einer berechnung, etc)
  with Form2 do begin
    SetDaten(eisen);
    ShowModal;
    end;
end;
end.


unit2:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
unit Unit2;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TForm2 = class(TForm)
    Label29: TLabel;
  private
    { Private-Deklarationen }
  public
        procedure SetDaten(eisen: integer);
  end;
  var Form2: TForm2;
  implementation
procedure TForm2.SetDaten(eisen: integer);
begin
  label29.caption:= inttostr(eisen);
end;
end.

und projekt1:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.


er bringt den fehler:
"
In projekt1.exe ist eine exception der Klasse EResNotfound aufgetreten Meldung: Ressorce TForm2 nicht gefunden ..."


:?: :?: :?:

_________________
Was man einmal gedacht hat, kann man nie mehr zurücknehmen.
eurohasi2
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16



BeitragVerfasst: Mo 01.09.03 12:07 
Titel: Super
Danke, jetzt funzt alles ...

:D :D :D

_________________
Was man einmal gedacht hat, kann man nie mehr zurücknehmen.
Mav
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Mo 01.09.03 19:44 
Ich n00b hab jetzt ein Problem mit 2 Units und Records.

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

type
  Tgame = Record
             name: string[30];
             beschreibung: string[200];
             preis: real;
             bestellnr, garantie: integer;
           end;
  Tsuche = Record
             name: string[30];
             preis: real;
             bestellnr, garantie: integer;
           end;
  TForm1 = class(TForm)
  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
    game, blubb: Tgame;
    suche, blabb: Tsuche;
    datei: file of Tgame;
    procedure Ausgabe(game: Tgame; suche: tsuche);
  end;

var
  Form1: TForm1;
  game: Tgame;
  suche: Tsuche;
  datei: file of Tgame;
implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.Ausgabe(game: Tgame; suche: Tsuche);
begin
     with game do
               begin
               tform1.stringgrid1.Cells[0,1]:= '' +inttostr(bestellnr);
               tform1.stringgrid1.Cells[1,1]:= '' +name;
               tform1.stringgrid1.Cells[2,1]:= '' +floattostrf(preis, fffixed, 102);
               tform1.stringgrid1.Cells[3,1]:= '' +inttostr(garantie);
               tform1.stringgrid1.Cells[4,1]:= '' +beschreibung;
               end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
     form2.show;
end;

end.


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

type
  TForm2 = class(TForm)
  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
  end;

var
  Form2: TForm2;

implementation

uses Unit1;

{$R *.DFM}

procedure TForm2.Button2Click(Sender: TObject);
begin
     form2.close;
end;

procedure TForm2.Button1Click(Sender: TObject);
var i: integer;
begin
    assignfile(datei, 'daten.dat');
     if fileexists('daten.dat'then
        reset(datei)
     else rewrite(datei);
     read(datei, game);
     i:= 0;

    if radiobutton1.checked then
    begin
    suche.bestellnr:= strtoint(edit1.text);
    while not eof(datei) do
     begin
          seek(datei, i);
          read(datei, game);
          if suche.bestellnr = game.bestellnr then
          begin
               form1.ausgabe(blubb.bestellnr, blabb.bestellnr);
          end;
          i:= i + 1;
     end;
          i:= i + 1;
     end;
     closefile(datei);
end;

end.


Trotzdem ist "blubb" immer noch undefiniert.
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Mo 01.09.03 21:24 
hallo mav!

in dieser procedure ist mal ganz sicher TForm1 überflüssig, da die procedure je schon zu form1 gehört :)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Ausgabe(game: Tgame; suche: Tsuche); 
begin 
     with game do 
               begin 
               tform1.stringgrid1.Cells[0,1]:= '' +inttostr(bestellnr); 
               tform1.stringgrid1


'game' & 'suche' funktionieren deshalb problemlos, da du sie doppelt definiert hast - einmal als variablen der Form1 und einmal global

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
  public 
    { Public-Deklarationen} 
    game, blubb: Tgame; 
    suche, blabb: Tsuche; 
    datei: file of Tgame; 
    procedure Ausgabe(game: Tgame; suche: tsuche); 
  end

var 
  Form1: TForm1; 
  game: Tgame; 
  suche: Tsuche; 
  datei: file of Tgame;


blubb und blabb erkennt der compiler in unit2 deshalb nicht, da sie zu Form 1 gehören. du solltest sie aber mittels
ausblenden Delphi-Quelltext
1:
  Form1.blubb					


ansprechen können. aber das finde ich zuviel des guten
da siehst, wie gemeingefährlich solche globalen variablen sein können *g*

ich würde die records in einer globalen unit definieren zb unit 'GLOBALS'
diese bindest in alle verwendeten units ein und du brauchst schon nicht drauf zu achten, ob die variablen nun in unit1 oder unit2 stehen

mfg, stefan
Mav
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Mo 01.09.03 22:25 
Erstmal danke Stefan. :D

Jetzt hab ich aber ein neues Problem, nämlich "[Fataler Fehler] Unit1.pas(7): Überkreuzender Bezug zweier Units auf 'Unit1' ".

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

interface

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

  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
    game, blubb: Tgame;
    suche, blabb: Tsuche;
    datei: file of Tgame;
    procedure Ausgabe(game: Tgame; suche: tsuche);
  end;

var
  Form1: TForm1;
implementation

uses Unit2;


ausblenden 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:
unit Unit2;

interface

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

  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
    game, blubb: Tgame;
    suche, blabb: Tsuche;
    datei: file of Tgame;
    procedure Ausgabe(game: Tgame; suche: tsuche);
  end;

var
  Form2: TForm2;

implementation

uses Unit1;


ausblenden 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:
unit Unit3;

interface

uses unit1;
     unit2;

type
Tgame = Record
             name: string[30];
             beschreibung: string[200];
             preis: real;
             bestellnr, garantie: integer;
           end;
  Tsuche = Record
             name: string[30];
             preis: real;
             bestellnr, garantie: integer;
           end;

implementation

end.


Hab da jetzt eine Weile rumprobiert, aber ich kann es nicht fixen.

Achso, das
Zitat:

with game do
begin
tform1.stringgrid1.Cells[0,1]:= '' +inttostr(bestellnr);
tform1.stringgrid1

war noch ein Überbleibsel des Copy+Paste.
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: Mo 01.09.03 23:30 
hallo mav!

kann es sein, dass dir in unit1 und unit2 die deklarationen der forms abhanden gekommen sind? ;)

unit3 used NICHT unit1 und unit2. wozu soll denn das gut sein?
wieso hast jetzt auf einmal zweimal die ausgábe deklariert? einmal reicht doch

die public variablen (game, blubb, suche, blabb, datei) würd ich local in den proceduren vereinbaren, in denen sie verwendet werden...

ausblenden Delphi-Quelltext
1:
2:
3:
if suche.bestellnr = game.bestellnr then 
          begin 
               form1.ausgabe(blubb.bestellnr, blabb.bestellnr);

wird nicht funktionieren, da du blubb nicht den inhalt von suche und blabb nicht den inhalt von game zuweist. in diesen records steht immer was zufälliges.
warum musst du beim aufruf andere record-bezeichnungen verwenden?
game & bestellnr tuns ja auch...

irgendwie hab ich jetzt den konnex verloren, was das programm eigentlich tun soll.
auf form1 hast ein stringgrid zum anzeigen, richtig?
über button 4 rufst das form2 auf, dort ist ein eingabefeld der bestellnr, welches du ausliest, wenn du den radiobutton klickst

ausblenden Delphi-Quelltext
1:
2:
3:
4:
   seek(datei, i);
.
.
   i:= i + 1;


wozu ist denn das gut, dass du den satzzähler händisch immer um 1 erhöhst?
das geschieht doch automatisch durch read

fangen wir mal anders an... was ist eigentlich die idee des programmes?

mfg, stefan
Mav
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Di 02.09.03 12:32 
Hi Stefan. Ich poste mal kurz den kompletten Code.

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:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Button2: TButton;
    Edit4: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Edit5: TEdit;
    StringGrid1: TStringGrid;
    Button3: TButton;
    Label6: TLabel;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Ausgabe(game: Tgame; suche: tsuche);
  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
  end;

var
  Form1: TForm1;
implementation

uses Unit2;

{$R *.DFM}

procedure TForm1.Ausgabe(game: Tgame; suche: Tsuche);
begin
     with game do
               begin
               stringgrid1.Cells[0,1]:= '' +inttostr(bestellnr);
               stringgrid1.Cells[1,1]:= '' +name;
               stringgrid1.Cells[2,1]:= '' +floattostrf(preis, fffixed, 102);
               stringgrid1.Cells[3,1]:= '' +inttostr(garantie);
               stringgrid1.Cells[4,1]:= '' +beschreibung;
               end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     with game do
     begin
          name:= edit1.text;
          garantie:= strtoint(edit2.text);
          preis:= strtofloat(edit3.text);
          bestellnr:= strtoint(edit4.text);
          beschreibung:= edit5.text;
     end;
     assignfile(datei, 'daten.dat');
     if fileexists('daten.dat'then
        reset(datei)
     else rewrite(datei);
     seek(datei, filesize(datei));
     write(datei,game);
     closefile(datei);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
     stringgrid1.Cells[0,0]:= 'Bestellnummer';
     stringgrid1.Cells[1,0]:= 'Name';
     stringgrid1.Cells[2,0]:= 'Preis';
     stringgrid1.Cells[3,0]:= 'Garantie';
     stringgrid1.Cells[4,0]:= 'Beschreibung';
     with game do
     begin
          name:= 'Unbekannt';
          garantie:= 0;
          preis:= 0;
          bestellnr:= 0;
          beschreibung:='Unbekannt';
     end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i: integer;
begin
     assignfile(datei, 'daten.dat');
     if fileexists('daten.dat'then
        reset(datei)
     else rewrite(datei);
     read(datei, game);
     i:= 0;
     stringgrid1.rowcount:= filesize(datei) + 1;

     while not eof(datei) do
     begin
          seek(datei, i);
          read(datei, game);
          with game do
          begin
          stringgrid1.Cells[0,i+1]:= '' +inttostr(bestellnr);
          stringgrid1.Cells[1,i+1]:= '' +name;
          stringgrid1.Cells[2,i+1]:= '' +floattostrf(preis, fffixed, 102);
          stringgrid1.Cells[3,i+1]:= '' +inttostr(garantie);
          stringgrid1.Cells[4,i+1]:= '' +beschreibung;
          end;
          i:= i+1;
     end;
     closefile(datei);
end;



procedure TForm1.Button3Click(Sender: TObject);
var i: integer;
begin
     assignfile(datei, 'daten.dat');
     if fileexists('daten.dat'then
        reset(datei)
     else rewrite(datei);
     read(datei, game);
     i:= 0;

     while not eof(datei) do
     begin
          seek(datei, i);
          read(datei, game);
          if suche.name = game.name then
          begin
               with game do
               begin
               stringgrid1.Cells[0,1]:= '' +inttostr(bestellnr);
               stringgrid1.Cells[1,1]:= '' +name;
               stringgrid1.Cells[2,1]:= '' +floattostrf(preis, fffixed, 102);
               stringgrid1.Cells[3,1]:= '' +inttostr(garantie);
               stringgrid1.Cells[4,1]:= '' +beschreibung;
               end;
          end;
          i:= i + 1;
     end;
     closefile(datei);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
     form2.show;
end;

end.


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

interface

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

type
  TForm2 = class(TForm)
    RadioGroup1: TRadioGroup;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    RadioButton4: TRadioButton;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen}
  public
    { Public-Deklarationen}
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}

procedure TForm2.Button2Click(Sender: TObject);
begin
     form2.close;
end;

procedure TForm2.Button1Click(Sender: TObject);
var i: integer;
begin
    assignfile(datei, 'daten.dat');
     if fileexists('daten.dat'then
        reset(datei)
     else rewrite(datei);
     read(datei, game);
     i:= 0;

    if radiobutton1.checked then
    begin
    suche.bestellnr:= strtoint(edit1.text);
    while not eof(datei) do
     begin
          seek(datei, i);
          read(datei, game);
          if suche.bestellnr = game.bestellnr then
          begin
               form1.ausgabe(game.bestellnr, suche.bestellnr);
          end;
          i:= i + 1;
     end;
    end;
     closefile(datei);
end;

end.


ausblenden 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:
unit Unit3;

interface

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

type
  Tgame = Record
             name: string[30];
             beschreibung: string[200];
             preis: real;
             bestellnr, garantie: integer;
           end;
  Tsuche = Record
             name: string[30];
             preis: real;
             bestellnr, garantie: integer;
           end;

var
    game: Tgame;
    suche: Tsuche;
    datei: file of Tgame;

implementation

end.


Das Programm soll eine Art Datenbank für die Schule sein.
Die Daten werden über Edits eingelesen, in einer Datei gespeichert und können über den 2. Button im Stringgrid ausgegeben werden.
In der 2.Unit findet dann die Suche nach einem Datensatz statt.
Und soll in der 1.Unit im Stringgrid ausgegeben werden.
z1dirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Di 02.09.03 22:07 
Hi nur mal so nebenbei:- mit alt+F11 verbindet man die units, die Einträge müssen bei beiden units votgenommen werden
-wenn man eine procedure aus einer anderen unit will geht das so z.B. "Unit1.Form1.procedure; "und eine Variable so "artikel:Unit1.Tartikel;"
so sind viele probleme gelöst.

Nur nebenbei ich mach auch gerad eine datenbank für die schule und wir sollen index dateien für die sortierung machen. vieleicht könnt ihr mir ein paar tips geben oder eine beispiel procedure.

Danke. cya Dirk.