Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Strange AV (https://www.delphipraxis.net/178061-strange-av.html)

WojTec 14. Dez 2013 18:35

Delphi-Version: XE5

Strange AV
 
Delphi-Quellcode:
procedure TForm1.ListView1Resize(Sender: TObject);
var
  I: Integer;
  FileName: string;
begin
  for I := 0 to ListView1.Items.Count do
  begin
    FileName := ListView1.Items[I].SubItems[4];
    FileName := MinimizeName(FileName, ListView1.Canvas, ListView1.Column[5].Width);
    ListView1.Items[I].SubItems[4] := FileName
  end;
end;
There is 7 columns. Why this raises AV :?: :o

Medium 14. Dez 2013 18:38

AW: Strange AV
 
Because .Count gives you the count. Not the highest index. That would generally be Count-1, in zero based arrays and lists.
(I would be interested in how many threads here deal with this infamous off-by-one issue :))

WojTec 14. Dez 2013 18:56

Re: Strange AV
 
Oh my gosh! I totally did not notice it! What the completely stupid error :oops:

himitsu 14. Dez 2013 20:01

AW: Strange AV
 
The title of your posts I would call "bad".

And your description of the error is even worse.
- Neither the error occurs
- Yet what it is for an error

Yes, the messages can be copied from the error messages by pressing Ctrl + C.

And no, the message is not "strange". She even tells you exactly as you did wrong.


Zitat:

List index out of bounds (%d)

Medium 15. Dez 2013 02:39

AW: Re: Strange AV
 
Zitat:

Zitat von WojTec (Beitrag 1239794)
Oh my gosh! I totally did not notice it! What the completely stupid error :oops:

Rest assured: It wasn't the last time :) Those will follow us into our graves, I fear. The only "stupid" thing was to post it here, and expose us all to the fact, that even renowned programmers, as many of us are, aren't impregnable to the most basic faults available ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:32 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz