![]() |
Variable in Record für Unit (initialization) deklarieren
Ich komme gerade nicht weiter. Wie muss man eine Variable in einem Record deklarieren, wenn diese nur für diese ein Unit zur Verfügung stehen soll?
Gebraucht wird die Variable im initialization-Teil. In dieser Variablen vom Typ TFormatSettings möchte ich die aktuell von Windows genutzten Formate FormatSettings.ShortTimeFormat, FormatSettings.LongTimeFormat, FormatSettings.ShortDateFormat und FormatSettings.LongDateFormat speichern. |
AW: Variable in Record für Unit (initialization) deklarieren
Zitat:
Delphi-Quellcode:
.
private
Delphi-Quellcode:
interface uses System.SysUtils;
type TSomeRecord = record private var originalFormatSettings: TFormatSettings; end; var iLikeGlobalVariables: TSomeRecord; implementation initialization iLikeGlobalVariables.originalFormatSettings := System.SysUtils.FormatSettings; end. |
AW: Variable in Record für Unit (initialization) deklarieren
Delphi-Quellcode:
Das hat mir gefehlt.
iLikeGlobalVariables: TSomeRecord;
Kann man das irgendwie lokal deklarieren, sodass andere Units diese Variable nicht sehen? Denn ich arbeite grundsätzlich mit Records und Class-Angaben wie diese hier
Delphi-Quellcode:
und rufe das über TUnitX.FunctionY(Z); auf.
class procedure TUnitX.FunctionY(Param: Z);
|
AW: Variable in Record für Unit (initialization) deklarieren
Verschiebe die Varialen-Deklaration vom
Delphi-Quellcode:
in den
interface
Delphi-Quellcode:
-Teil, schon sieht sie außer deiner Unit keiner mehr.
implementation
|
AW: Variable in Record für Unit (initialization) deklarieren
Delphi-Quellcode:
implementation
var iLikeGlobalVariables: TSomeRecord; |
AW: Variable in Record für Unit (initialization) deklarieren
:thumb:
Wieder was gelernt. Danke. Jetzt kann ich im initialization-Teil folgendes machen, genau wie gewünscht
Delphi-Quellcode:
Natürlich nutze ich andere Variablennamen.
iLikeGlobalVariables.originalFormatSettings.ShortDateFormat := FormatSettings.ShortDateFormat;
usw |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12: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