![]() |
Delphi-Version: 2007
"type xyz = type string" Sprachkonstrukt?!?
Was ist denn das für ein seltsames Konstrukt:
Delphi-Quellcode:
Was macht das zweite "type" da drin?
type
xyz = type string; |
AW: "type xyz = type string" Sprachkonstrukt?!?
Von woher stammt der Code?
|
AW: "type xyz = type string" Sprachkonstrukt?!?
Das sagt, dass
Code:
und
xyz
Code:
das gleiche ist. Du kannst also das hier machen:
string
Delphi-Quellcode:
var
A: string; B: xyz; begin A := 'Hallo'; B := 'Hallo'; end; |
AW: "type xyz = type string" Sprachkonstrukt?!?
Btw: was spricht dagegen für delphi-Code den Delphi-Tag zu verwenden? Da ihr das konsequenterweise nicht verwendet!
|
AW: "type xyz = type string" Sprachkonstrukt?!?
Aus den Delphi basics:
Zitat:
|
AW: "type xyz = type string" Sprachkonstrukt?!?
das type besagt, daß ein eigenständiger Type angelegt wird.
dieses erstellt einen Alias für den Type, aber in der RTTI bleibt es dennoch der externer Type "String".
Delphi-Quellcode:
.
type xyz = string;
hier wird in der RTTI für xyz ein eigenständiger Type angelegt.
Delphi-Quellcode:
.
type xyz = type string;
Delphi hat doch eine strenge Typenprüfung, so daß man nun "xyz" und "string" unterscheiden kann. [add]
Delphi-Quellcode:
type
PTypeInfo = ^TTypeInfo; TTypeInfo = packed record Kind: Byte; Name: ShortString; {TypeData: TTypeData} end; type xyz = type string; abc = string; def = xyz; begin ShowMessage(Format('string = %s'#10'xyz = %s'#10'abc = %s'#10'def = %s'#10, [ PTypeInfo(TypeInfo(string))^.Name, PTypeInfo(TypeInfo(xyz))^.Name, PTypeInfo(TypeInfo(abc))^.Name, PTypeInfo(TypeInfo(def))^.Name])); |
AW: "type xyz = type string" Sprachkonstrukt?!?
Zitat:
|
AW: "type xyz = type string" Sprachkonstrukt?!?
Bitte
Sowas kann man z.B. für sowas verwenden:
Delphi-Quellcode:
aber Achtung, dieses
procedure a(x: xyz); overload;
procedure a(x: string); overload;
Delphi-Quellcode:
geht hier allerdings nicht, da die Konstante noch keinem Typen direkt zugeordnet ist und somit der Compiler nicht weiß, welcher "String"-Type nun zuständig wäre, aber man kann somit unterschiedliche Variablen übergeben und anders behandeln.
a('dsa');
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:41 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz