hi,
globale Variablen sind für mich ein altes Pascal Relikt. In Objekt-Pascal sollte man besser objektorientierte Strukturen verwenden.
Delphi-Quellcode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 =
class(TForm)
private
{ Private-Deklarationen }
variable :
String;
public
{ Public-Deklarationen }
function _variable :
string;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1._variable :
string;
begin
result:=variable;
end;
end.
Die andere
Unit:
Delphi-Quellcode:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 =
class(TForm)
Label1: TLabel;
private
{ Private-Deklarationen }
procedure beispiel;
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.beispiel;
begin
Label1.Caption:=Form1._variable;
end;
end.
Auf den ersten Blick etwas umständlicher, aber wie ich finde auf jedenfall strukturierter.