Autor Beitrag
DerKrasseHans
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Di 07.01.03 16:44 
Ganz kleine Frage,
wenn man einem dynamischen array (meinetwegen: dynColors: array of TColor oder so) mit SetLength eine best. Anzahl an Einträgen zuweist (z.B. SetLength(dynColors, 23) ). Ist dann das erste Element immer beim Index 0 oder muss ich es über:
dynColors[Low(dynColors)]
explizit adressieren, weil man sich nich sicher sein kann, dass das erste Element beim Index zu finden ist?
Wenn aber das erste Element immer bei Index 0 ist, warum gibt es den Befehl Low(var X) für dynamische Arrays überhaupt?
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Di 07.01.03 17:24 
Hallo,

Low und High sind ja nicht nur für dynamische Arrays vorhanden. Wenn Du zum Beispiel ein statisches Array definierst:
ausblenden Quelltext
1:
2:
Var
  Test: Array [1..10] of Integer

dann ergibt
Low (Test) den Wert 1 und nicht 0.

Ganz hilfreich finde ich die beiden Befehle auch in zusammenhang mit Aufzählungstypen. Zum Beispiel so:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Type
  tWebsites = (idWebsiteAuqDe, idWebsiteDelphiForumDe);

Const
  cWebsiteName : Array [tWebsites] of String = ('AUQ.de', 'Delphi-Forum.de');

{...}

Var
  Id: tWebsites;
Begin
  For Id := Low (Id) To High (Id) Do
    ListBox1.Items.AddObject (cWebsiteName [Id], Ord (Id));
End;


gruß
TINO
DerKrasseHans Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Fr 10.01.03 19:09 
Hi Tino,
danke erstmal für deine Antwort, ich wusste gar nicht, dass man die Grenzen von statische Arrays durch Enumerationen festlegen kann, naja, aber ich wollte eigentlich wissen, ob dynamische Arrays immer ihr erstes Element am Index 0 haben, so dass man über dynArr[0] immer das erste Element adressiert, oder muss man das erste Element durch
ausblenden Quelltext
1:
dynArr[Low(dynArr)]					

adressieren?
Nicht, dass ich irgendwann eine Zugriffsverletzung bekommen, wenn ich davon ausgehe das erste Element ist am Index 0, weil das erste Element am Index "sonstwo" zu finden ist.
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Fr 10.01.03 21:23 
Schau dir doch in der Online Hilfe die Funktion Low an. Dort steht was du brauchst und noch mehr.

_________________
Ist Zeit wirklich Geld?
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Sa 11.01.03 14:21 
DerKrasseHans hat folgendes geschrieben:
aber ich wollte eigentlich wissen, ob dynamische Arrays immer ihr erstes Element am Index 0 haben

Davon kannst Du eigentlich ausgehen! Ich mache es aber immer über die Funktion Low!

Gruß
TINO
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Sa 11.01.03 17:12 
Da gibt's nur noch eins zu sagen:
Mein lieblingsakronym "rtfm".

Delphi-Hilfe hat folgendes geschrieben:

Dynamic arrays are always integer-indexed, always starting from 0.

Klar?
Die Leute, die es also mit Low( + i) machen, sind viel zu paranoid (nix für ungut Tino ;-) )

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
DerKrasseHans Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18



BeitragVerfasst: Sa 11.01.03 23:05 
moin,
danke tommie-lie genau das wollte ich wissen; die seite in der delphi-hilfe hab ich nicht gefunden.
Zitat:
Die Leute, die es also mit Low( + i) machen, sind viel zu paranoid

genauso paranoid hab ich mich auch gefühlt nachdem ich dein posting gelesen habe *g*
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: So 12.01.03 14:16 
im Codeeditor "array" eingeben, Cursor drauf, F1 drücken, Dynamic Arrays auswählen, lesen. So findet man zu fast jedem Thema, das nichts mit der API zu tun hat, alle Infos, die man braucht.

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert