Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-06

Writing fpWeb app without Lazarus

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mr Bee
Hi all,
I'm now learning how to use fpWeb. But for some reasons, I don't want to use Lazarus. Instead, I want to write the program using plain text editor or console text editor (like vim, nano, etc), in case I need to do it remotely. It's now just a simple Hello World program, so it must be simple enough to write the program as a single file without Lazarus. However, I failed. There must be something stupid that I forgot to write but I don't know what that is. So here's my code: program HelloWeb;
{$MODE OBJFPC}{$H+}{$J-}
uses  Classes, HTTPDefs, fpHTTP, fpCGI, fpWeb;
type  THelloModule = class(TFPWebModule)    procedure HelloReq(Sender: TObject; ARequest: TRequest;                       AResponse: TResponse; var Handled: Boolean);  end;
var  HelloModule: THelloModule;
procedure THelloModule.HelloReq(Sender: TObject; ARequest: TRequest;                                AResponse: TResponse; var Handled: Boolean);begin  AResponse.ContentType := 'text/html;charset=utf-8';  AResponse.Content := '<html><body>Hello World!</body></html>';  Handled := true;end;
begin  HelloModule := THelloModule.Create(nil);  HelloModule.ActionVar := 'm';  HelloModule.OnRequest := @HelloModule.HelloReq;
  RegisterHTTPModule('THelloModule',THelloModule,true);
  Application.Title := 'Hello World';  Application.Initialize;  Application.Run;end.
It was compiled fine without any errors using -XXs -CX -O3 parameters. But when the executable is deployed and then accessed from the browser, it returns 500 internal server error. I don't know what to do as I saw nothing is wrong.
That's the first problem. The second one is a question. I'd like to use fpWeb components in plain procedural way, without using the TApplication infrastructure, especially for simple CGI apps/services. Is it possible? Any advices?
I'm using a Linux Ubuntu 14.04 machine with Apache web server. I believe the problem has nothing to do with the OS nor the web server because my plain Pascal CGI (without using fpWeb) is running just fine.
Any hints to solve the problem is really appreciated.
Thank you.
Regards,
–Mr Bee
Michael Van Canneyt
to Mr Bee
Mr Bee wrote 12 lines
Hi all, I'm now learning how to use fpWeb. But for some reasons, I don't want to use Lazarus. Instead, I want to write the program using plain text editor or console text editor (like vim, nano, etc), in case I need to do it remotely. It's now just a simple Hello World program, so it must be simple enough to write the program as a single file without Lazarus. However, I failed. There must be something stupid that I forgot to write but I don't know what that is. So here's my code: program HelloWeb; {$MODE OBJFPC}{$H+}{$J-} uses  Classes, HTTPDefs, fpHTTP, fpCGI, fpWeb; type  THelloModule = class(TFPWebModule)    procedure HelloReq(Sender: TObject; ARequest: TRequest;                       AResponse: TResponse; var Handled: Boolean);  end; var  HelloModule: THelloModule; procedure THelloModule.HelloReq(Sender: TObject; ARequest: TRequest;                                AResponse: TResponse; var Handled: Boolean);begin  AResponse.ContentType := 'text/html;charset=utf-8';  AResponse.Content := '<html><body>Hello World!</body></html>';  Handled := true;end; begin  HelloModule := THelloModule.Create(nil);  HelloModule.ActionVar := 'm';  HelloModule.OnRequest := @HelloModule.HelloReq;   RegisterHTTPModule('THelloModule',THelloModule,true);   Application.Title := 'Hello World';  Application.Initialize;  Application.Run;end. It was compiled fine without any errors using -XXs -CX -O3 parameters. But when the executable is deployed and then accessed from the browser, it returns 500 internal server error. I don't know what to do as I saw nothing is wrong.

What is the URL you used to access your app ?
What is the output in the browser ?

Then, never create an instance of a webmodule manually, always let the framework create instances.

Also, a statement as

HelloModule := THelloModule.Create(nil);

is wrong, since it will attempt to stream the module. If you do want to create modules manually, do
HelloModule := THelloModule.CreateNew(nil,0);

That's the first problem. The second one is a question. I'd like to use fpWeb components in plain procedural way, without using the TApplication infrastructure, especially for simple CGI apps/services. Is it possible? Any advices?

No, this is not possible.
It was explicitly designed to use classes in a RAD environment. It is perfectly possible to drop the RAD part and use the classes as-is, but it is not possible not to use the classes.

I'm using a Linux Ubuntu 14.04 machine with Apache web server. I believe the problem has nothing to do with the OS nor the web server because my plain Pascal CGI (without using fpWeb) is running just fine.

Without more information, it is hard to say.

There are multiple examples in the FPC source tree;
Why don't you use those as a starting point ?

Michael.

Mr Bee
to Michael Van Canneyt

Pada Selasa, 7 Juni 2016 15:23, Michael Van Canneyt menulis:

What is the URL you used to access your app ?

http://beeography.koding.io/hello.cgi (/mod) (/act [/act1 | act/act2])

And here's the source code: http://pastebin.com/N7EQz4Lk Feel free to correct any mistakes in my code. Thank you.

What is the output in the browser ?

Just a "hello world" message.

Then, never create an instance of a webmodule manually, always let the

framework create instances.
Yes, the problem has been solved with a help from Mario's ebook (https://bitbucket.org/leledumbo/books/downloads/fpwebtutorial-chromeprint.pdf). Mario is also known as @leledumbo at Lazarus' forum.

Show quoted text 5 lines
Also, a statement as HelloModule := THelloModule.Create(nil); is wrong, since it will attempt to stream the module. If you do want to create modules manually, do HelloModule := THelloModule.CreateNew(nil,0);

Yes, I should have figured it out earlier, but it's been a long time since the last time I used TDataModule, so there are many things that I forgot about VCL. In fact, that's the main source of my problem. Once I used the CreateNew constructor, everything works as expected. Though I still have many things to learn to understand how the fpWeb works. :)

No, this is not possible. It was explicitly designed to use classes in a RAD environment. It is perfectly possible to drop the RAD part and use the classes as-is, but it is not possible not to use the classes.

I don't mind the clasess, but I do mind the RAD part. A web app development should be able to be done without the RAD part because in some cases we don't always have the access to use the RAD.

There are multiple examples in the FPC source tree;  Why don't you use those as a starting point ?

I did. But all the examples I found are using Lazarus aka RAD. Hence this email. fpWeb —and all the gems of FCL— do really need proper and complete documentations. It's hard —especially for Pascal newbies— to learn FCL from the source code alone. Documentation is the main and first obstacle for everyone who like to use FCL to its potential. I wish I could help. Thank you for the reply, Michael. 
Regards,
–Mr Bee

Michael Van Canneyt
to Mr Bee
Mr Bee wrote 27 lines
Pada Selasa, 7 Juni 2016 15:23, Michael Van Canneyt menulis: > What is the URL you used to access your app ? http://beeography.koding.io/hello.cgi (/mod) (/act [/act1 | act/act2]) And here's the source code: http://pastebin.com/N7EQz4Lk Feel free to correct any mistakes in my code. Thank you. > What is the output in the browser ? Just a "hello world" message. > Then, never create an instance of a webmodule manually, always let the framework create instances. Yes, the problem has been solved with a help from Mario's ebook (https://bitbucket.org/leledumbo/books/downloads/fpwebtutorial-chromeprint.pdf). Mario is also known as @leledumbo at Lazarus' forum. > Also, a statement as > HelloModule := THelloModule.Create(nil); > is wrong, since it will attempt to stream the module. If you do want to > create modules manually, do > HelloModule := THelloModule.CreateNew(nil,0); Yes, I should have figured it out earlier, but it's been a long time since the last time I used TDataModule, so there are many things that I forgot about VCL. In fact, that's the main source of my problem. Once I used the CreateNew constructor, everything works as expected. Though I still have many things to learn to understand how the fpWeb works. :) > No, this is not possible. > It was explicitly designed to use classes in a RAD environment. > It is perfectly possible to drop the RAD part and use the classes as-is, but > it is not possible not to use the classes. I don't mind the clasess, but I do mind the RAD part. A web app development should be able to be done without the RAD part because in some cases we don't always have the access to use the RAD.

I develop using fpweb all the time, without RAD, so I know this works :-)

Show quoted text 7 lines
> There are multiple examples in the FPC source tree;  > Why don't you use those as a starting point ? I did. But all the examples I found are using Lazarus aka RAD. Hence this email. fpWeb —and all the gems of FCL— do really need proper and complete documentations. It's hard —especially for Pascal newbies— to learn FCL from the source code alone. Documentation is the main and first obstacle for everyone who like to use FCL to its potential. I wish I could help.

There are over 1000 units. There is only 1 documenter...

On
http://www.freepascal.org/~michael/articles/
you can find some articles that explain the workings of fcl-web. See web1, web2.

Michael.

Graeme Geldenhuys
to Mr Bee: Pada Selasa, 7 Juni 2016 15:23, Michael Van Canneyt menulis:…
Mr Bee wrote
I did. But all the examples I found are using Lazarus aka RAD.

If you look at the wiki, then yes, that is predominantly a Lazarus support area. The FCL packages normally included example projects too, or unit tests. Both are handy for leaning usage of packages.

fpWeb —and all the gems of FCL— do really need proper and complete documentations.

Granted, not all FCL packages are document, but those that are, and the rest of FPC's documentation is excellent. As Michael mentioned, there is a library of technical articles too - those are very useful. And if all else fails, don't hesitate to ask here. Excellent advise can be had here.

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
Mr Bee
to Michael Van Canneyt: I develop using fpweb all the time, without RAD, so I know this works :-) There are over…

Pada Rabu, 8 Juni 2016 15:59, Michael Van Canneyt menulis:

I develop using fpweb all the time, without RAD, so I know this works :-)

Of course you do. You are the main author of fpWeb, after all. :) It's me who didn't know how to do it due the lack of documentation.

There are over 1000 units. There is only 1 documenter…

I know. You're our hero, Michael. Your work on documentations are really helpfull. Thank you very much.

On http://www.freepascal.org/~michael/articles/ you can find some articles that explain the workings of fcl-web. See web1, web2.

I'll save the link. This is a treasure.
Thank you.

Regards,
-Mr Bee

leledumbo
to Michael Van Canneyt: I develop using fpweb all the time, without RAD, so I know this works :-) There are over…
On http://www.freepascal.org/~michael/articles/ you can find some articles that explain the workings of fcl-web. See web1, web2.

WOW! You never said you did document for many things we don't know how to use properly yet. Must be put somewhere everyone else can see, Lazarus wiki would be good. Are you OK if I do that?

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Writing-fpWeb-app-without-Lazarus-tp5725431p5725446.html Sent from the Free Pascal - General mailing list .