Ir al contenido


Foto

Creando Componentes en tiempo de Ejecución desde un Archivo de Texto


  • Por favor identifícate para responder
2 respuestas en este tema

#1 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 17 junio 2010 - 01:36

Pues eso, tengo dos problemas, estoy creando componentes en tiempo de ejecución a través de una lista contenido en un archivo de texto, el archivo contiene lo siguiente:



delphi
  1. 143.1.21.111/D1,P01,01,M1
  2. 143.1.21.112/D2,P02,02,M1
  3. 143.1.21.110/D3,P03,03,M1
  4. 143.1.21.113/D4,P04,04,M2
  5. 143.1.21.114/D5,P05,05,M2
  6. 143.1.21.115/D6,P06,06,M2
  7. 143.1.21.116/D7,P07,07,CRC
  8. 143.1.21.117/D8,P08,08,DGET
  9. 143.1.21.118/D9,P09,09,DGET
  10. 143.1.21.119/D10,P10,10,COMEDOR1
  11. 143.1.21.120/D11,P11,11,COMEDOR2
  12. 143.1.21.121/D12,P12,12,M1
  13. 143.1.21.122/D13,P13,13,DGTT1
  14. 143.1.21.123/D14,P14,14,DGTT2
  15. 143.1.21.124/D15,P15,15,DGMCCV
  16. 143.1.21.125/D16,P16,16,PEAJE



El code es:



delphi
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var Txt: String;
  3.     ListaIP: TStringList;
  4.     i: Integer;
  5. begin
  6. Txt := ExtractFilePath(Application.ExeName) +'IP.txt';
  7.  
  8. ListaIP := TStringList.Create;
  9.  
  10. ListaIP.LoadFromFile(Txt);
  11.  
  12. for i := 0 to ListaIP.Count -1 do begin
  13.   with TButton.Create(self) do
  14.     begin
  15.       Name := 'Reloj'+ IntToStr(i);
  16.       Caption := Copy(ListaIP.Strings[i],0,12);
  17.       Parent := pnBase;
  18.       Left := 0 + Left;
  19.     end;
  20. end;
  21. end;



Los problemas que se me presentan son los siguientes:

1. El caption del button no me aparece nada.
2. No sé como colocar los componentes uno al lado del otro y al llegar al final continúe hacia abajo.

Espero se entienda.

Saludos.
  • 0

#2 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 17 junio 2010 - 02:05

Mira a ver si esto te sirve:



delphi
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var Txt: String;
  3.     ListaIP: TStringList;
  4.     i: Integer;
  5. begin
  6. Txt := ExtractFilePath(Application.ExeName) +'IP.txt';
  7.  
  8. ListaIP := TStringList.Create;
  9.  
  10. ListaIP.LoadFromFile(Txt);
  11.  
  12. for i := 0 to ListaIP.Count -1 do begin
  13.   with TButton.Create(self) do
  14.     begin
  15.       Name := 'Reloj'+ IntToStr(i);
  16.       Caption := Copy(ListaIP.Strings[i],0,12);
  17.       Parent := self;
  18.       Width:= 80;
  19.       Height:= 25;
  20.       Left:= (i mod (Form1.Width div Width))*Width;
  21.       Top:= (i div (Form1.Width div Width))*Height;
  22.     end;
  23. end;
  24. end;



Saludos.
  • 0

#3 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 18 junio 2010 - 08:59

Excelente Bro, me ha funcionado bien (y), en un rato les comento como me va :D

Saludos.
  • 0




IP.Board spam blocked by CleanTalk.