Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#4

Re: Verständnisproblem Stringlist mit Object

  Alt 9. Sep 2004, 10:01
Hallo TomDooley,
ich nicht was Du mit TStringList erreichen möchtest. Meiner Ansicht nach brauchst Du
TStringList nicht. Ich habe mal ein bißchen Source zusammengestellt.
Delphi-Quellcode:
unit Unit1;

interface

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

type

  PString = ^String; // Deklaration eines Zeiger auf einen String wg der Übersicht

  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
    procedure ClearStrings;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  iCnt : Integer;
  aStr : PString;
begin
  ClearStrings;
  ListBox1.Clear;
  For iCnt:=0 to 9 do
    begin
    New(aStr);
    aStr^:='TestString '+IntToStr(iCnt+1);
    ListBox1.Items.AddObject('TestString '+IntToStr(iCnt+1),TObject(aStr));
    end; // For iCnt:=0 to 9 do
end;

procedure TForm1.ClearStrings;
var
  iCnt : Integer;
begin
  For iCnt:=0 to ListBox1.Items.Count-1 do
    If Assigned(ListBox1.Items.Objects[iCnt]) then
      Dispose(PString(ListBox1.Items.Objects[iCnt]));
end;

procedure TForm1.ListBox1Click(Sender: TObject);
begin
  Label1.Caption:=PString(ListBox1.Items.Objects[ListBox1.ItemIndex])^ ;
end;


procedure TForm1.FormDestroy(Sender: TObject);
begin
  ClearStrings;
end;

end.
Damit das klappt was Du vorhast brauchst Du schon einen Zeiger.
Ich vermute mal Du möchtest neben dem String in der ComboBox in der Objects Eigenschaft einen Wert speichern. Das ist auch kein Problem.
I come from outer space to save the human race
  Mit Zitat antworten Zitat