Autor Beitrag
DaKrissX84
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mi 12.03.03 18:10 
Hi Leute!

Folgende Frage: (für die ich mich fast schon schäme)

Ich möchte ein einfaches, eindimensionales Array of String mit sehr vielen Wörtern füllen.

Meine Frage:
Gibt es eine einfachere Methode als diese hier:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
var
myArray :array[0..10] of String;
myArray[0] := 'Wort1';
myArray[1] := 'Wort2';
myArray[2] := 'Wort3';

//und so weiter...


Kann man sich dieses 'myArray[n] := ' nicht irgendwie sparen??

Vielen Dank!
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mi 12.03.03 18:12 
Also gaaaaanz streng an Deinem Beispiel entlang: :wink:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
var 
myArray :array[0..10] of String; 
i:integer
begin
for i:=0 to 10 do 
     myArray[i] := 'Wort'+inttostr(i+1);
end;
Popov
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 1655
Erhaltene Danke: 13

WinXP Prof.
Bei Kleinigkeiten D3Pro, bei größeren Sachen D6Pro oder D7
BeitragVerfasst: Mi 12.03.03 18:39 
Ich glaube der meint das:

ausblenden Quelltext
1:
2:
3:
4:
5:
var 
  myArray :array[0..10] of String = ('Wort1', 'Wort2', 'Wort3', ...);
begin
  ...
end;

_________________
Popov
DaKrissX84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mi 12.03.03 18:45 
@ popov:

Genau das meinte ich.
Allerdings:
Da kommt bei mir ne Fehlermeldung, wenn ichs so versuche:

[Fehler] (35): Lokale Variablen können nicht initialisiert werden


Is das normal??
fcg
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 360

WinXP
D3 Prof, D6 Pers
BeitragVerfasst: Mi 12.03.03 19:55 
mußt das array als globale variabel definieren...

_________________
.: Wer für alles offen ist, kann nicht ganz dicht sein! :.
naleh
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: Do 13.03.03 17:38 
Kleine Frage dazu,
Warum benutzt ihr keine Stringlisten(TStrings)?
MfG naleh
DaKrissX84 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Do 13.03.03 19:40 
Kleine Gegenfrage:
(Die gleichzeitig deine Frage beantworten sollte...)

Was sind Stringlists bzw. was ist der Unterschied zwischen Stringlist, String und Array?? :?
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Do 13.03.03 19:51 
Stringlisten sind im Grunde nichts anderes als arrays. Arrays kommen noch aus den Pascalzeiten. Die Stringliste ist wie der Name schon sagt eine Ansammlung von Strings. In der Liste kann ich halt durch angeben einer Itemnummer einen bestimmten String aus vielen herausziehen. Das gleiche geht auch mit Arrays. Es sind noch mehr funktionen damit möglich, die alle in der OH von Delphi erklärt sind.

Strings sind einzelne zeichenketten.

Schaue Dir auch mal noch dieses Tutorial an, dass gibt eine Einführung in Array und wozu sie zu gebrauchen sind.