pascal - Write string variable to the clipboard -
i'm going admit, right off bat, i'm pascal-inexperienced, least. so, can appreciated. :)
as part of larger program, need write string variable clipboard. i've created new project in lazarus (version 1.0.12) can try figure out how without complications caused extra, unnecessary code, have included below:
program vartoclipboard; uses clipbrd; var texttocopy:string; begin texttocopy := 'test text pascal'; clipboard.astext := texttocopy; end.
using above code, along required lclbase
dependency, i'm getting following error in cmd when running compiled exe:
an unhandled exception occurred @ $000000000043d45e : eaccessviolation : access violation $000000000043d45e clipboardregisterformat, line 98 of ./include/lclintf.inc $000000000043c35b predefinedclipboardformat, line 185 of lclintf.pas $0000000000415b0c tclipboard__setastext, line 452 of ./include/clipbrd.inc $0000000000401802 main, line 12 of vartoclipboard.lpr
according the documentation, seem doing right. although, have found documentation be... lacking on more on occasion.
also, have can run compiled exe (which generate , write string clipboard) without console window popping up?
you doing right. problem here clipboard class doesn't somehow encount used in console applications. application failed on following line lclintf.inc
file, widgetset
object going accessed. fails because widgetset
variable nil
while you're in console application because console application doesn't need widgets:
function clipboardregisterformat(const amimetype: string): tclipboardformat; begin result := widgetset.clipboardregisterformat(amimetype); end;
to workaround may add interfaces
unit uses clause , add lcl
package dependency project:
program project1; uses clipbrd, interfaces; begin clipboard.astext := 'hello, i''m text clipboard!'; end.
but according additional question seems want make application, copy text clipboard , terminates. that's console application type not right choice because of console window shown short time. sort of application make formless window application (please note know trick windows platform):
- create new application through menu
file / new...
, selectproject / application
in dialog's tree view , create new project clickingok
- now let's remove unit (with form) project; go menu
project / remove project
, in newly opened dialog selectunit1.pas
, clickok
- now have unitless (and formless) application, remains write code copy text clipboard; let's open project source menu
project / view project source
, project source paste code (this shortest possible form):
program project1; uses interfaces, forms, clipbrd; begin application.initialize; clipboard.astext := 'hello, i''m text clipboard!'; end.
Comments
Post a Comment