Longword und Real in Delphi einlesen?

  • 1
  • 2
  • 3
  • Page 2 of 3
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 27.09.2010 - 17:34  ·  #9
Hello Merlin,

yes, you are absolutely right. In case of strings Delphi now knows two types of strings, shortstrings and standard strings. Standard strings now have 2bytes for each char to be conform with new standards. Within Delphi this is don't care. But with moving strings between Delphi and 8/16bit Pascals like Turbo Pascal and AVRco this is a problem. So Delphi still knows the type shortstring which has still one length byte and the total size is 256 chars. It is also possible to implicitely define a shortstring variable with var st : string[56]. Giving a string length here it forces this var to be a short string.
The Delphi short strings are compatible with the AVRco strings.

btw.
In Delphi a char has still 8bits. But there is also a 2byte char = WideChar

rolf
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1406
Registered: 03 / 2005
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 27.09.2010 - 18:08  ·  #10
Hi Rolf.

You are not quite right about char. There are several types of char and you are absolutely right that WideChar is 2 bytes. However the guaranteed 8 bit version in AnsiChar. Char can, depending on your compiler settings be 8 or 16 bit, but the default is 16 bit.

Here is a relevant extract from the help files:

Quote
Character Types
The fundamental character types are AnsiChar and WideChar. AnsiChar values are byte-sized (8-bit) characters ordered according to the locale character set which is possibly multibyte.

WideChar characters use more than one byte to represent every character. In the current implementations, WideChar is word-sized (16-bit) characters ordered according to the Unicode character set (note that it could be longer in future implementations). The first 256 Unicode characters correspond to the ANSI characters.

The generic character type is Char, which is equivalent to WideChar on Win32. Because the implementation of Char is subject to change, it's a good idea to use the standard function SizeOf rather than a hard-coded constant when writing programs that may need to handle characters of different sizes.

A string constant of length 1, such as 'A', can denote a character value. The predefined function Chr returns the character value for any integer in the range of AnsiChar; for example, Chr(65) returns the letter A.



Note the comment on WideChar - might be more than 2 bytes one day!

There is nothing like consistency - and this is nothing like consistency!

Cheers

Merlin :-)
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 27.09.2010 - 18:12  ·  #11
Hello Merlin,

I'm still working with Delphi6 where a char seems to be 8bits. Anyhow, how can I force the Delphi to use 8bits for a char?
Similar is true with a boolean, I think.

rolf
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1406
Registered: 03 / 2005
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 27.09.2010 - 20:46  ·  #12
Hi Rolf.

Yes Delphi 6 definitely had 8 bit chars.

If you move to Delphi 2009, there is a compiler option that is supposed to force 8 bit chars, but I will be honest, when I tried it the results were a bit flakey. In any event, Delphi ironically runs slower when using 1 byte chars, so in the end I just decided that wherever I needed an 8 bit char I would use type byte. You could use AnsiChar, but I felt that any char type would be subject to the vaguaries of future upgrades (see my comments on WideChar type), whereas type byte was pretty bullet proof. Then you just typecast as normal or use Ord. Really, the only time it is an issue, though is during communication e.g. over serial. They have file reading and writing covered pretty well. I never had a problem there.

Regards

Merlin.
ThomasW69
 
Avatar
 
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 28.09.2010 - 07:14  ·  #13
Ja die Umstellung auf Unicode in Delphi9 hat mir auch schlaflose Nächte gebracht. Im Prinzip ist es aber recht einfach. Das was früher mal string in Delphi war ist jetzt AnsiString (8bit). Ebenso ist es mit char -> ansichar.
http://edn.embarcadero.com/art…nicode.pdf
Da ich auch irgendwann mal mit Delphi auf den ATMEga zugreifen will wäre es aber nicht shclecht, wenn man mal eine Liste mit AVRCo-datentypen und deren Äquivalent in Delphi veröffentlichen würde.
Lschreyer
Schreiberling
Avatar
Gender: n/a
Posts: 527
Registered: 02 / 2007
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 28.09.2010 - 08:24  ·  #14
Nach meinem Wissen:

Avrco = Delphi

Byte=Byte
Float= Single
Word = Word
Longword=Longword
Integer = Smallint
Longint = Integer
Int64 = Int64

Wie die anderen aussehen weiss ich nicht.

Louis
pvs-deck
PowerUser
Avatar
Gender:
Age: 53
Homepage: pvs-deck.de
Posts: 1341
Registered: 02 / 2009
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 28.09.2010 - 13:44  ·  #15
Hallo Louis.
Hallo Rolf.

Quote by Lschreyer

Avrco = Delphi

Byte=Byte
Real = Single
Word = Word
Longword=Longword
Integer = Smallint
Longint = Integer
Int64 = Int64


Da wohl die meisten (ich auch) auf dem PC mit dem Delphi arbeiten, komme ich mit diesem Problemen auch in nächster Zeit in Berührung.

@Rolf: Besteht hier evtl. die Möglichkeit eine Datentypen-Vergleichsliste in das Compiler-Handbuch zu setzen? Z.B. als Anhang, damit man gar nicht mehr über diese Probleme stolpert?

Es würde ja eine einfach Liste so wie bei Louis ausreichen, dazu noch das "packed record" usw. Fertig :)

Gruß
Thorsten
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1406
Registered: 03 / 2005
Subject:

Re: Longword und Real in Delphi einlesen?

 · 
Posted: 28.09.2010 - 14:05  ·  #16
Hi Thorsten, Thomas et al.

As has been seen in this thread, there is no surefire conversion. Delphi is not consistant in its usage. Even Rolf's version and mine have different properties leading us initially to different conclusions, and Delphi under Linux may be different again (who knows?). The best I think that you should hope for is a clear definition of the various types in AVRCo (including endian properties) that you can compare to your version of Delphi (or whatever compiler you may be using at the time). Ultimately when moving between two platforms it must be the responsibility of the programmer to ensure compatibility IMHO. These are given in the compiler manual section 4.1 onwards.

Regards

Merlin.
  • 1
  • 2
  • 3
  • Page 2 of 3
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   137   151 · Page-Gen-Time: 0.04315s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI