Autor Beitrag
commin
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 17

WinXP
Delphi 5
BeitragVerfasst: Mi 15.02.06 15:53 
Hallo,

ich habe ein kleines Problem. Ich möchte in unit2 auf eine varibale in unit1 zugreifen. Wo muss ich diese variablen dann genau deklarieren und wie läuft der zugriff ab (form1.variablenname?)?

Danke für Tipps :)
Danny87
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 688

Windows 10 Pro 64bit
Sprachen: HTML, PHP, JavaScript, Delphi || IDE: RAD Studio 10.1 Berlin Starter, WeBuilder
BeitragVerfasst: Mi 15.02.06 15:57 
erst mal :welcome: in der EE :-D


Du musst die variable in unit 1 global deklarieren und
die unit 1 in die uses-klausel der unit 2 aufnehmen (uses Unit2;)

gruss daniel
commin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 17

WinXP
Delphi 5
BeitragVerfasst: Mi 15.02.06 16:06 
Wo genau ist der globale-abschnitt zum deklarieren? Ich habe es bei publik versuche - aber leider den fehler bekommen: end-erwartet.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 15.02.06 16:07 
Moin und :welcome: im Delphi-Forum!

user profile iconcommin hat folgendes geschrieben:
Wo genau ist der globale-abschnitt zum deklarieren? Ich habe es bei publik versuche - aber leider den fehler bekommen: end-erwartet.

Das ist schon gar nicht so schlecht, die Deklaration im public-Abschnitt. Mir scheint aber eher, du hast einen Syntaxfehler in der Deklaration, zeig doch mal den Code.

cu
Narses
commin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 17

WinXP
Delphi 5
BeitragVerfasst: Mi 15.02.06 16:09 
public

var anmeldemodus:string;
{ Public-Deklarationen }

end;
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Mi 15.02.06 16:10 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  Globale_Variable_aus_unit_2: String; <=

implementation
 uses unit1;
{$R *.dfm}


da musses hin ;)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 15.02.06 16:16 
Moin!

@user profile iconNoTVerYEvilPzYchO: Nein, da muss es nicht hin; nur, wenn es Programmglobal sein soll, wovon ich abrate! :wink:

Du hast ein var in der Deklaration, die muss raus, also so:
ausblenden Delphi-Quelltext
1:
2:
3:
public 
  anmeldemodus: String; 
end;

cu
Narses
commin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 17

WinXP
Delphi 5
BeitragVerfasst: Mi 15.02.06 16:19 
Irgendwie stehe ich ein weing auf der "Leitung".

Ich deklariere die variable a in unit 1 als string. Nun will ich in unit 2 darauf zugreifen. Wenn ich dass jetzt richtig verstehe, deklariere ich doch aber die variable a in unit 2 neu - und sommit wird doch diese neu initialisiert und ich habe faktisch eine neue varibale nur mit dem gleichen Namen?

*** hatte den letzten Beitrag noch nicht gelesen - sorry - ich probiere es mal ****
commin Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 17

WinXP
Delphi 5
BeitragVerfasst: Mi 15.02.06 16:22 
Es geht! Vielen Dank!