I understand that you can't write multiple custom formats to the clipboard using clipboard.writeBuffer(),
But when I try to use it write a special format (not text, html, image or rtf), nothing is written to the clipboard:
const buffer = Buffer.from('slide format data');
clipboard.writeBuffer("application/special-format", buffer);
and consequently, nothing is being pasted when
webcontent.paste() is called.
That being said, I am able to read the buffer from the clipboard using clipboard.readBuffer(),
but clipboard.availbaleFormtas() returns an empty array.
Are some formats not supported at all?
Related
I am opening up .txt files but when they are loaded on Xojo weird characters like these (’ , â€ک) show up.
I've tried DefineEncoding and ConvertEncoding but it still doesn't seem to work.
output.text = output.text.DefineEncoding(Encodings.WindowsANSI)
output.text = output.text.ConvertEncoding(Encodings.UTF8)
You may have to define the encoding already at time of loading, not afterwards, or you'll get UTF8 chara from loading that you will then mess up with your posted code. So, pass the encoding to the Read function or load the data as a binary file, not as a text file.
This fragment does not write to file a stream of 90 characters after the buffer is full
"full" means that an output operation is executed when the buffer is full, or when we explicitly flush the file. By writing out:write(string.rep("A",90)) and opening the file with notepad I can see the text.
This fragment does not write to the file
out = io.open("E:\\file","w")
out:setvbuf("full",90)
out:write(string.rep("A",89))
out:write("A")
On the other hand this fragment does write to the file
out = io.open("E:\\file","w")
out:setvbuf("full",90)
out:write(string.rep("A",90))
This might seem a simple question, but what actually surprises me is that rather that writing the text to the file, the first fragment does not write anything due to such a trivial change. Why does this happen? By the way, I am using Lua 5.3.4.
Embarcadero RAD Studio VCL has the TClipboard.HasFormat Method, with a usage e.g. Clipboard.HasFormat(CF_TEXT) or Clipboard.HasFormat(CF_BITMAP) etc..
But I did not find any supported CF_RTF or CF_RICHTEXT format-descriptor which indicates a rich-text format in the clipboard.
So I created some formatted text in Microsoft WordPad and copied it to the clipboard. Then I used a clipboard-spy program to inspect the formats on the clipboard:
This lists 3 RichText formats with the format-descriptors C078, C16B and C1A5.
Are these format-descriptors universal or dependent from the individual system or from the current situation? I.e., can I generally use Clipboard.HasFormat($C078) to detect any RichText format on the clipboard? Or is there another method?
Can I generally use Clipboard.HasFormat($C078) to detect any
RichText format on the clipboard?
No, You need to register the RTF clipboard format via RegisterClipboardFormat function. The returned value is generated by the system and may vary.
Registers a new clipboard format. This format can then be used as a
valid clipboard format.
If a registered format with the specified name already exists, a new
format is not registered and the return value identifies the existing
format. This enables more than one application to copy and paste data
using the same registered clipboard format.
var
CF_RTF: UINT;
...
initialization
CF_RTF := RegisterClipboardFormat('Rich Text Format');
Then check for:
if Clipboard.HasFormat(CF_RTF) then ...
{ or // if Windows.IsClipboardFormatAvailable(CF_RTF) then ... }
Edit: After reading the documentation: How to Use Rich Edit Clipboard Operations
The constant CF_RTF is already declared in RichEdit unit as:
CF_RTF = 'Rich Text Format';
CF_RTFNOOBJS = 'Rich Text Format Without Objects';
CF_RETEXTOBJ = 'RichEdit Text and Objects';
So it might be a better idea to use other naming for the returned value of RegisterClipboardFormat. e.g.
uses RichEdit;
...
var
CF_RICHTEXT: UINT;
...
initialization
CF_RICHTEXT := RegisterClipboardFormat(RichEdit.CF_RTF);
And:
if Clipboard.HasFormat(CF_RICHTEXT) then ...
Note: There are already a few reserved system clipboard formats such as CF_TEXT (=1), CF_BITMAP(=2) etc ... but the "CF_RTF" or "CF_RICHTEXT" is not one of them. it is a custom format used by the RICHEDIT common control, and registered via RegisterClipboardFormat as already mentioned.
I have read multiple posts on the issue, and none seem to come to a decent conclusion to my question. (Perhaps I'm trying to see if anything has popped up lately.)
I have a small charity app that handles pledges. In doing so, it needs to work with and print documents.
Thing is, if Word is open in the background, the app thread will hang and won't respond to the closure of Word, and I have to roll back manually and close word. Sure, that all works fine, but I simply cannot guarantee that the end user will close Word, even if I put the instruction in a user manual.
I'm not too fussed about speed, but I guess that if it can be enhanced, it would be a nice little bonus.
Have any libraries been released for Delphi that will allow me to open, edit, print, and save documents? If not, is there a way to use Word Automation in such a way that it will not conflict with another open handle of Word when opened?
If you use GetActiveOleObject, you will get the running instance of Word.
By using CreateOleObject, you will get a new instance and shouldn't be troubled by other running instances.
In case you use the TWordApplication, wrapper you can set ConnectKind to ckNewInstance to accomplish this. By default, TWordApplication will try to connect with a running instance.
If you want to open edit and print Word documents and you don't mind using RTF format for what you're doing, investigate TRichView.
It will generate rich documents that are in RTF format, which is one of the formats MS word supports. I don't think it directly reads .DOC files but you can convert .DOC and .DOCX into RTF, for most simple files, but certain advanced formatting features would be lost in the conversion.
It has the advantage of working without any need for even any copy of MS Word to be installed on the machine that is going to do the document processing. For production of receipts and other simple documents, this would be the most reliable technique; Don't use Word directly, at all.
procedure PrintViaWord (const filename: string);
const
wdUserTemplatesPath = 2;
var
wrdApp, wrdDoc, wrdSel: variant;
begin
wrdApp:= CreateOleObject ('Word.Application'); // create new instance
sleep (5000); // this fixes a bug in Word 2010 to do with opening templates
wrdDoc:= wrdApp.documents.add (
wrdApp.Options.DefaultFilePath[wdUserTemplatesPath] + '\mytemplate.dot');
wrdDoc.Select;
wrdSel:= wrdApp.selection;
wrdApp.Options.CheckSpellingAsYouType:= 0;
wrdSel.paragraphformat.alignment:= 1;
wrdSel.typetext ('This is a program demonstrating how to open Word in the background'
+ ' and add some text, print it, save it and exit Word');
wrdDoc.SaveAs (filename + '.doc');
wrdApp.ActivePrinter:= 'Konica Minolta 211';
wrdApp.PrintOut;
WrdDoc.SaveAs (filename + '.doc');
wrdApp.quit;
wrdSel:= unassigned;
wrdDoc:= unassigned;
wrdApp:= unassigned
end;
I am trying to download a source code file from a web site which works fine for small files, but a couple of larger ones get truncated.
The example below should be returning a file 146,135 bytes in size, but returns one of 141,194 bytes with a status of 200.
I have tried winhttp.winhttprequest.5.1 as well, but both seem to truncate at the same point.
I have also found quite a few people with similar problems, but have not been able to find a solution.
require('luacom')
http = luacom.CreateObject('MSXML2.ServerXMLHTTP')
http:Open("GET","http://www.family-historian.co.uk/wp-content/plugins/forced-download2/download.php?path=/wp-content/uploads/formidable/tatewise/&file=Map-Life-Facts3.fh_lua&id=190",true)
http:Send()
http:WaitForResponse(30)
print('Status: '..http.Status)
print('----------------------------------------------------------------')
headers = http:GetAllResponseHeaders()
data = http.Responsetext
print('Data Size = '..#data)
print('----------------------------------------------------------------')
print(headers)
I finally worked out what was going on so will post it here for others.
To avoid the truncation I needed to use ResponseBody and not ResponseText, what appears to be happening is the file is being sent in binary format, the ResponseText data is the same number of bytes as the ResponseBody one, but is in UTF-8 format, this means the number if special characters in the file (which are double byte in UTF-8 are dropped from the end of the ResponseText. I am not sure at what level the "mistake" in the length is made, but the way to avoid it is to use ResponseBody.