claudefox / ActiveVFP

17 stars 7 forks source link

oRequest.DumpVars => something useful (JSON) #4

Open tachyx opened 5 years ago

tachyx commented 5 years ago

I can't make an object containing the HTTP request form key-value pairs.

ActiveVFP can't fully expose the oRequest context. The only thing it does is DumpVars() which spits out a literal HTML string of a table containing the information. An HTML string is useless for practical purposes, I need a JSON string which I can then convert into an object and "for each" in my code.

I wrote a new method based on the form section of DumpVars but it doesn't produce any results.

So I tried to call out oRequest.DumpVars and it throws an error because there is not enough data-type checking.

dumpvars err#= 107 line= 1501 (in my code!) Operator/operand type mismatch. In my code line 1501 is: +lcVar +[]+crlf Which assumes lcVar is a string. I would suppose it should be a string, but apparently not.

Anyway this is the method I added which produces no results (blank string):

FUNCTION formJSON PRIVATE lcSTR, lcFormVar, lcVar lcSTR="" FOR EACH lcFormVar IN THIS.oRequest.FORM IF ISBLANK(lcSTR) lcSTR=[{] ELSE lcSTR=lcSTR+[,] ENDIF lcVar = THIS.oRequest.FORM(lcFormVar) lcSTR=lcSTR+["]+lcFormVar+[":"]+lcVar+["] NEXT IF !ISBLANK(lcSTR) lcSTR=lcSTR+[}] ENDIF RETURN lcSTR ENDFUNC

And this also throws the same error on the line assuming lcVar is a string.

I tried to add data-type checking using either VARTYPE or TRANSFORM but VFP will fail to build the project if either of those commands are used at all.

Function argument value, type or count is invalid And produces a small DLL file which is not valid.

tachyx commented 5 years ago

Sometimes, sometimes not, I get "Function argument value, type, or count is invalid." error during build. Restarting VFP seemed to fix it but annoying. Remember to run as Administrator!

So I spent a lot of time trying to expose the request.form contents and I found a bug in my AJAX code which was not sending anything, so nothing was found in the request.form.