Autor Beitrag
Janus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Sa 08.03.03 18:32 
Hallo zusammen, gibt es Delphi sowas wie statische Variablendeklarationen ?

Eine lokale Variable, die jedoch beim Verlassen des aktuelle Scope nicht zerstört wird...

Bsp: c - code

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
int inc(void){
 static int i = 0;
 return i++;
}

int a = inc(); // a ist jetzt 0
a = inc(); // a ist jetzt 1
a = inc(); // a ist jetzt 2
a = inc(); // a ist jetzt 3

usw...



Gruss Janus

Moderiert von user profile iconKlabautermann: Code-Tags hizugefügt.

_________________
Don't give in the hate, that leaves to the dark side of the force !!!
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Sa 08.03.03 18:37 
Titel: logisch
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
program test;

var 
  I: Integer; // Globale Variable

procedure Blub;
var I:Integer; // lokale Variable
begin
  I:=9;
end;

procedure Blab;
begin
  I:=8;
end;

end.

Grüße
MSCH
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 08.03.03 18:38 
Mit der $J+ Direktive (Siehe OH) geht's:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Timer1Timer(Sender: TObject);
const
  {$J+} Test : Integer = 7; {$J-}
begin
  Inc(Test);
  Caption := Inttostr(Test)
end;


Moderiert von user profile iconKlabautermann: Code-Tags hinzugefügt.
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Sa 08.03.03 18:46 
Frägt sich nur, wie lange es noch mit {$J+}...{$J-} geht.

_________________
Ist Zeit wirklich Geld?
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Do 13.03.03 21:26 
Ich kenne mich damit nicht aus, daher: Wozu konstanten, die variabel sind? Etwa, um sie z uinitialisieren? Das kann man auch mit 'ner Variable, wenn sie keiner Klasse angehört. Oder welchen Hintergrund hat das?

_________________
Life is a bad adventure, but the graphic is really good!
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Fr 14.03.03 00:02 
Andreas Pfau hat folgendes geschrieben:
Das kann man auch mit 'ner Variable
Aber erst ab Delphi 6.
var MyVar: Integer = 10;musste man in den Vorgängerversionen so schreiben.
ausblenden Quelltext
1:
const MyVar: Integer = 10;					

_________________
Ist Zeit wirklich Geld?
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 14.03.03 12:56 
Ah... so ist das.

dann würde ich 'ne bedingte Kompilierung vorschlagen: Bis D5 mit const, ab D6 mit var.

_________________
Life is a bad adventure, but the graphic is really good!