Autor Beitrag
dekoepke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP, Suse Linux 11.1
Delphi 5 Prof. Delphi 7 Enterprise Edition
BeitragVerfasst: Do 12.02.09 17:40 
Hallo Leute,
ich habe mit diesem Code Probleme. Ich weiß nicht warum mir der Debugger beim Onclick-Ergebnis eine Zugriffsverletzung zurückgibt.

ausblenden volle Höhe 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:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, XPMan, StdCtrls;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    XPManifest1: TXPManifest;
    Label1: TLabel;
    procedure ListView1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListView1Click(Sender: TObject);
var i:Integer;
begin
for i := 0 to ListView1.Items.Count do
 begin
  if (Listview1.Items.Item[i].Selected = true) then
   begin
    Label1.Caption := Listview1.Items.Item[i].Caption;
   end;
 end;
end;

end.


Vielen Dank für eure Antworten im vorraus.

MfG
dekoepke
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von dekoepke am Do 12.02.09 17:43, insgesamt 1-mal bearbeitet
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Do 12.02.09 17:43 
Titel: Re: Listview Onclick Ergebnis löst Exeption Fehler aus..
ausblenden Delphi-Quelltext
 
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
{ ... }
procedure TForm1.ListView1Click(Sender: TObject);
var i:Integer;
begin
for i := 0 to ListView1.Items.Count-1 do
 begin
  if (Listview1.Items.Item[i].Selected = true) then
   begin
    Label1.Caption := Listview1.Items.Item[i].Caption;
   end;
 end;
end;

Das war wohl einer zu viel ;)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 12.02.09 17:43 
Titel: Re: Listview Onclick Ergebnis löst Exeption Fehler aus..
user profile icondekoepke hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
for i := 0 to ListView1.Items.Count do					
Der letzte Index ist nicht die Anzahl.
Beispiel: Anzahl = 5
--> Indizes 0..4 ;-)
dekoepke Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28

Win XP, Suse Linux 11.1
Delphi 5 Prof. Delphi 7 Enterprise Edition
BeitragVerfasst: Do 12.02.09 17:44 
Wahnsinn.
Ihr seit die besten :D :wink: :!: