Wednesday, September 2, 2020
Paste) - Delphi Code
Clipboard Basics (Cut/Copy/Paste) - Delphi Code The Windows Clipboard speaks to the holder for any content or designs that are cut, duplicated or stuck from or to an application. This article will tell you the best way to utilize the TClipboard item to actualize cut-duplicate glue highlights in your Delphi application. Clipboard in General As you most likely know, the Clipboard can hold just one bit of a similar sort of information for cut, reorder at once. In the event that we send new data in a similar arrangement to the Clipboard, we clear out what was there previously, yet the substance of the Clipboard remains with the Clipboard considerably after we glue those substance into another program. TClipboard So as to utilize the Windows Clipboard in our applications, we should add the ClipBrd unit to the utilizations proviso of the venture, with the exception of when we limit cutting, reordering to the parts previously having worked in help for Clipboard techniques. Those parts are TEdit, TMemo, TOLEContainer, TDDEServerItem, TDBEdit, TDBImage and TDBMemo. The ClipBrd unit consequently speaks to a TClipboard object called Clipboard. Well utilize the CutToClipboard, CopyToClipboard, PasteFromClipboard, Clear and HasFormat strategies to manage Clipboard activities and text/realistic control. Send and Retrieve Text So as to send some content to the Clipboard the AsText property of the Clipboard object is utilized. On the off chance that we need, for instance, to send the string data contained in the variable SomeStringData to the Clipboard (clearing out whatever text was there), well utilize the accompanying code: utilizes ClipBrd; ... Clipboard.AsText : SomeStringData_Variable; To recover the content data from the Clipboard well use utilizes ClipBrd; ... SomeStringData_Variable : Clipboard.AsText; Note: in the event that we just need to duplicate the content from, lets state, Edit part to the Clipboard, we don't need to incorporate the ClipBrd unit to the utilizations provision. The CopyToClipboard strategy for TEdit duplicates the chose text in the alter control to the Clipboard in the CF_TEXT design. methodology TForm1.Button2Click(Sender: TObject) ; start à â /the accompanying line will choose à â /ALL the content in the alter control à â {Edit1.SelectAll;} à â Edit1.CopyToClipboard; end; Clipboard Images To recover graphical pictures from the Clipboard, Delphi must realize what sort of picture is put away there. Thus, to move pictures to the clipboard, the application must mention to the Clipboard what sort of designs it is sending. A portion of the potential estimations of the Format boundary follow; there are a lot more Clipboard designs gave by Windows. CF_TEXT - Text with each line finishing with a CR-LF combination.CF_BITMAP - A Windows bitmap graphic.CF_METAFILEPICT - A Windows metafile graphic.CF_PICTURE - An object of type TPicture.CF_OBJECT - Any relentless item. The HasFormat technique returns True if the picture in the Clipboard has the correct arrangement: on the off chance that Clipboard.HasFormat(CF_METAFILEPICT) at that point ShowMessage(Clipboard has metafile) ; Utilize the Assign technique to send (allocate) a picture to the Clipboard. For instance, the accompanying code duplicates the bitmap from a bitmap object named MyBitmap to the Clipboard: Clipboard.Assign(MyBitmap) ; All in all, MyBitmap is an object of type TGraphics, TBitmap, TMetafile or TPicture. To recover a picture from the Clipboard we need to: confirm the arrangement of the current substance of the clipboard and utilize the Assign technique for the objective article: {place one catch and one picture control on form1} {Prior to executing this code press Alt-PrintScreen key combination} utilizes clipbrd; ... method TForm1.Button1Click(Sender: TObject) ; start in the event that Clipboard.HasFormat(CF_BITMAP) at that point Image1.Picture.Bitmap.Assign(Clipboard) ; end; More Clipboard Control Clipboard stores data in various arrangements so we can move information between applications utilizing various configurations. When perusing data from the clipboard with Delphis TClipboard class, we are restricted to standard clipboard designs: text, pictures, and metafiles. Assume youre working between two diverse Delphi applications; how might you characterize custom clipboard group so as to send and get information between those two projects? With the end goal of investigation, lets state you are attempting to code a Paste menu thing. You need it to be impaired when there is no content in the clipboard (as a case). Since the whole procedure with the clipboard happens in the background, there is no technique for TClipboard class that will illuminate you when some adjustment in the substance of the clipboard has occurred. The thought is to snare in the clipboard notice framework, so youre ready to access and react to occasions when the clipboard changes. To appreciate greater adaptability and usefulness, managing clipboard change warnings and custom clipboard positions tuning in to the Clipboard is important.
Subscribe to:
Posts (Atom)