Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Pegar desde Clipboard a InputBox (https://www.clubdelphi.com/foros/showthread.php?t=82594)

Cristhor1982 21-03-2013 20:14:30

Pegar desde Clipboard a InputBox
 
Amigos, tengo una duda, puedo pegar por ejemplo

123,456,789
101,110,121,015
125
235-785
2512 8545

en un imputbox, que quede de esta forma

123,456,789,101,110,121,015,125,235,785,2512,8545

y luego de que quede delimitado por comas al aceptar el inputbox
lo llevo a un stringgrid y los valores en una columna especifica.

Si alguien me ayuda...FANTASTICO!!

Saludos

ecfisa 21-03-2013 21:32:24

Hola Cristhor1982.

Basándome en el ejemplo de tu mensaje:
Cita:

123,456,789
101,110,121,015
125
235-785
2512 8545
Podrías hacer:
Código Delphi [-]
...
uses Clipbrd;

procedure ClipToColRow(SG: TStringGrid; const aCol, aRow:Integer; const Str: string);
var
  SL: TStrings;
  i : Integer;
begin
  SL:= TStringList.Create;
  try
    SL.Delimiter     :=',';
    SL.DelimitedText := Str;
    SG.RowCount:= SL.Count + 1;
    for i := 0 to SL.Count-1 do
       SG.Cells[SG.FixedCols, SG.FixedRows+i] := SL[i];
  finally
    SL.Free
  end
end;

procedure TForm1.btnToSGridClick(Sender: TObject);
var
  Str: string;
  SL: TStrings;
  i : Integer;
begin
  if Clipboard.HasFormat(CF_TEXT) then
  begin
    SL:= TStringList.Create;
    try
      SL.Text:= Clipboard.AsText;
      for i:= 0 to SL.Count-1 do
        if i < SL.Count-1 then SL[i]:= SL[i] + ',';
      Str := SL.Text;
      Str := StringReplace(Str, '-', ',', [rfReplaceAll]);
      Str := StringReplace(Str, ' ', ',', [rfReplaceAll]);
      Str := StringReplace(Str, #10,  '', [rfReplaceAll]);
      Str := StringReplace(Str, #13,  '', [rfReplaceAll]);
      Clipboard.AsText:= Str;
    finally
      SL.Free
    end
  end;
  Str := InputBox('Dato', ':', Str); // esto podría ser innecesario...
  ClipToColRow(StringGrid1, 1, 1, Str);
end;
...
Podrías enviar directamente la variable Str como parámetro de la función ClipToColRow sin pasar por el InputBox.

Saludos.:)

Cristhor1982 21-03-2013 21:50:10

Wow!!, excelente justo en el clavo, ahora tengo k modificar un par de cosas y toy, Muchas Gracias!!!

Te Pasaste ...Necesito un profe como tu 100%

Saludos

Cita:

Empezado por ecfisa (Mensaje 457352)
Hola Cristhor1982.

Basándome en el ejemplo de tu mensaje:


Podrías hacer:
Código Delphi [-]
...
uses Clipbrd;

procedure ClipToColRow(SG: TStringGrid; const aCol, aRow:Integer; const Str: string);
var
  SL: TStrings;
  i : Integer;
begin
  SL:= TStringList.Create;
  try
    SL.Delimiter     :=',';
    SL.DelimitedText := Str;
    SG.RowCount:= SL.Count + 1;
    for i := 0 to SL.Count-1 do
       SG.Cells[SG.FixedCols, SG.FixedRows+i] := SL[i];
  finally
    SL.Free
  end
end;

procedure TForm1.btnToSGridClick(Sender: TObject);
var
  Str: string;
  SL: TStrings;
  i : Integer;
begin
  if Clipboard.HasFormat(CF_TEXT) then
  begin
    SL:= TStringList.Create;
    try
      SL.Text:= Clipboard.AsText;
      for i:= 0 to SL.Count-1 do
        if i < SL.Count-1 then SL[i]:= SL[i] + ',';
      Str := SL.Text;
      Str := StringReplace(Str, '-', ',', [rfReplaceAll]);
      Str := StringReplace(Str, ' ', ',', [rfReplaceAll]);
      Str := StringReplace(Str, #10,  '', [rfReplaceAll]);
      Str := StringReplace(Str, #13,  '', [rfReplaceAll]);
      Clipboard.AsText:= Str;
    finally
      SL.Free
    end
  end;
  Str := InputBox('Dato', ':', Str); // esto podría ser innecesario...
  ClipToColRow(StringGrid1, 1, 1, Str);
end;
...
Podrías enviar directamente la variable Str como parámetro de la función ClipToColRow sin pasar por el InputBox.

Saludos.:)



La franja horaria es GMT +2. Ahora son las 05:32:41.

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