[fpc-pascal] fpweb and reading the contents of a request
Hello, I am trying to send data from javascript and read data back from my cgi module with this: SendSyncRequest = function(RequestURL, RequestContent) { var request = new XMLHttpRequest(); request.open('GET', RequestURL, false); request.setRequestHeader('Content-Type', 'text/html'); request.send(RequestContent); //debugDiv.innerHTML = debugDiv.innerHTML + after sendbr; return request.responseText; } var tableInnerHTML = SendSyncRequest(mywebapp.cgi?module=LobbyServer, $200); Which works, except for 1 thing. I wanted to read this $200 in my web module, but: procedure TwebLobbyServer.DataModuleRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: Boolean); var LobbyComm: TLobbyComm; OPResponse: TGameResponse = nil; Msg: TMarshallable; begin WebDebugOut('[TwebLobbyServer.DataModuleRequest] ARequest.Content=' + ARequest.Content); With this code I receive an empty ARequest.Content Any ideas? thanks, -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, 17 Oct 2011, Felipe Monteiro de Carvalho wrote: Hello, I am trying to send data from javascript and read data back from my cgi module with this: SendSyncRequest = function(RequestURL, RequestContent) { var request = new XMLHttpRequest(); request.open('GET', RequestURL, false); request.setRequestHeader('Content-Type', 'text/html'); request.send(RequestContent); //debugDiv.innerHTML = debugDiv.innerHTML + after sendbr; return request.responseText; As far as I know, this will always be empty, for the simple reason that the request is executed asynchronously. You must attach a callback which is executed once the request is ready, and read ResponseText after that. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, Oct 17, 2011 at 3:55 PM, Michael Van Canneyt mich...@freepascal.org wrote: As far as I know, this will always be empty, for the simple reason that the request is executed asynchronously. You must attach a callback which is executed once the request is ready, and read ResponseText after that. Ah, no, my problem is not in the JavaScript ... my syncronous request works fine in Opera at least. My problem is in fpweb: procedure TwebLobbyServer.DataModuleRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: Boolean); begin WebDebugOut('[TwebLobbyServer.DataModuleRequest] ARequest.Content=' + ARequest.Content); --- HERE This is where I get an empty ARequest.Content -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, 17 Oct 2011, Felipe Monteiro de Carvalho wrote: On Mon, Oct 17, 2011 at 3:55 PM, Michael Van Canneyt mich...@freepascal.org wrote: As far as I know, this will always be empty, for the simple reason that the request is executed asynchronously. You must attach a callback which is executed once the request is ready, and read ResponseText after that. Ah, no, my problem is not in the JavaScript ... my syncronous request works fine in Opera at least. ? AFAIK xhttprequest is never synchronous... My problem is in fpweb: procedure TwebLobbyServer.DataModuleRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: Boolean); begin WebDebugOut('[TwebLobbyServer.DataModuleRequest] ARequest.Content=' + ARequest.Content); --- HERE This is where I get an empty ARequest.Content Did you properly encode the content ? Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, Oct 17, 2011 at 4:01 PM, Michael Van Canneyt mich...@freepascal.org wrote: ? AFAIK xhttprequest is never synchronous... It is synchronous if the third parameter of open is set to false: http://www.w3.org/TR/XMLHttpRequest/#the-open-method client . open(method, url, async, user, password) The asynchronous flag True when fetching is done asychronously. False when fetching is done synchronously. Did you properly encode the content ? What exactly do I need to do? Pass a header saying it is UTF-8? I am just sending simple text. -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, 17 Oct 2011, Felipe Monteiro de Carvalho wrote: On Mon, Oct 17, 2011 at 4:01 PM, Michael Van Canneyt mich...@freepascal.org wrote: ? AFAIK xhttprequest is never synchronous... It is synchronous if the third parameter of open is set to false: http://www.w3.org/TR/XMLHttpRequest/#the-open-method client . open(method, url, async, user, password) The asynchronous flag True when fetching is done asychronously. False when fetching is done synchronously. Did you properly encode the content ? What exactly do I need to do? Pass a header saying it is UTF-8? I am just sending simple text. Ehm. I think that the problem is elsewhere. Content is only accepted with the POST method. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, Oct 17, 2011 at 4:11 PM, Michael Van Canneyt mich...@freepascal.org wrote: Ehm. I think that the problem is elsewhere. Content is only accepted with the POST method. Why? Is this a limitation from HTTP? If I change to POST then I can no longer select my module, neither ?module=MainPage nor /MainPage worked. In fact then I get a very strange error message: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. With this Apache log: [Mon Oct 17 16:20:15 2011] [error] [client 127.0.0.1] Premature end of script headers: openpoker3.cgi, referer: http://localhost:8080/cgi-bin/openpoker3.cgi?module=MainPage -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, 17 Oct 2011, Felipe Monteiro de Carvalho wrote: On Mon, Oct 17, 2011 at 4:11 PM, Michael Van Canneyt mich...@freepascal.org wrote: Ehm. I think that the problem is elsewhere. Content is only accepted with the POST method. Why? Is this a limitation from HTTP? Yes. If I change to POST then I can no longer select my module, neither ?module=MainPage nor /MainPage worked. In fact then I get a very strange error message: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. You must specify an action. A single path component is treated as an action. ?module=MainPageAction=MyAction Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, Oct 17, 2011 at 4:33 PM, Michael Van Canneyt mich...@freepascal.org wrote: Yes. I see ... simply encoding the data differently from what I originally wanted and feeding it to a GET field worked fine. You must specify an action. A single path component is treated as an action. ?module=MainPageAction=MyAction That didn't help. Also I was not using actions before and it worked with GET without specifying an action. I think that this part of the URL cannot be used in POST, so we would need another way to select the module. Although I might be wrong. -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] fpweb and custom debug log
Hello, I see that when my CGI raises an exception we get a nice error message with a stack trace as a response. Is it possible to put some logging messages into this error response too? I know I can simply put logging info into log files in the server, but it looks like it would be handy to be able to see the log messages directly in the browser if an exception happens. thanks, -- Felipe Monteiro de Carvalho ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and reading the contents of a request
On Mon, 17 Oct 2011, Felipe Monteiro de Carvalho wrote: On Mon, Oct 17, 2011 at 4:33 PM, Michael Van Canneyt mich...@freepascal.org wrote: Yes. I see ... simply encoding the data differently from what I originally wanted and feeding it to a GET field worked fine. Also a solution :-) You must specify an action. A single path component is treated as an action. ?module=MainPageAction=MyAction That didn't help. Also I was not using actions before and it worked with GET without specifying an action. That's because the system assumes certain defaults. I think that this part of the URL cannot be used in POST, so we would need another way to select the module. Although I might be wrong. The method of determining the module/action does not depend on the method. Either PATHINFO is used, or the module and action request variables are used. You can perfectly do a post with an URL that contains ?module=MainPageAction=MyAction Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpweb and custom debug log
On Mon, 17 Oct 2011, Felipe Monteiro de Carvalho wrote: Hello, I see that when my CGI raises an exception we get a nice error message with a stack trace as a response. Is it possible to put some logging messages into this error response too? With some custom coding, it should be possible, yes. The error message is formatted in ShowException, if I'm correct. It works much as in TApplication. I know I can simply put logging info into log files in the server, but it looks like it would be handy to be able to see the log messages directly in the browser if an exception happens. Eventually, I plan to implement something like firephp, which logs into the http headers, and this is subsequently shown by firebug... Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Reopen issue 20500: TSQLParser cant Parse Statements containing as
The issue reporter gave this example: select ORDERNO as OrderNo from ORDERS as Orders; It does parse AS, but only for a field. Michael Van Canneyt replied: TSQLParser implements SQL syntax as used in Firebird, and firebird does not allow AS for a tablename, just append the alias. The correct syntax would be: select ORDERNO as OrderNo from ORDERS Orders; However: On my Firebird 2.5, this works perfectly (in FlameRobin and SQLWorkBench/J): select * from rdb$relations as tables; Would it make sense to reopen this bug? Thanks, Reinier ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Reopen issue 20500: TSQLParser cant Parse Statements containing as
On Mon, 17 Oct 2011, Reinier Olislagers wrote: The issue reporter gave this example: select ORDERNO as OrderNo from ORDERS as Orders; It does parse AS, but only for a field. Michael Van Canneyt replied: TSQLParser implements SQL syntax as used in Firebird, and firebird does not allow AS for a tablename, just append the alias. The correct syntax would be: select ORDERNO as OrderNo from ORDERS Orders; However: On my Firebird 2.5, this works perfectly (in FlameRobin and SQLWorkBench/J): select * from rdb$relations as tables; Would it make sense to reopen this bug? ? Eh ? If indeed it is accepted, then yes please. Quite strange, because I implemented the SQL parser based on the official Firebird server docs. And it definitely was not allowed. But I'll test on 2.5, and if it indeed works, I'll of course implement it. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] How can I implement thrice in Free Pascal?
Haskell lets you define functions like thrice, which accepts an element of type a and returns a list of the element repeated three times, for any data type a. thrice :: a - [a] thrice x = [x, x, x] I know the answer involves generics, but the docs don't offer examples using Free Pascal's built-in generic types. Cheers, Andrew Pennebaker www.yellosoft.us ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Delphi's anonymous functions in Free Pascal
Does Free Pascal have anonymous functions that you can pass around, e.g. to a sort(compare : function, arr : array) function? If not, does anyone know any hacks to accomplish this? Cheers, Andrew Pennebaker www.yellosoft.us ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
In our previous episode, Andrew Pennebaker said: thrice :: a - [a] thrice x = [x, x, x] I know the answer involves generics, but the docs don't offer examples using Free Pascal's built-in generic types. There is no built in list type, generic or not, and no way to define new operators. All list and collection types are library. I see no way this could work. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Can this be done with arrays? I didn't mean to be too specific; I'd be happy with any generic collection that could do this. Cheers, Andrew Pennebaker www.yellosoft.us On Mon, Oct 17, 2011 at 6:08 PM, Marco van de Voort mar...@stack.nl wrote: In our previous episode, Andrew Pennebaker said: thrice :: a - [a] thrice x = [x, x, x] I know the answer involves generics, but the docs don't offer examples using Free Pascal's built-in generic types. There is no built in list type, generic or not, and no way to define new operators. All list and collection types are library. I see no way this could work. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] fpc has trouble with array types
But, but, the docs imply that this is the syntax for a function that returns an array of bytes. fpc ios7crypt.pas ios7crypt.pas(3,25) Error: Type identifier expected ios7crypt.pas(3,25) Fatal: Syntax error, ; expected but ARRAY found Fatal: Compilation aborted $ cat ios7crypt.pas program IOS7Crypt; function XlatPrime () : array of byte; begin XlatPrime := ( $64, $73, $66, $64, $3b, $6b, $66, $6f, $41, $2c, $2e, $69, $79, $65, $77, $72, $6b, $6c, $64, $4a, $4b, $44, $48, $53, $55, $42, $73, $67, $76, $63, $61, $36, $39, $38, $33, $34, $6e, $63, $78, $76, $39, $38, $37, $33, $32, $35, $34, $6b, $3b, $66, $67, $38, $37 ); end; function Encrypt (hash : string) : string; begin Encrypt := 'abc'; end; function Decrypt (hash : string) : string; begin Decrypt := 'abc'; end; var password : string; hash : string; begin password := 'abc'; hash := Encrypt(password); password := Decrypt(hash); write('Password: '); writeln(password); end. Cheers, Andrew Pennebaker www.yellosoft.us ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Reopen issue 20500: TSQLParser cant Parse Statements containing as
On 17-10-2011 20:57, Michael Van Canneyt wrote: Would it make sense to reopen this bug? ? Eh ? If indeed it is accepted, then yes please. Quite strange, because I implemented the SQL parser based on the official Firebird server docs. And it definitely was not allowed. But I'll test on 2.5, and if it indeed works, I'll of course implement it. Michael. Had a look through the Interbase 6 docs. The description on SELECT indeed mentions column aliases with AS but table aliases without them. Then the Firebird 2.5 Language Reference Update (8 October 2011, version 1.1, covers Firebird 2.5 and 2.5.1) http://www.firebirdsql.org/en/news/firebird-2-5-language-reference-update-12296/ doesn't explicitly say anything about table aliases with AS... I'll ask in the Firebird list, maybe the docs need updating. Note: I didn't open that ticket, so can't reopen it... Reinier ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpc has trouble with array types
2011/10/18 Andrew Pennebaker andrew.penneba...@gmail.com: But, but, the docs imply that this is the syntax for a function that returns an array of bytes. Where in the docs did you read this? Vincent ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal