Autor Beitrag
Calculon
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Do 11.09.08 13:51 
Hi zusammen,

wie kann ich festellen, ob ein gültiger array Eintrag existiert? Also in anderen Worten: Wurde für diesen Index bereits Speicher angefordert?

Wenn ich

ausblenden Delphi-Quelltext
1:
2:
  if data[i] = nil then
    ShowMessage('NIL');

ausführe, dann kommt immer eine Zugriffsverletzung bevor auf nil geprüft werden kann...

Gruß
--

_________________
Hallo Mutti
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 11.09.08 13:53 
length(myArray) < i ?

_________________
We are, we were and will not be.
Calculon Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 676

Win XP Professional
Delphi 7 PE, Delphi 3 PRO
BeitragVerfasst: Do 11.09.08 14:02 
Thx! :idea:

Gruß
--

_________________
Hallo Mutti
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 11.09.08 14:48 
Muss es nicht korrekterweise high(myArray) < i heißen? :gruebel:
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 11.09.08 14:49 
ich glaube es geht beides.

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
wazup
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 101

Windows XP
Delphi 2009
BeitragVerfasst: Do 11.09.08 14:53 
So weit ich das weis ist das so:

(High(MyArray)) = (Length(MyArray) - 1) Bessere erklärung fiel mir jetzt nicht ein *LOL*


Zuletzt bearbeitet von wazup am Do 11.09.08 14:57, insgesamt 2-mal bearbeitet
baka0815
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 489
Erhaltene Danke: 14

Win 10, Win 8, Debian GNU/Linux
Delphi 10.1 Berlin, Java, C#
BeitragVerfasst: Do 11.09.08 14:56 
Nicht ganz richtig.

Man kann ein Array von [5..20] definieren, dann wäre High()=20, Low()=5, aber Length()=16.
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Do 11.09.08 15:00 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if i in [low(MyArray)..high(MyArray)] then
begin

end;

Geht nur, wenn das Array weniger als 255 Werte hat.

Sonst:
ausblenden Delphi-Quelltext
1:
if (i >= low(MyArray)) and (i <= high(MyArray)) then					

_________________
PROGRAMMER: A device for converting coffee into software.