Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Capturar Texto desde un notepad (https://www.clubdelphi.com/foros/showthread.php?t=74542)

kirios 24-06-2011 19:00:15

Capturar Texto desde un notepad
 
Hola, estoy queriendo capturar una lista de palabras desde un bloc de notas en windows, y asignarlos a un array de strings, alguien sabe algun método? o algun link con info, graciaas.

ecfisa 24-06-2011 19:25:45

Hola.

Como ejemplo una forma seria:
Código Delphi [-]
...
uses ClipBrd;

procedure TForm1.Button1Click(Sender: TObject);
var
  CB: TClipBoard;
  VStr : array of string;
  i : Integer;
  TS: TStrings;
begin
  try
   TS:= TStringList.Create;
   try
    CB:= TClipBoard.Create;
    TS.Text:= CB.AsText;
    for i:= 0 to TS.Count-1 do
    begin
      SetLength(VStr,i+1);
      VStr[i]:= TS[i];
    end;
   finally
    TS.Free;
   end;
  finally
   CB.Free;
  end;
end;

Saludos.

kirios 24-06-2011 19:46:23

ja, me mataste, no la tengo tan clara con los comandos, tenes algun archivo de ayuda? me comentaron que con el opendialog y un scanf podria funcionar, puede ser?
graciaas

ecfisa 24-06-2011 20:06:48

Hola.

Te pido mil disculpas, no sé donde tenía la cabeza que interpreté 'clipboard' cuando en realidad era 'notepad' :o

Sería:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  TS: TStrings;
  VStr: array of string;
  i: Integer;
begin
  OpenDialog1.Filter:= 'Archivos de texto|*.txt';
  if OpenDialog1.Execute then
  begin
    TS:= TStringList.Create;
    try
      TS.LoadFromFile(OpenDialog1.FileName);
      for i:= 0 to TS.Count -1 do
      begin
        SetLength(VStr,i+1);
        VStr[i]:= TS[i];
      end;
    finally
      TS.Free;
    end;
  end;
end;
El código sería mucho más sencillo si no te pidieran guardarlo en un array de string.

Saludos.


La franja horaria es GMT +2. Ahora son las 20:41:13.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi