force1758,
Cita:
|
Empezado por force1758
...me ayudan a pasarla a función...
|
Revisa esta 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;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
private
public
end;
TArrayStr = Array of String;
var
Form1: TForm1;
FileVector : TArrayStr;
implementation
{$R *.dfm}
function ReadTextFile(FileName : String) : TArrayStr;
var
F : TextFile;
i : Integer;
Buffer : String;
begin
try
FileMode := fmOpenRead;
AssignFile(F, FileName);
Reset(F);
i := 1;
while not Eof(F) do
begin
Readln(F, Buffer);
SetLength(Result,i);
Result[i-1] := Buffer;
Inc(i);
end;
CloseFile(F);
except
MessageDlg('Error de I/O', mtInformation, [mbOK], 0);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
FileVector := ReadTextFile('C:\TestFile.txt');
for i := Low(FileVector) to High(FileVector) do
begin
TLabel(FindComponent(Format('Label%d',[i+1]))).Caption := FileVector[i];
end;
end;
end.
El código anterior
lee por medio de una función un archivo de texto línea x línea y carga su contenido en un arreglo el cual es retornado como resultado de la función y utilizado posteriormente para modificar la propiedad Caption de los Componentes TLabel de un Form.
Te sugiero consultar este link, te sera útil como información general de Delphi:
Espero sea útil
Nelson.