Hab eine typische Anfängerfrage:
Ich möchte aus der Unit1 die Form2 der Unit2 aufrufen und in der Unit2 eine Funktion aus Unit1 verwenden.
Geht das?
Wenn ja: Wie?
Verwende folgenden Code, der nicht funktioniert (Funktion Test kennt er nicht)
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: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private public end;
var Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
function test : string; begin result:='Hallo'; end;
procedure TForm1.Button1Click(Sender: TObject); begin Form2.show; end;
end. |
Und Unit2:
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: 29: 30: 31: 32: 33: 34:
| unit Unit2;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm2 = class(TForm) Button1: TButton; Label1: TLabel; procedure Button1Click(Sender: TObject); private public end;
var Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm2.Button1Click(Sender: TObject); begin label1.caption:=form1.test; end;
end. |
Wie muss ich die Funktion Test in Unit2 einbinden?