Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: Zugriff auf unitübergreifende Variablen

  Alt 17. Dez 2015, 13:00
Wenn du wirklich etwas Globales benötigst, dann verwende eine statische Klasse mit Eigenschaften.

statt
Delphi-Quellcode:
unit uGlobal;

interface

var
  foo : Integer;

inmplementation

end.
das hier
Delphi-Quellcode:
unit uGlobal;

interface

type
  Globals = class abstract
  private
    class var _Foo: Integer;
    class function GetFoo; static;
    class procedure SetFoo( const Value: Integer ); static;
  public
    class property Foo : Integer read GetFoo write Setfoo;
  end;

implementation

class function Globals.GetFoo: Integer;
begin
  Result := _Foo;
end;

class procedure SetFoo( const Value: Integer );
begin
  _Foo := Value;
end;

end.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat