Buffer abuse

"flicknemo" <[email protected]> Thu, 25 Apr 2013 13:11:00 -0000
Newsgroups gmane.comp.windows.gui4cli
Message-ID <[email protected]>
Buffer abuse

Hi Dimitris,

I wrote a script to detect drop any LNK file icon onto its window.
On each drop it is detected by my function
~~~~~~~~~~~~~
xondrop #window
local filepath
~~~~~~~~~~~~~
which checks first if it is a LNK, and opts out if it is not.
Since it is to be used repeatedly during the run, on each drop, it has
to
clear the data by :
  Buffer LOAD $filepath Binarydata //Read the file contents to RAM
The interpreter is set not to allow us to accidentally overwrite our
buffer data.
So it only allows this when it is creating Binarydata in RAM during a
run.

There is an error message which halts it if it already exists .  The
answer is to free the
Binarydata buffer.  If it does NOT already exist, it gives an error
message
when the script tries to free it.  I looked at IFEXIST... ENDIF in the
manual
and it was not listed for buffers.  So I reasoned that if it tries to
Use buffer,
the interpreter will make it point at the RAM containing that buffer. 
Then it
should set a true or false in the $$buffer.valid
~~~~~~~~~~~~~
use buffer Binarydata
if $$buffer.valid > 0
      buffer free Binarydata
endif
~~~~~~~~~~~~~
I get an error :
  [Item was not found, Binarydata]
on the first drop, since the script asks this first before doing
anything else. That will be from asking it to use a buffer which does
not exist.  While the buffer lives it contains the contents of the LNK
file and another function :
xroutine link2path buffer_name pcmode
has these : modes of operation
//mode =  0 which it defaults to pcpath, 1 is pcpath in quotes, 2 is
gcpath, 3 is pcpath in quotes
A Docase causes the selecting number to create the text in that manner,
which at the moment, I shall print on the Debug output screen GCWIN. 
The text will be used by other calling scripts as this is a library
function.

It is only intellectually challenging as the function does its job. 
Shall I live with the error message in
debug, or is there a way around this?

Regards, Flicknemo