![]() |
![]() |
![]() |
![]() |
![]() |
FTP | ![]() |
![]() |
CCD | ![]() |
![]() |
Buscar | ![]() |
![]() |
Trucos | ![]() |
![]() |
Trabajo | ![]() |
![]() |
Foros | ![]() |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
TObjectList y TStringList
Buenas. Con vuestra ayuda he echo el siguiente codigo utilizando TObjectList y TStringLIst. Despues de mirar la ayuda me di cuenta q la variable soc en vez de de TObjectList hubiera sido mejo del tipo TStringLIst y con el metodo ADD.Object q aparte de asignarle un objeto tambien permite un string y ese strings yo lo utilizare para un control posterior.
Como podria cambiar soc de TobjectList a TStringList y a cada objeto q le inserte ponerle un string := 0 con el metodo ADD.OBJECT. var Form1: TForm1; soc: TObjectList; implementation {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject); begin soc:= TObjectList.Create; soc.OwnsObjects:= true; end; //----------------------------------------------------------------------- procedure TForm1.Button1Click(Sender: TObject); var indice: integer; i: integer; temp: TStringLIst; begin I:= 0; indice:= soc.Add(TStringLIst.create()); temp:= soc.items[indice] as TStringList; while i <> 5 do begin temp.Add(inttostr(i)); i:= i + 1; end; //soc.Free(); end; //------------------------------------------------------------------------ procedure TForm1.Button5Click(Sender: TObject); var indice: integer; i: integer; temp: TStringLIst; begin I:= 0; indice:= soc.Add(TStringLIst.create()); temp:= soc.items[indice] as TStringList; while i <> 5 do begin temp.Add(inttostr(i + 10)); i:= i + 1; end; //soc.Free(); end; //------------------------------------------------------------------------ procedure TForm1.Button2Click(Sender: TObject); begin form1.Label1.Caption:= inttostr(soc.count); end; //------------------------------------------------------------------------ procedure TForm1.Button3Click(Sender: TObject); var s: integer; begin for s:= 0 to TStringList(soc[0]).Count - 1 do form1.ListBox1.Items.Add(TstringList(soc[0]).strings[s]); end; //------------------------------------------------------------------------ procedure TForm1.Button4Click(Sender: TObject); var s: integer; begin for s:= 0 to TStringList(soc[1]).Count - 1 do form1.ListBox1.Items.Add(TstringList(soc[1]).strings[s]); end; //------------------------------------------------------------------------ end. |
|
|
![]() |
|