Ver Mensaje Individual
  #2  
Antiguo 16-07-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
santiago14,

Cita:
...tengo un StringList y quiero ponerle un valor y un objeto...pero a la hora de visualizarlo..devuelve basura...¿Qué estoy haciendo mal?...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
const
   A1 : Array[0..3] of String = ('Item-1', 'Item-2', 'Item-3', 'Item-4');
   A2 : Array[0..3] of String = ('Object-1', 'Object-2', 'Object-3', 'Object-4');

var
   SL : TStringList;
   i : Integer;
   S1, S2 : String;

begin

   SL := TStringList.Create;

   for i := 0 to 3 do
      SL.AddObject(A1[i],TObject(A2[i]));

   for i := 0 to 3 do
   begin
      S1 := SL.Strings[i];
      S2 := String(SL.Objects[i]);
      ShowMessage(S1 + ',' + S2);
   end;

   SL.Free;

end;

end.
El código anterior en Delphi 7 bajo Windows 7 Professional x32, ejemplifica el uso del método AddObject en una variable TStringList.

Revisa esta información:
Espero sea útil

Nelson

Última edición por nlsgarcia fecha: 16-07-2014 a las 21:09:01.
Responder Con Cita