Autor Beitrag
Alstar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 827



BeitragVerfasst: Sa 26.02.05 01:41 
Hallo!!

Ich hoffe es liegt nur an meiner Dummheit. Ich habe zwei Prozeduren:

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:
procedure xyz;
var
  Datei: TFileStream;

  dataread, I: integer;
  BufZahl: Extended;
  Zahl: Extended;
   FileBuffer: array[0..2048] of byte;
begin
  Datei := TFileStream.Create(Edit1.Text, fmopenread);
  zahl := 0;
  while true do
  begin
    dataRead := Datei.Read(FileBuffer[0], SizeOf(FileBuffer));
    BufZahl := 0;
    if dataread = 0 then break;
    For I := 0 to dataread do
    begin
      BufZahl := BufZahl + Integer(FileBuffer[I]);
    end;
    BufZahl := BufZahl / dataread;
    Zahl := Zahl + BufZahl;
    Zahl := Zahl / 2;
  end;
  Label1.Caption := FloatToStr(Zahl);

  Datei.Free;
end;

und
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:
procedure TForm1.Button2Click(Sender: TObject);
var
  Datei: TFileStream;

  dataread, I: integer;
  Zahl, BufZahl: Extended;
  FileBuffer: array[0..2048] of byte;
begin
  Datei := TFileStream.Create(Edit1.Text, fmopenread);
  zahl := 0;
  while true do
  begin
    dataRead := Datei.Read(FileBuffer[0], SizeOf(FileBuffer));
    BufZahl := 0;
    if dataread = 0 then break;
    For I := 0 to dataread do
    begin
      BufZahl := BufZahl + Integer(FileBuffer[I]);
    end;
    BufZahl := BufZahl / dataread;
    Zahl := Zahl + BufZahl;
    Zahl := Zahl / 2;
  end;
  Label1.Caption := FloatToStr(Zahl);

  Datei.Free;
end;


Sie unterscheiden sich nur durch 1 Zeile! Und zwar habe ich nur die Variable "Zahl" mit zu der Variablen "BufZahl" geschrieben.

Kaum zu glauben, aber dadurch wird das Ergebnis verfälscht!!!
WARUM??

Alstar


Moderiert von user profile iconUGrohne: Topic aus Sonstiges verschoben am Sa 26.02.2005 um 14:22
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Sa 26.02.05 14:22 
Was für eine Datei öffnest Du? Ist es immer dieselbe? Was kommt denn raus und was soll rauskommen? Geh doch einfach mal beide Prozeduren durch (mit F8 debuggen) und schau Dir genau den Inhalt der Variablen an, während die Prozedur durchläuft.