Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Frage zu Typendeklarationen (https://www.delphipraxis.net/114396-frage-zu-typendeklarationen.html)

Neutral General 24. Mai 2008 15:50


Frage zu Typendeklarationen
 
Hi,

Ich frage mich gerade, was der Unterschied zwischen

Delphi-Quellcode:
type
  Dings = Word;
und

Delphi-Quellcode:
type
  Dings = type Word;
ist. Kann mir das jemand sagen?

Apollonius 24. Mai 2008 15:51

Re: Frage zu Typendeklarationen
 
Type verhindert laut Hilfe einen impliziten Cast.

Neutral General 24. Mai 2008 15:52

Re: Frage zu Typendeklarationen
 
Hi Apollonius,

Danke für die Antwort. Ok.. Also ich denke dann werde ich das Type wohl weglassen *g*

Gruß
Neutral General

Apollonius 24. Mai 2008 15:58

Re: Frage zu Typendeklarationen
 
Naja, Word ist ein schlechtes Beispiel. Wenn du es mal ausprobierst, kannst du trotzdem noch ein Word einem Dings und ein Dings einem Word zuweisen. Es geht aber nicht mehr, falls du beispielsweise TObject nimmst.

Neutral General 24. Mai 2008 15:59

Re: Frage zu Typendeklarationen
 
Achso.. Also bei so einfachen Datentypen wie Word, Boolean, Integer etc ist es im Prinzip egal?

Apollonius 24. Mai 2008 16:02

Re: Frage zu Typendeklarationen
 
Schau mal in die Hilfe unter "Type Compatibility". Da heißt es bei mir unter "Assignment Compatibility" unter anderem:
Zitat:

[...] An expression of type T2 can be assigned to a variable of type T1 if the value of the expression falls in the range of T1 and at least one of the following conditions is satisfied.
[...]
T1 and T2 are compatible ordinal types.
T1 and T2 are both real types.

Muetze1 24. Mai 2008 16:18

Re: Frage zu Typendeklarationen
 
Das erste ist eine reine Typen-Alias Deklaration und zweites legt einen neuen Typen an. Sprich: beim ersten wird in der RTTI der Basistyp verwendet, beim zweiten wird dieser als neuer Typ in der RTTI hinterlegt.


Alle Zeitangaben in WEZ +1. Es ist jetzt 12:12 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz