![]() |
Was ist ein "Property" intern?
Delphi-Quellcode:
Hier ein kleines Beispiel, mit dem ich eine Membervariable auslesen kann. Aber was von den beiden ist schneller? Das Property GetZahl oder die gleichnamige Funktion? Das Problem mit dem Funktionsaufruf ist, dass es eben ein Funktionsaufruf ist. C++ würde so eine Funktion wohl automatisch inlinen, aber das kann Delphi ja nicht.
interface
type CIrgendwas = class private zahl: Integer; public property GetZahl read zahl; function GetZahl(): Integer; end; implementation function CIrgenwas.GetZahl(): Integer; begin Result := zahl; end; Jetzt frage ich mich, was das Property genau macht. Wird da einfach die Variable zahl an die entsprechenden Stellen im Quellcode kopiert, oder findet hier wie bei der gewöhnlichen Funktion auch ein Funktionsaufruf statt? |
Re: Was ist ein "Property" intern?
Wenn du wissen willst, was schneller ist:
Delphi-Quellcode:
ist schneller.
property GetZahl read zahl;
Zu der zweiten Frage: Ein Property "macht" nichts! Klassen sind im Prinzip nur records, die man mit Methoden spicken kann. DElphi versteckt einige Teile des Recors vor dem Programmierer, aber eine Klasse ist ein record, womit Properties nichts anderes als Record-Felder sind. |
Re: Was ist ein "Property" intern?
Zitat:
Folgende zwei Konstruktionen erzeugen also den gleichen Code:
Delphi-Quellcode:
type
TMyClass1 = class private FField: Integer; public Field: Integer read FField; end; begin with TMyClass1.Create do begin ShowMessage(InttoStr(Field)); Free; end; //oder with TMyClass1.Create do begin ShowMessage(InttoStr(FField)); Free; end; |
Re: Was ist ein "Property" intern?
Zitat:
...:cat:... |
Re: Was ist ein "Property" intern?
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:02 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