Autor Beitrag
Deerfield
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi XE Pro
BeitragVerfasst: Mi 15.10.03 14:09 
Hallo,

hab mal ne bescheidene Frage. Wie kann ich denn eine in einer Unit deklarierte Variable übergreifend in allen anderen Units auswerten bzw. verwenden?

Mfg
Deerfield
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Mi 15.10.03 14:12 
Hallo,

indem Du sie im interface-Bereich deklarierst. Diese Unit bindest Du dann in die Units ein, die die Variablen benötigen.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 15.10.03 14:42 
was in dem zusammenhang auch nützlich ist, wenn es sichtbarkeits-oder NamensGleichheitsProbleme gibt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
uses DeineUnit;

...

  DeineUnit.DeineVar := $AF39B;
Mit dem unitnamen und dem punkt kannst du den zugriff qualifizieren :wink:

_________________
mfg.
mâximôv
Deerfield Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi XE Pro
BeitragVerfasst: Mi 15.10.03 14:44 
Naja, das Szenario sieht folgendermaßen aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
unit sprache;

interface

const  sp_deutsch  = 0;
       sp_englisch = 1000;

procedure Spracheinstellung(offset:Integer);

implementation

...


wobei hier

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
unit Main;

...

procedure TMainForm.Deutsch1Click(Sender: TObject);
begin
  spracheinstellung(sp_deutsch);
end;

...


der aktuelle Wert gesetzt wird.

Und auf die Variable offset (also den Wert) will ich von einer anderen Unit aus zugreifen. Ich will aber den aktuell gesetzten Wert benutzen.

MfG
Deerfield
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 15.10.03 14:50 
*GG* procedure Spracheinstellung(offset:Integer);

'offset' ist aber keine variable...sondern ein parameter...mit dem aufruf..

ausblenden Delphi-Quelltext
1:
spracheinstellung(sp_deutsch);					


...ist in der function dieser parameter mit 'sp_deutsch' gefüllt.

_________________
mfg.
mâximôv
Deerfield Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi XE Pro
BeitragVerfasst: Mi 15.10.03 14:53 
*g* oder so :wink:

und ich brauch halt diesen aktuellen Parameterwert zur weiteren Verwendung.

MfG
Deerfield
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 15.10.03 14:56 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
unit sprache;

interface

var actOffset:Integer;

const  sp_deutsch  = 0;
       sp_englisch = 1000;

procedure Spracheinstellung(offset:Integer);

implementation

procedure Spracheinstellung(offset:Integer);
begin
  ..
  actOffset := offset; // ;)
end;

...


wobei hier

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
unit Main;

...

procedure TMainForm.Deutsch1Click(Sender: TObject);
begin
  spracheinstellung(sp_deutsch);

 showMessage(intToStr(  sprache.actOffset  )); 
end;

...



sowas in der art?

_________________
mfg.
mâximôv
maze2k
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 252

WIN 95, WIN NT 4.0, WIN 98, WIN 98SE, WIN 2000, RedHat Linux 7.3, Mandrake Linux 9.2, Knoppix Linux 3.3
D6 Pers
BeitragVerfasst: Mi 15.10.03 14:57 
Ich schreib mir hier gerade einen ab wie man ne Variable übergibt (was eigentlich nich schwer is... aber hab extra ein Beispiel-Prog gemacht)

und da seh ich dass du nur auf die Prozedur zugreifen willst...

also in deine Unit Main bindest du bei USES einfach die Unit sprache ein.

und die Prozedur "spracheinstellung()" startest du aus deinem zweiten Form dann einfach mit:

ausblenden Delphi-Quelltext
1:
SpracheForm.spracheinstellung(sp_deutsch);					


(ich nehm einfach mal an das die Form der Unit sprache "SpracheForm" heisst)

_________________
Wer das Konzept der Unendlichkeit verstehen will, muss nur das Ausmaß menschlicher Dummheit betrachten. (Voltaire)
Deerfield Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 35


Delphi XE Pro
BeitragVerfasst: Mi 15.10.03 15:07 
Hey, das funktioniert ja sogar. Vielen Dank! :D

(@maximus 8) )


Zuletzt bearbeitet von Deerfield am Mi 15.10.03 15:28, insgesamt 1-mal bearbeitet
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mi 15.10.03 15:15 
wen meinst du jetzt?

_________________
mfg.
mâximôv