Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   FireMonkey (https://www.clubdelphi.com/foros/forumdisplay.php?f=50)
-   -   Copiar y pegar en FireMonkey (https://www.clubdelphi.com/foros/showthread.php?t=94065)

TiammatMX 16-07-2019 00:33:51

Copiar y pegar en FireMonkey
 
En mi primer aplicación usando FireMonkey, me llevo la sorpresa que no existe (o no he encontrado) una implementación copiar / pegar entre el clipboard (ya sea de Android, iOS o Windows) que me permita tomar texto (copiar) o agregar texto (pegar) a un TMemo para FireMonkey.

En VCL, esos procesos los tengo más que dominados, pero como ésto es nuevo para mí, pues aún no localizo el proceso o función o funcionalidad que me permita hacerlo. Supongo que es algo super sencillo, pero me declaro incompetente para hacerlo...

Código Delphi [-]
procedure TfrmPrincipal.btnPegarClick(Sender: TObject);
begin
//
end;

procedure TfrmPrincipal.btnCopiarClick(Sender: TObject);
begin
//
end;

La idea es que usando éstos botones, de la memoria intermedia (clipboard) pase al contenido del TMemo como texto.

Por su atención, gracias.

TiammatMX 16-07-2019 15:16:57

Me encantan los diálogos de sordos, es decir, ya encontré la respuesta...

Código Delphi [-]
procedure TCopyPasteDemo.CopyButtonClick(Sender: TObject);
var
  Svc: IFMXClipboardService;
  Image: TBitmap;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, Svc) then
    if TextRadioButton.IsChecked then
      Svc.SetClipboard(Edit1.Text)
    else
    begin
      Image := TextBorder.MakeScreenshot;
      try
        Svc.SetClipboard(Image);
      finally
        Image.Free;
      end;
    end;
end;

procedure TCopyPasteDemo.PasteButtonClick(Sender: TObject);
var
  Svc: IFMXClipboardService;
  Value: TValue;
  Bitmap: TBitmap;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, Svc) then
  begin
    Value := Svc.GetClipboard;
    if not Value.IsEmpty then
    begin
      if Value.IsType<string> then
      begin
        PasteLabel.Text := Value.ToString;
        PasteImage.Bitmap := nil;
      end
      else if Value.IsType then
      try
        PasteLabel.Text := string.Empty;
        Bitmap := TBitmap.Create;
        try
          Bitmap.Assign(Value.AsType);
          PasteImage.Bitmap := Bitmap;
        finally
          Bitmap.Free;
        end;
      finally
        Value.AsType.Free;
      end;
    end;
  end;
end;

Ahora, a experimentar que sirva... :):):):)

Casimiro Notevi 16-07-2019 18:31:37

^\||/^\||/^\||/

dec 17-07-2019 08:55:33

Hola a todos,

¡Gracias por compartir la solución TiammatMX! :)

Teto10 02-09-2019 18:37:02

Hola muy buen codigo, gracias por compartirlo


La franja horaria es GMT +2. Ahora son las 07:50:45.

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