Entwickler-Ecke

Delphi Language (Object-Pascal) / CLX - Globale Variablen für alle Units?


GR-Thunderstorm - Sa 13.05.06 14:13
Titel: Globale Variablen für alle Units?
Hi Leutz,
ich hab mal ne generelle Frage:
Angenommen in Unit1 deklariere ich ne Variable X als integer, gilt diese Variable dann auch in allen anderen Units dieses Programs? Wenn nicht, ist es auf andere Weise machbar?

DANKE!


Xion - Sa 13.05.06 14:14

wenn du die Unit unter uses einbindest funktionierts normalerweise schon.


Tino - Sa 13.05.06 14:24

Neben dem Hinweis von Xion ist auch wichtig, das die Variable im Interface Abschnitt definiert wird und nicht im Implementation Abschnitt.


GR-Thunderstorm - Sa 13.05.06 18:24

Wäre das also so richtig?


Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  x:integer;          {<----- an dieser Stelle?}

implementation

uses Unit2;

{$R *.dfm}
begin
...
end.