<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Your</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
FN:=''; </div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
is clobbering the pointer 'FN' with nonsense.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Just leave that line out, it isn't necessary. Or do like FN^:=#0; if you want C-string like functions to report zero length..</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div>
<div id="Signature">
<div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
--</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Alexander Grotewohl</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
https://dcclost.com</div>
</div>
</div>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> fpc-pascal <fpc-pascal-bounces@lists.freepascal.org> on behalf of James Richters via fpc-pascal <fpc-pascal@lists.freepascal.org><br>
<b>Sent:</b> Wednesday, December 30, 2020 7:09 PM<br>
<b>To:</b> 'FPC-Pascal users discussions' <fpc-pascal@lists.freepascal.org><br>
<b>Cc:</b> James Richters <james.richters@productionautomation.net><br>
<b>Subject:</b> [fpc-pascal] GetClipboardFormatName causing an Error 216</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">I'm trying to write a programs to get data from the windows clipboard that<br>
was put into it with Notepad++ using vertical editing.<br>
It uses a non-standard format and I'm trying to figure it out.<br>
GetClipboardFormatName is supposed to get me the name of non-standard<br>
formats,<br>
but whenever I try to run it, I get a runtime error 216<br>
<br>
I found some python code at: <a href="https://gist.github.com/adam-p/2514182">https://gist.github.com/adam-p/2514182</a> that I'm<br>
trying to convert to FPC. <br>
My fork is at:<br>
<a href="https://gist.github.com/Zaaphod/7d94e1d712a5b9ac2bcb0bc79f039a63">https://gist.github.com/Zaaphod/7d94e1d712a5b9ac2bcb0bc79f039a63</a> Which shows<br>
both the original python code and my FPC attempt<br>
<br>
It works fine for standard formats:<br>
<br>
Running "i:\programming\gcode\test\clipboard formats.exe "<br>
Number of formats: 4<br>
13 CF_UNICODETEXT<br>
16 CF_LOCALE<br>
1 CF_TEXT<br>
7 CF_OEMTEXT<br>
<br>
But if I highlight some text in Notepadd++ using vertical editing, holding<br>
down Shift and ALT while using the arrow keys to highlight a block of text, <br>
and the copy that to the clipboard, I get the following:<br>
<br>
Running "i:\programming\gcode\test\clipboard formats.exe "<br>
Number of formats: 6<br>
13 CF_UNICODETEXT<br>
49882<br>
Runtime error 216 at $774C246C<br>
$774C246C<br>
$76932F63<br>
$76932EB7<br>
$004017EC main, line 60 of i:/programming/gcode/test/clipboard<br>
formats.pas<br>
$00408F67<br>
<br>
Line 60 is:<br>
GetClipboardFormatName(Format_Id,FN,250);<br>
<br>
It only gets run for non-standard formats. As I understand it that's all it<br>
us supposed to be used for.<br>
<br>
It's pretty short program so I pasted it below.<br>
<br>
Any ideas on what I'm doing wrong here?<br>
<br>
James<br>
<br>
---------------------------------------------<br>
<br>
<br>
uses<br>
Windows,strings;<br>
Type<br>
BT = Record<br>
BT_ID: Byte;<br>
BT_Name: String;<br>
End;<br>
<br>
Const<br>
builtin_type: Array [0..22] of BT = (<br>
{ 0} (BT_ID:2 ;BT_Name:'CF_BITMAP' ),<br>
{ 1} (BT_ID:8 ;BT_Name:'CF_DIB' ),<br>
{ 2} (BT_ID:17 ;BT_Name:'CF_DIBV5' ),<br>
{ 3} (BT_ID:5 ;BT_Name:'CF_DIF' ),<br>
{ 4} (BT_ID:130 ;BT_Name:'CF_DSPBITMAP' ),<br>
{ 5} (BT_ID:142 ;BT_Name:'CF_DSPENHMETAFILE' ),<br>
{ 6} (BT_ID:131 ;BT_Name:'CF_DSPMETAFILEPICT'),<br>
{ 7} (BT_ID:129 ;BT_Name:'CF_DSPTEXT' ),<br>
{ 8} (BT_ID:14 ;BT_Name:'CF_ENHMETAFILE' ),<br>
{ 9} (BT_ID:15 ;BT_Name:'CF_HDROP' ),<br>
{10} (BT_ID:16 ;BT_Name:'CF_LOCALE' ),<br>
{11} (BT_ID:18 ;BT_Name:'CF_MAX' ),<br>
{12} (BT_ID:3 ;BT_Name:'CF_METAFILEPICT' ),<br>
{13} (BT_ID:7 ;BT_Name:'CF_OEMTEXT' ),<br>
{14} (BT_ID:128 ;BT_Name:'CF_OWNERDISPLAY' ),<br>
{15} (BT_ID:9 ;BT_Name:'CF_PALETTE' ),<br>
{16} (BT_ID:10 ;BT_Name:'CF_PENDATA' ),<br>
{17} (BT_ID:11 ;BT_Name:'CF_RIFF' ),<br>
{18} (BT_ID:4 ;BT_Name:'CF_SYLK' ),<br>
{19} (BT_ID:1 ;BT_Name:'CF_TEXT' ),<br>
{20} (BT_ID:6 ;BT_Name:'CF_TIFF' ),<br>
{21} (BT_ID:13 ;BT_Name:'CF_UNICODETEXT' ),<br>
{22} (BT_ID:12 ;BT_Name:'CF_WAVE' ));<br>
<br>
Var<br>
i,j,Number_Of_Formats : Byte;<br>
Format_ID : DWord;<br>
FN : LPTSTR;<br>
Format_Name : String;<br>
<br>
Begin<br>
FN:=StrAlloc (255);<br>
OpenClipboard(0);<br>
Number_Of_Formats := CountClipboardFormats();<br>
Writeln('Number of formats: ',Number_Of_Formats);<br>
format_id := 0;<br>
for i := 1 to Number_Of_Formats do<br>
Begin<br>
Format_Name := 'FAILED';<br>
Format_ID:=EnumClipboardFormats(Format_ID);<br>
For J:= 0 to 22 do<br>
Begin<br>
If Format_ID = builtin_type[J].BT_ID then<br>
Format_Name := builtin_type[J].BT_Name;<br>
End;<br>
If Format_Name = 'FAILED' Then<br>
Begin<br>
FN:='';<br>
Writeln(Format_ID);<br>
GetClipboardFormatName(Format_Id,FN,250);<br>
Writeln(FN);<br>
<br>
If strpas(FN) <> '' Then<br>
Format_Name := StrPas(FN);<br>
End;<br>
Writeln(Format_ID,' ',Format_Name);<br>
End;<br>
CloseClipboard();<br>
End.<br>
<br>
_______________________________________________<br>
fpc-pascal maillist - fpc-pascal@lists.freepascal.org<br>
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br>
</div>
</span></font></div>
</body>
</html>