Autor Beitrag
Taladan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 88


Delphi 2005 Personal
BeitragVerfasst: Fr 25.07.03 14:51 
Kann man Items von einer ListBox einen nicht-sichtbaren wert (auser den index) geben. Was ich hier Sichtbar in dem String habe?

ausblenden Delphi-Quelltext
1:
2:
name := table1Name.value + ', ' + table1Vorname.value + inttostr(table1Zhler.value);
listbox1.items.add(name);


Moderiert von user profile iconKlabautermann: Delphi-Tags hinzugefügt.
specialwork
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

Windows XP Professional; Windows Server 2003
Delphi 7 Prof, Delphi 8.Net
BeitragVerfasst: Fr 25.07.03 21:14 
Titel: Einer TListBox (TStrings) Objekte zuweisen
Hallo Taladan,

Die folgende Unit fügt Objekte zu einer TListBox hinzu.

Allerdings ist dies nicht eine Funktionalität von TListBox sondern von TStrings. TStrings bietet die Möglichkeit zu jeder Zeile ein Objekt zu hinterlegen.

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:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
unit Unit3;

interface

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

type
  THiddenListBoxValues = class(TObject)
  public
    Age: Integer;
    Country: String;
    ZIP: String;
    ID: Integer;
  end;


type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  HiddenData: THiddenListBoxValues;
  X: Integer;
begin
  for X:=0 to 10 do begin
    HiddenData:=THiddenListBoxValues.Create;
    HiddenData.Age:=31;
    HiddenData.Country:='Emmelshausen';
    HiddenData.ZIP:='56281';
    HiddenData.ID:=X;

    Listbox1.Items.InsertObject(x, 'Specialwork', HiddenData);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  HiddenData: THiddenListBoxValues;
  X: Integer;
begin
  Memo1.Lines.BeginUpdate;
  Memo1.Lines.Clear;

  for X:=0 to ListBox1.Items.Count-1 do begin
    HiddenData:=(ListBox1.Items.Objects[x] as THiddenListBoxValues);
    Memo1.Lines.Add(ListBox1.Items.Strings[X]);
    Memo1.Lines.Add(HiddenData.Country);
    Memo1.Lines.Add(HiddenData.ZIP);
    Memo1.Lines.Add(inttostr(HiddenData.Age));
    Memo1.Lines.Add(inttostr(HiddenData.ID));
  end;

  Memo1.Lines.EndUpdate;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
  X: Integer;
begin
  for X:=0 to ListBox1.Items.Count-1 do begin
    ListBox1.Items.Objects[x].Free;
  end;
end;

end.

Gruß, Tom
Taladan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 88


Delphi 2005 Personal
BeitragVerfasst: Sa 26.07.03 11:28 
Dankäää das hat geklappt.