Autor Beitrag
bruce185
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Do 11.05.06 11:33 
hallo,
also ich habe folgendes probiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
  Form1: TForm1;
  Max: integer;
  Wort[Max]: string;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Max := 3;
  randomize;
  Wort[0] = 'Hallo...';
  Wort[1] = 'wie geht es dir?';
  Wort[2] = 'Was ist?';
end;



könnt ihr mir vieleicht sagen was ich da falsch gemacht habe?
Vielen Dank schonmal :wink:

Gruss Andreas
Horst_H
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1654
Erhaltene Danke: 244

WIN10,PuppyLinux
FreePascal,Lazarus
BeitragVerfasst: Do 11.05.06 11:36 
Hallo,

Du moechstest also ein dynamisches array.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var   
  Form1: TForm1;   
  Max: integer;   
  Wort: array of string;   

implementation   

{$R *.dfm}   

procedure TForm1.FormCreate(Sender: TObject);   
begin   
  Max := 3;
  setlength(Wort,max);//Array Laenge auf max festlegen)
  randomize;   
  Wort[0] = 'Hallo...';   
  Wort[1] = 'wie geht es dir?';   
  Wort[2] = 'Was ist?';   
end;


Gruss Horst
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 11.05.06 11:39 
Entweder Du nimmst ein statisches Array
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
const
  Max = 3;
var
  Form1: TForm1;
  Wort: array[0..Max-1] of string;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  randomize;
  Wort[0] = 'Hallo...';
  Wort[1] = 'wie geht es dir?';
  Wort[2] = 'Was ist?';
end;

oder ein dynamisches Array
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var
  Form1: TForm1;
  Max: integer;
  Wort: array of String
;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Max := 3;
  randomize;
  SetLength (Word,Max);
  Wort[0] = 'Hallo...';
  Wort[1] = 'wie geht es dir?';
  Wort[2] = 'Was ist?';
end;


und noch besser Du ziehst die Variable Word in den Form1-Private-Bereich und machst FWord daraus!

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Do 11.05.06 11:46 
ich danke dir für die schnelle antwort :lol:

aber noch ein Problem gibts, wenn ich auf den Button klicke, dann soll als random ein Wort in Label1 angezeigt werde, so hab ich das probiert:

ausblenden 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:
var
  Form1: TForm1;
  Max, Nr: integer;
  Wort: array of string;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Max := 3;
  setlength(Wort,Max);
  randomize;
  Wort[0] := 'Hallo...';
  Wort[1] := 'was geht?';
  Wort[2] := 'nix man...';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Nr := random(Max);
  Label1.Caption := Wort[Max];
end;


und wenn ich auf den Button klicke kommt Zugriffsverletzung, wieso?
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 11.05.06 11:48 
Weil Max 3 ist. Dadurch verlässt du den zulässigen Bereich des Arrays. Du musst Nr statt Max schreiben. (Wort[Nr])
Fighter#1
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 787

Win XP, Ubuntu 8.04
Turbo Delphi 2006, Delphi 2005 Pe, Delphi 5 Pe, Netbeans 6.1, Eclipse, Microsoft VisualC#, Dev C++, PHP, HTML, CSS
BeitragVerfasst: Do 11.05.06 11:52 
Oder Max-1, dann ist es immer noch so 'variabel'

_________________
Wer andere beherrscht ist stark,
wer sich selbst beherrscht ist mächtig. Lao Tse
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Do 11.05.06 11:53 
ups, hab mich vieleicht vertippt oder so, hab ich ja garnet gesehen das ich Max statt Nr geschrieben habe, vielen dank für eure antworten, ihr habt mir echt weiter geholfen :lol:

Gruss Andreas
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 11.05.06 11:55 
Inhalt gelöscht, da es sich erledigt hat. (War zu langsam)
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Do 11.05.06 14:54 
noch eine Frage?
und zwar wie kann ich das hier als Konstante vereinbarung benutzen?

const string DateiName := 'Wortliste';

das problem ist das ich erfahrung für Borland C++ Builder gesammelt habe und es in Delphi ja anders ist, deshalb weiss ich net wie ich das in Delphi hin bekomme :wink:

Gruss Andreas
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 11.05.06 15:10 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
const 
  DateiName: String  = 'Wortliste';
  //oder einfacher
  DateiName = 'Wortliste';

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Do 11.05.06 15:54 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
var
  Form1: TForm1;
  Wort : Array[0..2]of String =('Hallo...',
                                'was geht?',
                                'nix man...');
  i:Integer;
implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  i:=Random(3);
  Label1.Caption := Wort[i];
end;