Re: [fpc-pascal] GetClipboardFormatName causing an Error 216

2020-12-30 Thread Alexander Grotewohl via fpc-pascal
The memory for FN is allocated at the top with StrAlloc()

--
Alexander Grotewohl
https://dcclost.com

From: fpc-pascal  on behalf of Martin 
Frb via fpc-pascal 
Sent: Wednesday, December 30, 2020 8:00 PM
To: fpc-pascal@lists.freepascal.org 
Cc: Martin Frb 
Subject: Re: [fpc-pascal] GetClipboardFormatName causing an Error 216

On 31/12/2020 01:09, James Richters via fpc-pascal wrote:
> Var
> FN : LPTSTR;
>
> Begin
>
> FN:='';
> Writeln(Format_ID);
> GetClipboardFormatName(Format_Id,FN,250);
>

Check the msdn help.
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboardformatnamea

FN must point to an existing buffer (allocated mem) that receives the
result.

FN : Array [0..255]of Byte;
GotLen := GetClipboardFormatName(Format_Id, LPTSTR(@FN[0]),250);

then "move()" the received bytes into a string, make sure to use
UniqueString() or similar

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] GetClipboardFormatName causing an Error 216

2020-12-30 Thread Martin Frb via fpc-pascal

I missed you have
FN:=StrAlloc (255);

in that case see Alexanders response.

On 31/12/2020 02:00, Martin Frb via fpc-pascal wrote:


FN must point to an existing buffer (allocated mem) that receives the 
result.


FN : Array [0..255]of Byte;
GotLen := GetClipboardFormatName(Format_Id, LPTSTR(@FN[0]),250);

then "move()" the received bytes into a string, make sure to use 
UniqueString() or similar


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] GetClipboardFormatName causing an Error 216

2020-12-30 Thread Martin Frb via fpc-pascal

On 31/12/2020 01:09, James Richters via fpc-pascal wrote:

Var
FN : LPTSTR;

Begin

FN:='';
Writeln(Format_ID);
GetClipboardFormatName(Format_Id,FN,250);



Check the msdn help.
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclipboardformatnamea

FN must point to an existing buffer (allocated mem) that receives the 
result.


FN : Array [0..255]of Byte;
GotLen := GetClipboardFormatName(Format_Id, LPTSTR(@FN[0]),250);

then "move()" the received bytes into a string, make sure to use 
UniqueString() or similar


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] GetClipboardFormatName causing an Error 216

2020-12-30 Thread Martin Frb via fpc-pascal

On 31/12/2020 01:09, James Richters via fpc-pascal wrote:

I'm trying to write a programs to get data from the windows clipboard that
was put into it with Notepad++ using vertical editing.


Just for Info, SynEdit (trunk) can handle notepad++ column selection

See the code at.
There are 2 common formats (and as a 3rd the one used by SynEdit).
NP++ uses one of them, not sure which.

components\synedit\syneditmiscclasses.pp
 TSynClipboardStream = class
    class function ClipboardFormatMSDEVColumnSelect: TClipboardFormat;
    class function ClipboardFormatBorlandIDEBlockType: TClipboardFormat;

IIRC in both cases the text is in the normal ClipBoard.AsText. Each line 
is one column segment.


'MSDEVColumnSelect' acts as a flag if present.
'Borland IDE Block Type' has a single byte. the value $02 indicates 
column mode.


Register the format, to get the ID, then check if it is on the clipboard.

Either check the synEdit source, or google the 2 format names
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] GetClipboardFormatName causing an Error 216

2020-12-30 Thread Alexander Grotewohl via fpc-pascal
Your

FN:='';

is clobbering the pointer 'FN' with nonsense.

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..


--
Alexander Grotewohl
https://dcclost.com

From: fpc-pascal  on behalf of James 
Richters via fpc-pascal 
Sent: Wednesday, December 30, 2020 7:09 PM
To: 'FPC-Pascal users discussions' 
Cc: James Richters 
Subject: [fpc-pascal] GetClipboardFormatName causing an Error 216

I'm trying to write a programs to get data from the windows clipboard that
was put into it with Notepad++ using vertical editing.
It uses a non-standard format and I'm trying to figure it out.
GetClipboardFormatName is supposed to get me the name of non-standard
formats,
but whenever I try to run it, I get a runtime error 216

I found some python code at: https://gist.github.com/adam-p/2514182 that I'm
trying to convert to FPC.
My fork is at:
https://gist.github.com/Zaaphod/7d94e1d712a5b9ac2bcb0bc79f039a63 Which shows
both the original python code and my FPC attempt

It works fine for standard formats:

Running "i:\programming\gcode\test\clipboard formats.exe "
Number of formats: 4
13 CF_UNICODETEXT
16 CF_LOCALE
1 CF_TEXT
7 CF_OEMTEXT

But if I highlight some text in Notepadd++ using vertical editing, holding
down Shift and ALT while using the arrow keys to highlight a block of text,
and the copy that to the clipboard, I get the following:

Running "i:\programming\gcode\test\clipboard formats.exe "
Number of formats: 6
13 CF_UNICODETEXT
49882
Runtime error 216 at $774C246C
  $774C246C
  $76932F63
  $76932EB7
  $004017EC  main,  line 60 of i:/programming/gcode/test/clipboard
formats.pas
  $00408F67

Line 60 is:
   GetClipboardFormatName(Format_Id,FN,250);

It only gets run for non-standard formats.  As I understand it that's all it
us supposed to be used for.

It's pretty short program so I pasted it below.

Any ideas on what I'm doing wrong here?

James

-


uses
   Windows,strings;
Type
   BT = Record
  BT_ID: Byte;
  BT_Name: String;
   End;

Const
builtin_type: Array [0..22] of BT = (
{ 0} (BT_ID:2   ;BT_Name:'CF_BITMAP' ),
{ 1} (BT_ID:8   ;BT_Name:'CF_DIB'),
{ 2} (BT_ID:17  ;BT_Name:'CF_DIBV5'  ),
{ 3} (BT_ID:5   ;BT_Name:'CF_DIF'),
{ 4} (BT_ID:130 ;BT_Name:'CF_DSPBITMAP'  ),
{ 5} (BT_ID:142 ;BT_Name:'CF_DSPENHMETAFILE' ),
{ 6} (BT_ID:131 ;BT_Name:'CF_DSPMETAFILEPICT'),
{ 7} (BT_ID:129 ;BT_Name:'CF_DSPTEXT'),
{ 8} (BT_ID:14  ;BT_Name:'CF_ENHMETAFILE'),
{ 9} (BT_ID:15  ;BT_Name:'CF_HDROP'  ),
{10} (BT_ID:16  ;BT_Name:'CF_LOCALE' ),
{11} (BT_ID:18  ;BT_Name:'CF_MAX'),
{12} (BT_ID:3   ;BT_Name:'CF_METAFILEPICT'   ),
{13} (BT_ID:7   ;BT_Name:'CF_OEMTEXT'),
{14} (BT_ID:128 ;BT_Name:'CF_OWNERDISPLAY'   ),
{15} (BT_ID:9   ;BT_Name:'CF_PALETTE'),
{16} (BT_ID:10  ;BT_Name:'CF_PENDATA'),
{17} (BT_ID:11  ;BT_Name:'CF_RIFF'   ),
{18} (BT_ID:4   ;BT_Name:'CF_SYLK'   ),
{19} (BT_ID:1   ;BT_Name:'CF_TEXT'   ),
{20} (BT_ID:6   ;BT_Name:'CF_TIFF'   ),
{21} (BT_ID:13  ;BT_Name:'CF_UNICODETEXT'),
{22} (BT_ID:12  ;BT_Name:'CF_WAVE'   ));

Var
   i,j,Number_Of_Formats : Byte;
   Format_ID : DWord;
   FN : LPTSTR;
   Format_Name : String;

Begin
   FN:=StrAlloc (255);
   OpenClipboard(0);
   Number_Of_Formats := CountClipboardFormats();
   Writeln('Number of formats: ',Number_Of_Formats);
   format_id := 0;
   for i := 1 to Number_Of_Formats do
  Begin
 Format_Name := 'FAILED';
 Format_ID:=EnumClipboardFormats(Format_ID);
 For J:= 0 to 22 do
Begin
   If Format_ID = builtin_type[J].BT_ID then
  Format_Name := builtin_type[J].BT_Name;
End;
 If Format_Name = 'FAILED' Then
Begin
   FN:='';
   Writeln(Format_ID);
   GetClipboardFormatName(Format_Id,FN,250);
   Writeln(FN);

   If strpas(FN) <> '' Then
  Format_Name := StrPas(FN);
End;
 Writeln(Format_ID,' ',Format_Name);
 End;
CloseClipboard();
End.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] GetClipboardFormatName causing an Error 216

2020-12-30 Thread James Richters via fpc-pascal
I'm trying to write a programs to get data from the windows clipboard that
was put into it with Notepad++ using vertical editing.
It uses a non-standard format and I'm trying to figure it out.
GetClipboardFormatName is supposed to get me the name of non-standard
formats,
but whenever I try to run it, I get a runtime error 216

I found some python code at: https://gist.github.com/adam-p/2514182 that I'm
trying to convert to FPC.  
My fork is at:
https://gist.github.com/Zaaphod/7d94e1d712a5b9ac2bcb0bc79f039a63 Which shows
both the original python code and my FPC attempt

It works fine for standard formats:

Running "i:\programming\gcode\test\clipboard formats.exe "
Number of formats: 4
13 CF_UNICODETEXT
16 CF_LOCALE
1 CF_TEXT
7 CF_OEMTEXT

But if I highlight some text in Notepadd++ using vertical editing, holding
down Shift and ALT while using the arrow keys to highlight a block of text, 
and the copy that to the clipboard, I get the following:

Running "i:\programming\gcode\test\clipboard formats.exe "
Number of formats: 6
13 CF_UNICODETEXT
49882
Runtime error 216 at $774C246C
  $774C246C
  $76932F63
  $76932EB7
  $004017EC  main,  line 60 of i:/programming/gcode/test/clipboard
formats.pas
  $00408F67

Line 60 is:
   GetClipboardFormatName(Format_Id,FN,250);

It only gets run for non-standard formats.  As I understand it that's all it
us supposed to be used for.

It's pretty short program so I pasted it below.

Any ideas on what I'm doing wrong here?

James

-


uses
   Windows,strings;
Type
   BT = Record
  BT_ID: Byte;
  BT_Name: String;
   End;

Const
builtin_type: Array [0..22] of BT = (
{ 0} (BT_ID:2   ;BT_Name:'CF_BITMAP' ),
{ 1} (BT_ID:8   ;BT_Name:'CF_DIB'),
{ 2} (BT_ID:17  ;BT_Name:'CF_DIBV5'  ),
{ 3} (BT_ID:5   ;BT_Name:'CF_DIF'),
{ 4} (BT_ID:130 ;BT_Name:'CF_DSPBITMAP'  ),
{ 5} (BT_ID:142 ;BT_Name:'CF_DSPENHMETAFILE' ),
{ 6} (BT_ID:131 ;BT_Name:'CF_DSPMETAFILEPICT'),
{ 7} (BT_ID:129 ;BT_Name:'CF_DSPTEXT'),
{ 8} (BT_ID:14  ;BT_Name:'CF_ENHMETAFILE'),
{ 9} (BT_ID:15  ;BT_Name:'CF_HDROP'  ),
{10} (BT_ID:16  ;BT_Name:'CF_LOCALE' ),
{11} (BT_ID:18  ;BT_Name:'CF_MAX'),
{12} (BT_ID:3   ;BT_Name:'CF_METAFILEPICT'   ),
{13} (BT_ID:7   ;BT_Name:'CF_OEMTEXT'),
{14} (BT_ID:128 ;BT_Name:'CF_OWNERDISPLAY'   ),
{15} (BT_ID:9   ;BT_Name:'CF_PALETTE'),
{16} (BT_ID:10  ;BT_Name:'CF_PENDATA'),
{17} (BT_ID:11  ;BT_Name:'CF_RIFF'   ),
{18} (BT_ID:4   ;BT_Name:'CF_SYLK'   ),
{19} (BT_ID:1   ;BT_Name:'CF_TEXT'   ),
{20} (BT_ID:6   ;BT_Name:'CF_TIFF'   ),
{21} (BT_ID:13  ;BT_Name:'CF_UNICODETEXT'),
{22} (BT_ID:12  ;BT_Name:'CF_WAVE'   ));

Var
   i,j,Number_Of_Formats : Byte;
   Format_ID : DWord;
   FN : LPTSTR;
   Format_Name : String;

Begin
   FN:=StrAlloc (255);
   OpenClipboard(0);
   Number_Of_Formats := CountClipboardFormats();
   Writeln('Number of formats: ',Number_Of_Formats);
   format_id := 0;
   for i := 1 to Number_Of_Formats do
  Begin
 Format_Name := 'FAILED';
 Format_ID:=EnumClipboardFormats(Format_ID);
 For J:= 0 to 22 do
Begin
   If Format_ID = builtin_type[J].BT_ID then
  Format_Name := builtin_type[J].BT_Name;
End;
 If Format_Name = 'FAILED' Then
Begin
   FN:='';
   Writeln(Format_ID);
   GetClipboardFormatName(Format_Id,FN,250);
   Writeln(FN);
   
   If strpas(FN) <> '' Then
  Format_Name := StrPas(FN);
End;
 Writeln(Format_ID,' ',Format_Name);
 End;
CloseClipboard();
End.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Two versions of freemem() - are they equal

2020-12-30 Thread Alexander Grotewohl via fpc-pascal
The TP7 manual suggests it was possible to partially free the memory. If you 
had a pointer to the un-freed chunk, I wonder if that could also have been 
freed, or if was left in limbo.

As the manual suggests, I bet everyone just used SizeOf() as the parameter, and 
I'm not so sure how useful using freemem like above would be..

--
Alexander Grotewohl
https://dcclost.com


From: fpc-pascal  on behalf of Marco 
van de Voort via fpc-pascal 
Sent: Wednesday, December 30, 2020 5:56:45 PM
To: FPC-Pascal users discussions 
Cc: Marco van de Voort 
Subject: Re: [fpc-pascal] Two versions of freemem() - are they equal


Op 2020-12-30 om 23:54 schreef Graeme Geldenhuys via fpc-pascal:
> Do both these method yield the same result, or is one better (performance,
> safer?) that the other?
>
>
> procedure FreeMem(p:pointer;Size:ptruint);
> procedure FreeMem(p:pointer);
They are the same.   TP required size for deallocation, Delphi and FPC
don't.  The overload with size is for TP compatibility.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Two versions of freemem() - are they equal

2020-12-30 Thread Marco van de Voort via fpc-pascal


Op 2020-12-30 om 23:54 schreef Graeme Geldenhuys via fpc-pascal:

Do both these method yield the same result, or is one better (performance,
safer?) that the other?


procedure FreeMem(p:pointer;Size:ptruint);
procedure FreeMem(p:pointer);
They are the same.   TP required size for deallocation, Delphi and FPC 
don't.  The overload with size is for TP compatibility.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Two versions of freemem() - are they equal

2020-12-30 Thread Graeme Geldenhuys via fpc-pascal
Hi,

Do both these method yield the same result, or is one better (performance,
safer?) that the other?


procedure FreeMem(p:pointer;Size:ptruint);
procedure FreeMem(p:pointer);


Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal