Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 28.02.05 19:35 
ich bekomme den fehler auch, ist mir aber schleierhaft ...
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 28.02.05 19:37 
Und ohne die ganze PChar Bastelei? Du Kopierst einen String in einen PChar und liest nachher Byte für Byte vom PChar und schreibst es ins sndBytes. Das ist alles gar nicht nötig.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
Var
 Buffer : PByteArray;
 Len : Integer;
 MsgType : Word;
 Msg : String;
begin
 Msg := CreateCharacterForm.ENewCharacterName.text;
 Len := length(Msg);
 GetMem(Buffer, Len+2);
 MSGType := 7;
 try
  Move(MsgType, Buffer^[0], 2);
  Move(Msg[1], Buffer^[2], Len);
  ClientSocket.Socket.SendBuf(Buffer^,Len+2);
 finally
  FreeMem(Buffer);
 end;
end;

Ich glaube du überschreibst sonstwo irgend was im Speicher und erhältst deswegen nen Fehler..
//Edit: Korrektur


Zuletzt bearbeitet von delfiphan am Mo 28.02.05 19:52, insgesamt 1-mal bearbeitet
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 28.02.05 19:41 
NeWsOfTzzz hat folgendes geschrieben:
nein es muss nicht einen länger sein, weil ich auch so schon alle buchstaben habe. aber um das auszuschliessen hab ich das mal getestet aber der fehler besteht nach wie vor...


Delphi Dokumentation: "StrLCopy copies a null terminator as well as MaxLen characters (das heisst du brauchst MaxLen+1 Bytes zur Verfügung). Be sure that Dest is large enough to accommodate the null terminator at the end."

Es ist egal ob du "so schon alle Buchstaben hast". Du brauchst Platz für die 0 am Ende. Du überschreibst vielleicht an anderen Orten im Programm was und kriegst Folgefehler, wenn du auf ne Komponente zugreifst.
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Mo 28.02.05 19:47 
delfiphan hat folgendes geschrieben:
Es ist egal ob du "so schon alle Buchstaben hast". Du brauchst Platz für die 0 am Ende. Du überschreibst vielleicht an anderen Orten im Programm was und kriegst Folgefehler, wenn du auf ne Komponente zugreifst.

oh, der böse bube kopiert die null bei length+1 einfach drüber? nenene.. was der sich erlaubt ^^
aber ich kann dir garantieren dass das nicht die quelle des fehlers war, und das mit pbytearray guck ich mir mal an
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 28.02.05 19:57 
Oder in Kurzform ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Type
 Word2Char = packed record
  Lo, Hi : Char;
 end;
var
 S: string;
 MsgType : Word;
Begin
 MsgType := 7;
 S := Word2Char(MsgType).Lo+Word2Char(MsgType).Hi+CreateCharacterForm.ENewCharacterName.text;
 ClientSocket.Socket.SendBuf(S[1],length(S));
end;
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Mo 28.02.05 20:09 
omg, jetzt hab ich gerade gesehen dass ich für den testlauf mit der länge+1 falsch angesetzt habe, nämlich bei "sndBytes" und nicht bei "MSG" :oops:
und wenn ich jetzt tstringlist1 eingebe, dann geht das..
was mich wundert, was hat diese nullterminierung, die ja so in MSG fehlt, bloß mit delphi komponenten zu tun?
ich hab vorher schon 1000 eingaben gemacht und nie ist das ohne die nullterminierung abgestürzt, erst mit diesem account1...
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 28.02.05 20:55 
Also generell zum Thema PChars, Strings und Typecasting von String nach PChar kann ich dir mal mein String-Tutorial empfehlen: www.manuel-poeter.de

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Mo 28.02.05 21:08 
guck ich mir mal an, danke.. ich wusste ehrlich gesagt bis heute nicht dass die normalen strings in delphi nicht nullterminiert sind.. hab früher nur mit c++ gearbeitet.. deswegen hab ich auch einfach die länge des normalen strings übernommen :oops:
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 28.02.05 21:47 
NeWsOfTzzz hat folgendes geschrieben:
ich wusste ehrlich gesagt bis heute nicht dass die normalen strings in delphi nicht nullterminiert sind..

Sind sie eh..! Nur Delphi führt dieses Nullzeichen intern automatisch mit und dieses wird bei der Länge nicht berücksichtigt. ;) Lass dir mal das Zeichen an der Stelle String[Length(String)] ausgeben, du wirst feststellen, dass es das letzte Zeichen dest Strings ist, und nicht das Nullzeichen. Das Nullzeichen befindet sich an Position Length(String) + 1.

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Mo 28.02.05 21:56 
man kann mit string[i: integer] auf eine bestimmte stelle im string zugreifen? dann is der ganze umweg über pchar ja eh umsonst?
ps: ja es geht :gruebel: :motz:
soviel arbeit ganz umsonst ^^
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 28.02.05 22:05 
Ja, kann man.. und dass der ganze Umweg über PChar umsonst ist haben dir in dem Thread auch schon ein paar Leute zu erklären versucht.. ;)

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
NeWsOfTzzz Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 233


D4 Prof
BeitragVerfasst: Mo 28.02.05 22:09 
nun reite nicht noch drauf rum, das tut so schon weh O.o
bockwurst
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 191

win98 /XP
D1 D5 Prof DE2005PE
BeitragVerfasst: Di 15.03.05 11:56 
hallo zusammen,
alles läuft immer wunderbar wenn du den String mit StrAlloc oder mit StrNew reserviert. Dannach mußt du ihn immer mit StrDispose freigeben.


Andreas