Autor Beitrag
hui1991
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Mi 10.05.06 06:57 
Also ich mache ein Code:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
  NumberBytes: Integer; FromIP: String; Port: Integer);
var
  MyStream2: TMemoryStream;
  wert: String;
  endwert: Integer;
begin
  MyStream2 := TMemoryStream.Create;
  try
    NMUDP1.ReadStream(MyStream2);
    SetLength(wert, NumberBytes);
    MyStream2.Read(wert, NumberBytes);
    endwert:=StrToInt(wert[1]);
    Label15.Caption:=IntToStr(endwert);
  finally
    MyStream2.Free;
  end;
end;

Dabei kommt das hier noch:
ausblenden Quelltext
1:
2:
Exception EAccessViolation in Modul ABC.exe bei 00002C9C.
Zugriffsverletzung bei Adresse 00402C9C in Modul 'ABC.exe'. Lesen von Adresse FFFFFFFF.


Wenn es ausgeführt wird, wird entweder MyStream2.Free zwei mal ausgeführt oder es kommt eine Access Violation. Ich weis leider nicht warum :(

MfG
hui1991
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 10.05.06 09:28 
Moin!

Ich kenn die Kompo NMUDP nicht, aber kennst du diese Kompo? Vielleicht kommst du damit ja besser klar, da brauchst du keine Streams. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mi 10.05.06 10:11 
Der Fehler liegt beim Lesen aus dem Stream in den String - TStream.Read schreibt die gelesenen Daten direkt in die übergebene Variable. String ist aber intern ein Zeiger auf den String. Mit Read wird also der Zeiger und (wenn mehr als 4 Bytes gelesen werden) andere lokale Variablen und sonstige Daten auf dem Stack überschrieben.

So ist es richtig;

ausblenden Delphi-Quelltext
1:
MyStream2.Read(PChar(wert)^, NumberBytes);					


Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
hui1991 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Mi 10.05.06 16:19 
Ich kenne dieses Problem nicht:
ausblenden Quelltext
1:
Im Projekt ABC.exe ist eine Exception der Klasse EConvertError aufgetreten. Meldung: ''					


Hab den code so angepast wie es sein sollte.
Weis nicht woran das liegt.
Stefan.Buchholtz
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 612

WIN 2000, WIN XP, Mac OS X
D7 Enterprise, XCode, Eclipse, Ruby On Rails
BeitragVerfasst: Mi 10.05.06 16:32 
Das sieht so als ob StrToInt fehlschlägt. Hast du mal überprüft, ob du überhaupt Daten bekommst und wie die aussehen?

Stefan

_________________
Ein Computer ohne Windows ist wie eine Schokoladentorte ohne Senf.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 10.05.06 16:39 
Der Fehler liegt in Zeile 12. Dort muss es heißen MyStream.ReadBuffer(wert[1], NumberOfBytes);

Die zweite Änderung bzgl. Read und ReadBuffer betrifft einzig und allein die Fehlerkorrektur: ReadBuffer löst eine Exception aus, wenn die angeforderte Datenmenge nicht gelesen werden konnte.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
hui1991 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Mi 10.05.06 17:00 
Genau das ist das Problem.
War ein wenig zu lahm das noch hin zuschreiben.
Dummer weise kommt nur das hier raus:
wert: #0'ÜE'#0' J'
Ich weis nicht warum
Ich habe eigentlich 1Hallo geschrieben.
Keine Ahnung warum das falsch angezeigt wird.