Board index » delphi » Copying data from Clipboard into a Blob Field

Copying data from Clipboard into a Blob Field

I want to copy clipboard data directly into a blob field. Also I want
to be able to then save this data out into a file such as a text or
bmp file etc depending on what data is stored.

Can anyone help with any examples.

Thankyou.

 

Re:Copying data from Clipboard into a Blob Field


(*In this example, you'll need a DBMemo, a Button and a SaveDialog*)
(*To copy text from a clipboard into a tDBMemo,
which basically saves it to a blob field. I believe that the ClipBoard
has to be accomodated in the Uses list, but I don't know the name of the
unit*)

procedure TForm1.Button1Click(Sender: TObject);
begin
  DbMemo1.PasteFromClipboard;
end;

(*To save text from the tDBMemo*)
procedure TForm1.bbSaveFileClick(Sender: TObject);
var zF1: textfile; zI: integer; zDM: tdbmemo;
begin
  assignfile(zF1, savedialog1.filename); (*full path and filename*)
  try
    rewrite(zF1);
    for zI:=0 to zDM.Lines.count-1 do
      writeln(zF1, zDM.lines[zI]);
  finally
    closefile(zF1);
  end;
end;

Re:Copying data from Clipboard into a Blob Field


Sorry, I didn't see that you requested that the procedure be independent of
the type of data in the clipboard. I might have something on that, but I
don't have the time for it right now.

John Bleau

Re:Copying data from Clipboard into a Blob Field


Here, you can combine the following with my earlier post. Note that the
Clipboard.HasFormat(CF_TEXT) would indicate that its contents are in text
format. The help function will give the rest. Note also that
Image1.Picture.SaveToFile is an available method.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

uses
  ClipBrd;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
 var
  MyHandle: THandle;
  BMPPtr: PChar;
  MyString: string;

begin
  if Clipboard.HasFormat(CF_BITMAP) then
  try
    ClipBoard.Open;
    MyHandle := Clipboard.GetAsHandle(CF_BITMAP);
    Image1.picture.LoadFromClipboardFormat(CF_BITMAP, MyHandle,
Image1.Picture.Bitmap.palette);
  finally
    Clipboard.Close;
  end;
end;

Re:Copying data from Clipboard into a Blob Field


Paul, if I may quote your email to me, since it's germane to this thread:

Hello,
You recently posted the following code to one of my newsgroup postings about
saving clipboard data to a BLOB Field. Your code is loading clipboard into
the picture property of a TImage. I want to load data into a BLOB field.

Answer: Use DBImage from Data Controls.

Cheers,

John Bleau

Other Threads