Autor Beitrag
rizor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 11.11.06 18:25 
Hi, ich hab folgendes Problem:
Ich lese eine Datei ein und suche den höchsten Wert.
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:
procedure TForm1.Button1Click(Sender: TObject);
  var Messwert:TWetter;
      Datei:File of TWetter;
      i:integer;
      t,n:real;
begin
  AssignFile(Datei,'wetter.dat');
  Reset(Datei);
  t:=0.0;
  n:=0.0;
  i:=0;
  repeat
    Inc(i);
    Read(Datei,Messwert);
    with Messwert do
    begin
      SGDaten.Cells[0,i]:=InttoStr(Tag);
      SGDaten.Cells[1,i]:=FloattoStrF(Temperatur,ffFixed,10,1);
      SGDaten.Cells[2,i]:=FloattoStrF(Niederschlag,ffFixed,10,1);
      max(n,t);
    end;
  until EOF(Datei);
  CloseFile(Datei);
  Label1.Caption:=FloatToStr(t);
  Label2.Caption:=FloatToStr(n);
end;


Das ist der Quellcode, der die Datei ausliest und dann den höchsten Wert mit max(n,t)
ermittelt.
Am Ende soll der höchste Wert ausgegeben werden

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.max(var nied,temp:real);
  var Messwert:TWetter;
begin
  with Messwert do
  begin
  if temp<Temperatur then temp:=Temperatur;
  if nied<Niederschlag then nied:=Niederschlag;
  end;
end;


Das ist die Prozedur, die ermitteln soll, welcher Wert der größte ist.

Das Problem ist, dass die falschen Werte ausgegeben werden.
n=2,49*10^-307
t=6,59*10^-313

Ich entdecke leider den Fehler nicht.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 11.11.06 18:32 
Du deklarierst Messwert als lokale Variable. Diese ist dann undefiniert.

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 11.11.06 18:37 
Wie soll ich es dann sonst machen?
Muss ich Messwert dann global definieren?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 11.11.06 18:40 
Zitat:
Muss ich Messwert dann global definieren?
Entweder das oder besser als weitrern Parameter der Methode der Funktion.

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 11.11.06 18:41 
Wie geht das?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 11.11.06 18:43 
ausblenden Delphi-Quelltext
1:
procedure TForm1.max(var nied,temp:real; var Messwert:TWetter);					

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 11.11.06 18:49 
Ach,... so meinst du das.
Das Problem ist nur, wenn ich es so mache, sagt er mir, dass TWetter ein undefinierter Bezeichner ist.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 11.11.06 18:51 
Hast du TWetter zufällig im Implementation-Abschnitt deklariert?

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 11.11.06 18:52 
Ja.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 11.11.06 18:55 
Dann verschiebe die deklaration in den Interface-Abschnitt oder Deklariere die Variable Messwert global.

_________________
Markus Kinzler.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 11.11.06 19:15 
Hab ich jetzt gemchat.
Danke. Funktioniert.
rizor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 209

WIN XP
Delphi 2005 PE, Visual C++
BeitragVerfasst: Sa 11.11.06 19:18 
Habe noch ein Problem :(.
Ich rechne folgendes:

s:= 315 / n;
Round(s);

Nun sagt er: [Fehler] Unit1.pas(112): E2014 Anweisung erforderlich, aber Ausdruck vom Typ 'Int64' gefunden

Der Fehler ist bei Round(s);
n ist als real deklariert.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 11.11.06 19:23 
entweder:
ausblenden Delphi-Quelltext
1:
s:= Round(315 / n);					

oder
ausblenden Delphi-Quelltext
1:
s : = Round(s);					

;)