Autor Beitrag
schitho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: Sa 05.03.05 23:02 
Hi

ich verwende folgende Procedure:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure ItemAddToLV (s1,s2,s3,s4,s5,s6 : string; chk : boolean; i : integer);
var
  ListItem: TListItem;
begin
  ListItem := FForm1.ListView1.Items.Add;
  ListItem.Caption := s1;
  ListItem.SubItems.Add(s2);
  ListItem.SubItems.Add(s3);
  ListItem.SubItems.Add(s4);
  ListItem.SubItems.Add(s5);
  ListItem.SubItems.Add(s6);
  ListItem.Data:=Pointer(i);
  ListItem.Checked:=chk;
end;


In Data speicher ich einen Zeiger zu einem Integer-Wert.

Wie kann ich nun aus Data den Intergerwert wieder auslesen und einer Integervariablen zuweisen?

Gruß
Thomas

_________________
(Sorry! Leider ewiger Delphi-Neuling)
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Sa 05.03.05 23:16 
Es sollte nicht Pointer(i) sondern @i heißen.

AXMD
schitho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: So 06.03.05 20:35 
Aha...

Aber wie les ich es wieder aus?

Hab es so probiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
  x : integer;
begin
  x:=ListView1.Selected.Data^;
^

Doch da bekomm ich leider eine Fehlermeldung:

[Fehler] Unit1.pas(515): E2010 Inkompatible Typen: 'Integer' und 'procedure, untyped pointer or untyped parameter'

Wie muss ich den Code ändern, damit es funktioniert?

Gruß
Thomas

_________________
(Sorry! Leider ewiger Delphi-Neuling)
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: So 06.03.05 20:37 
Typecasting lautet das Zauberwort ;)

ausblenden Delphi-Quelltext
1:
x := Integer(ListView1.Selected.Data^);					


woher soll Delphi denn wissen welchen Typ die Daten haben auf die der Zeiger zeigt ;)

AXMD
schitho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: So 06.03.05 21:05 
Danke für die Antwort.

Nun bekomm ich aber beim Versuch den Integerwert auszulesen eine Exception. :(

Woran kann das liegen?

Gruß
Thomas

_________________
(Sorry! Leider ewiger Delphi-Neuling)
schitho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: So 06.03.05 21:37 
Hab die Fehler selbst gefunden. :D

Die Zuweisung eines Integerwertes geht doch mit Pointer:

ausblenden Delphi-Quelltext
1:
ListItem.Data:=Pointer(i)					


Auslesen geht dann wieder so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
var
  x : integer;
begin
  x:=Integer(ListView.Selected.Data);


Gruß
Thomas

_________________
(Sorry! Leider ewiger Delphi-Neuling)