Autor Beitrag
ene
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 779
Erhaltene Danke: 1

Vista, XP, W2K
Delphi, .Net, Deutsch und Englisch
BeitragVerfasst: Do 22.03.07 16:22 
Hi,

kann mir einer sagen, wie die Umkehrfunktion von Char() heißt? Ich muss einen String in eine Datei schreiben, deswegen würde ich auch ein StrToByte nehmen, aber leider scheints da nix zu geben.

Vielen Dank im Vorraus.
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Do 22.03.07 16:25 
Hallo,

verstehe nicht was du meinst!

Ord gibt den ASCII-Code eines Zeichens zurück!
Ein Typcast mit Byte wandelt das Zeichen in seinen Binärcode um (müsste das selbe sein).

Gruß Hape!
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 22.03.07 16:37 
Moin!

user profile iconene hat folgendes geschrieben:
Ich muss einen String in eine Datei schreiben,

Und warum tust du das nicht einfach... ? :gruebel: Da muss man nix umwandeln, typecasten, sonwas... ;) Zeig doch mal deinen Code, dann kommen wir auch sicher weiter. :mahn:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
ene Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 779
Erhaltene Danke: 1

Vista, XP, W2K
Delphi, .Net, Deutsch und Englisch
BeitragVerfasst: Do 22.03.07 16:42 
Ord('a') gibt ja auch den richtigen Wert wieder, aber ich habe eben einen String und da komm ich auf keinen grünen Zweig:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Var 
  a: String;
  x: Char;
  y: String;
  z: Byte;
Begin
  a:= 'EinText';
  For i:= 1 To 7 Do Begin
    x:= Copy(a, i, 1); <-- Fehler Char und String inkompatibel
    y:= Copy(a, i, 1); <-- Funktioniert
    z:= Copy(a, i, 1); <-- Fehler Byte und String inkompatibel
    z:= Ord(PChar(y)); <-- Inkompatibel
  End;
End;


Irgendwas überseh ich da wohl :(

@Narses Ich kann leider nicht dort einfach reinschreiben, da noch ein paar Informationen dazugehören und es ein kompletter Header ist.
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Do 22.03.07 16:46 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Var 
  a: String;
  x: Char;
  y: String;
  z: Byte;
Begin
  a:= 'EinText';
  For i:= 1 To 7 Do Begin
    x := a[1]; //Erstes Zeichen 'E', Char = 1 Zeichen
    y := Copy(a, 11); //Zeichenkette länge eins mit 'E'
                        //da Copy auch mehrere Zeichen zurückgegeben kann,
                        //ist der Rückgabewert String und kann deshalb nicht in
                        //einem Char der festen Länge 1 gespeichert werden
    z := Byte(a[1]);    //oder z := ord(a[1]);
  End;
End;
Übrigens, wenn du binäre Datein speichern willst (so scheint es mir zumindest), dann schau mal nach Suche in: Delphi-Forum TFILESTREAM.

Gruß Hape!


Zuletzt bearbeitet von wulfskin am Do 22.03.07 16:48, insgesamt 1-mal bearbeitet
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Do 22.03.07 16:47 
aber mystring[i] ist ein char
ene Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 779
Erhaltene Danke: 1

Vista, XP, W2K
Delphi, .Net, Deutsch und Englisch
BeitragVerfasst: Do 22.03.07 16:54 
Ok, dann hab ichs wohl auch verstanden. Vielen Dank, es läuft!