Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

clipboard

How to copy an image and text to the clipboard at the same time?
0
Cheng_sam
Asked:
Cheng_sam
  • 5
  • 3
  • 2
  • +1
1 Solution
 
saravananvgCommented:
Hello Sir,

  You could check the following site if it is of any use to you

http://delphi.about.com/od/database/l/aa092199.htm

with regards,
padmaja.
0
 
Slick812Commented:
hello Cheng_sam, the windows system has it's "Standard" clipboard formats, there is one for "Text" and there is one for "Bitmaps", but if you want to combine to separate Data types (like text and a bitmap) into a single memory block and save it to clipboard, you will need to "Invent" your own clipboard format and register it with the system , , so it can know and handle your clipboard format. Is this what you mean ?
0
 
bernaniCommented:
Here is a way to do it if it can help

uses
  Clipbrd;

{$R *.DFM}

procedure TForm1.btnCopyClick(Sender: TObject);
begin
  Clipboard.Open;
  try
    Clipboard.AsText := Edit1.Text;
    Clipboard.Assign(Image1.Picture)
    { or Clipboard.Assign(Image1.Picture.Bitmap) }
  finally
    Clipboard.Close
  end
end;

procedure TForm1.btnPasteClick(Sender: TObject);
begin
  Clipboard.Open;
  try
    Edit2.Text := Clipboard.AsText;
    Image2.Picture.Assign(Clipboard)
    { or Image2.Picture.Bitmap.Assign(Clipboard) }
  finally
    Clipboard.Close
  end
end;

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Cheng_samAuthor Commented:
thank bernani & Slick812 'comment. I have tried bernani's example.it work well.It can paste text and bmp same time  on my application.But it can only paste text or picture to MS Word . Maybe it need a  extra transform like Slick812's comment.  
 

0
 
Slick812Commented:
???. . . You have NOT given nessary information ! !,  You question asked -
 How to copy an image and text to the clipboard at the same time?

but you did not say anything about what or where you wanted to "Paste" this information, now you have given a "New" requirement -
     "  paste text or picture to MS Word  ", , , ? ? ?
as far as I know of, ,  almost every application that does a "Paste" operation, will use just ONE data type for it's paste, like use ONE, text or Bitmap, ,  , Other wize, it may NOT know what to do with the Two types of data, ,  I have not ever heard of a word processing program (Word, WordPad) pasting more than one data type in a single "Paste" operation, , you might go to the EE MS Word Page at -
http://www.experts-exchange.com/Applications/MS_Office/Word/
and ask if that is even posible?
But my comment about another clipboard format would not be something I know about for MS Word, there may be such a format for Word, but I do not know it.
0
 
Slick812Commented:
Sorry, I was thinking of something else   :-(
You can do a muti data copy and paste in Word, but I have no idea how to format that, sorry, I need some sleep
0
 
bernaniCommented:
Hi,

If you want to paste AND the text AND the picture in MS Word, here is the VBA Code which insert at the same time the text and the picture in Word:

' CallPasteSpecialDlg Macro
' Macro enregistrée le 21/03/2006 par Bernard
'
    //paste the text from the clipboard
    Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
   // new paragraph - blank line
    Selection.TypeParagraph
   //paste picture from the clipboard
    Selection.PasteSpecial Link:=False, DataType:= wdPasteDeviceIndependentBitmap, Placement:=wdFloatOverText, DisplayAsIcon :=False
End Sub

I believe you will have no problem to use it in Delphi (don't forget to check, before calling this, that the clipboard contains well the required data formats).

Hope this help,
0
 
bernaniCommented:
To complete my previous, here is the Delphi code to do the job (Test and functionnal):

//Click on the button presume you have copy the data to the clipboard as mentionned above
//procedure TForm1.btnCopyClick(Sender: TObject);
//begin
//  Clipboard.Open;
//  try
//    Clipboard.AsText := Edit1.Text;
//    Clipboard.Assign(Image1.Picture)
//    { or Clipboard.Assign(Image1.Picture.Bitmap) }
//  finally
//    Clipboard.Close
//  end
//end;

//in the uses clause

uses ComObj {for CreateOleObject}, clipbrd;

procedure TForm1.btnPasteTextAndPicToWordClick(Sender: TObject);
var
  Word: OLEVariant;
  Doc, SelSpec: variant;
begin
  try
  Word := CreateOleObject('Word.Application');
  except
  ShowMessage('Cannot start Word !');
  Exit;
  end;

Word.Visible := True;
Doc:=Word.Documents.Add;
SelSpec:= Word.Selection;
SelSpec.pastespecial(Link:=false,datatype:=2,Placement:=0,DisplayAsIcon:=false);
SelSpec.TypeParagraph;
SelSpec.pastespecial(Link:=false,datatype:=5,Placement:=1,DisplayAsIcon:=false);
end;

Hope it's what you were looking for.


0
 
Cheng_samAuthor Commented:
Thanks for Slick812 & bernani  .Sorry to make a misconception due to my indefinite question .
 In  MS Word ,there are a couple of data type (text,rtf, HTTP,picture..) shown at same time and we can select one of them  and  paste it.That is what I want.  
   I have tried bernani 's  example .It works. Thanks.

0
 
bernaniCommented:
Cheng_sam,

May I ask you to close this question as it seems complete for you. Thanks.
0
 
bernaniCommented:
Thanks for finalizing this question.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now