Code: Alles auswählen
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.showmodal;
end;
{$R *.lfm}
end.
-----------
Und für Form2:
unit Unit2;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
type
TForm2 = class(TForm)
private
{ private declarations }
public
{ public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.lfm}
end.
Außerdem möchte ich eine Variable in beiden Formularen verwenden. Es sollte eine Integer Variable sein. Ich will auf Form1 einen Kontostand haben und in Form2 etwas kaufen, wobei in Form2 auch der Kontostand stehen sollte. Ich wollte das ganze mit einer Globalen Variable lösen. Sobald das Programm gestartet wird sollte in Form1 der Kontostand stehen. Das habe ich auch ohne Probleme geschafft. Nur bin ich icht ganz sicher wie es jetzt weitergeht. Ich kann es auch nicht ausprobieren, weil ich ja immer diese Fehlermeldung bekomme. Soweit bin ich bisher:
Code: Alles auswählen
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
kontostand: integer;
implementation
uses unit2;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
kontostand:=10000;
label1.caption:=IntToStr(kontostand);
end;
{$R *.lfm}
end.