Einzelnen Beitrag anzeigen

Benutzerbild von Manzoni
Manzoni

Registriert seit: 15. Feb 2004
Ort: Berlin
120 Beiträge
 
Delphi 7 Enterprise
 
#12

Re: Werte an andere Form übergeben

  Alt 22. Feb 2004, 17:15
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.
Bob
  Mit Zitat antworten Zitat