Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 22.06.06 20:33 
Hallo,

ich will einem Char ein Integer zuweisen. Inttostr akzeptiert Delphi nicht:

[Fehler] maf.pas(840): Inkompatible Typen: 'Char' und 'String'

Was tun?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Do 22.06.06 20:53 
Nun ja ein char ist ja nur ein einziges Zeichen damit kann man also genau Zahlen von 1-9 darstellen (hexadezimal möchtest du doch nicht).
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function inttochar(int:integer):char
asm
   add al,$30;
end;

//oder in pascal

function inttochar(int:integer):char
   result:=char(int+$30));
end;


Zuletzt bearbeitet von Allesquarks am Do 22.06.06 20:54, insgesamt 1-mal bearbeitet
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.06.06 20:53 
ausblenden Delphi-Quelltext
1:
CharVar := Char(IntVar);					

_________________
There are 10 types of people - those who understand binary and those who don´t.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 22.06.06 20:57 
user profile iconAllesquarks hat folgendes geschrieben:

function inttochar(int:integer):char
result:=char(int+$30));
end;
[/delphi]

Was bedeutet $30?

@Narses: funktioniert :zustimm:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Allesquarks
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 510

Win XP Prof
Delphi 7 E
BeitragVerfasst: Do 22.06.06 21:03 
Ein Character in Delphi ist nach dem Ascii oder Ansii Zeichensatz codiert egal wie, wenn der Binäre Wert des Char 2 ist ist das irgendein sehr merkwürdiges Sonderzeichen. Die Ziffern 1-9 beginnen in der Ascii Tabelle bei $30, wobei das $ nur signalisiert, dass die eingegebene Zahl hexadezimal ist, das heißt im konkreten Fall 3*16=48, dass heißt du könntest auch 48 hinterschreiben dann aber ohne $.

Um die Tabellenplätze bestimmter Zeichen zu finden empfiehlt sich ord().

Da ein char = 1 byte ist hat die ascii Tabell maximal 256 einträge, da 11111111b = $FF = 255 . +1 wegen der Null

siehe auch widechar.