Autor Beitrag
schitho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: Di 12.08.03 12:23 
Hi,

ich hab eine blöde Anfängerfrage (nicht böse sein). :oops:

Ich eine Formular (Form1) und möchte von diesem Formular über einen Button (Button1) ein anderes Formular (Form2) aufrufen. In diesem Formular (Form2) soll der Anwender nun einige Einstellungen vornehmen können. Diese Einstellungen sollen direkt auf das ursprüngliche Formular (Form2) wirken.

Konkret meine damit folgendes:

In Form1 wird eine Variable deklariert und mit einem Wert versehen. In Form2 soll diese Variable verändert werden können, sodass in Form1 damit weiterarbeiten kann.

Wie mach ich das?

Ich fürchte es ist eine wirklich dämliche Frage, trotzdem wär ich für einen Hinweis dankbar. :lol:

_________________
(Sorry! Leider ewiger Delphi-Neuling)
Terra23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: Di 12.08.03 12:42 
Du mußt die jeweilige Variable mit dem Namen der Form davor versehen und dann müßtest du eigentlich damit arbeiten können. Da du ja Form2 über Form1 aufrufst, gehe ich fest davon aus, daß in der Uses-Anweisung eine Form die jeweils andere beinhaltet und dann kannst du so arbeiten:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm2.Button1Click(Sender: TObject);
begin
<span style="font-weight: bold">Form1.</span>Integervariable:=2;
end;


Damit hast du per Knopfdruck in Form2 die in der Form1 deklarierte Variable bearbeitet und ihr den Wert "2" gegeben. Das müßte eigentlich so gehen. Vergiß bitte nicht, daß die Variable global sein muß. :-)

_________________
Hasta La Victoria Siempre
schitho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: Di 12.08.03 13:00 
Das funktioniert nicht. :cry:

Er kennt dann zwar die Objekte (wenn ich unit1 in uses aufnehme), aber nicht die Variablen. :(

_________________
(Sorry! Leider ewiger Delphi-Neuling)
Tana´Ri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 230



BeitragVerfasst: Di 12.08.03 13:07 
in form2 spricht du vars aus form1 über form1 an
bzw. schreib mal den unit namen davor geht och !

-> z.b. (in form2)
ausblenden Delphi-Quelltext
1:
2:
3:
     form1.reqNumber := 2;
// mit unit name
    Unit1.form1.reqNumber := 2;


muessen allerding miteinander verbunden sein; sprich USES

Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.

_________________
mfg
Tana´Ri
schitho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: Di 12.08.03 13:18 
Scheinbar mach ich was falsch :(

Hier der Quellcode:

ausblenden volle Höhe 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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  test : string;

implementation

uses Unit2;

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  test:='hallo';
  label1.Caption:=test;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.Show;
end;

end.


und hier unit2

ausblenden volle Höhe 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:
29:
30:
31:
32:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  form1.test:='juju';
  form1.Label1.Caption:=form1.test;
end;

end.


Wo liegt nun der Fehler?

_________________
(Sorry! Leider ewiger Delphi-Neuling)
schitho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: Di 12.08.03 13:21 
Ups.

Beim nochmalige hinschauen hab ich den Fehler gefunden.

Es heist unit1.test und nicht form1.test. :idea:

Thanx! :lol:

Du hast mir sehr geholfen. :dance2:

_________________
(Sorry! Leider ewiger Delphi-Neuling)
Tana´Ri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 230



BeitragVerfasst: Di 12.08.03 13:25 
test ist ne globale variable und nicht eine des Obj Form 1

richtig wäre

form1.caption := unit1.test;

_________________
mfg
Tana´Ri