Recent

Author Topic: Help with FreeSpider Web Page builder  (Read 7918 times)

tjpren

  • Jr. Member
  • **
  • Posts: 67
Help with FreeSpider Web Page builder
« on: December 21, 2011, 08:35:05 am »
Hi Forum,

I'm now looking to develop a web application with lazarus, and am trying FreeSpider.

I've tried putting the example Freespider.exe in the cgi-bin directory of IIS, Apache, and TinyWeberServer.  In all of them, I can get the first screen to show up, but not the secondary screens (eg Hello world).

All I get is the Http 404 error (page cannot be found).

The application seems to compile correctly.

I am using Laz ver 0.9.3.0, and FPC 2.4.2

Any thoughts?

Regards  :)

jamhitz

  • Jr. Member
  • **
  • Posts: 83
Re: Help with FreeSpider Web Page builder
« Reply #1 on: December 22, 2011, 02:20:01 pm »
Works for me. This is a simplified sample of how I did it.

Start off with the first demo in the official documentation (http://code.sd/freespider.pdf). Make sure you can get as far as getting a response from http://localhost/cgi-bin/first

Create your html documents (mine are info.html:

Code: [Select]
<html></head><title>Info</title></head><body>
<h1>Information</h1>
<p>You are logged in as @user;</p>
</body></html>

...and about.html):

Code: [Select]
<html></head><title>About Us</title></head><body>
<h1>About Us</h1>
<p>You are logged in as @user;</p>
<br>
<p>Generated on: @date;</p>
</body></html>

On the data module, add two TSpiderPage components assigning them different PathFileName to the respective file. Mine were:

Code: [Select]
Name: pgInfo
PageFileName: info.html

Name: pgAbout
PageFileName: pgAbout.html

And assign then these event handlers:

Code: [Select]
procedure TDataModule1.pgAboutTag(Sender: TObject; ATag: string; var TagReplacement: string);
begin
    if aTag = 'user' then
        TagReplacement := 'FreePascal User'
    else if aTag = 'date' then
        TagReplacement := FormatDateTime('dd MMMM yyyy', Date());
end;

procedure TDataModule1.pgInfoTag(Sender: TObject; ATag: string; var TagReplacement: string);
begin
    if aTag = 'user' then TagReplacement := 'FreePascal User';
end; 

Also, add two TSpiderAction components acInfo (path = /info) and acAbout (path = /about) and add the following event handlers to the OnRequest handlers:

Code: [Select]
procedure TDataModule1.acInfoRequest(Sender: TObject; Request: TSpiderRequest; var Response: TSpiderResponse);
begin
    Response.Add(pgInfo.Contents);
end; 

procedure TDataModule1.acAboutRequest(Sender: TObject; Request: TSpiderRequest; var Response: TSpiderResponse);
begin
    Response.Add(pgAbout.Contents);
end;

That's it. You can access the two pages as http://localhost/cgi-bin/first/about and http://localhost/cgi-bin/first/info respectively.

Good luck!
« Last Edit: December 22, 2011, 02:23:58 pm by jamhitz »

tjpren

  • Jr. Member
  • **
  • Posts: 67
Re: Help with FreeSpider Web Page builder
« Reply #2 on: January 02, 2012, 12:01:40 pm »
Hi,

Thanks - I've managed to get it working - I quite like it.

It took some googling to get IIS and Apache working with cgi-bin.  A useful tutorial is at:
http://www.chromicdesign.com/2009/05/setting-up-perl-for-wampp.html

I then set about modifying the freeSpider example, and jamhitz code to make a test.

Now, I'm wondering if there is any documentation on the TMemdataset.  The Freespider example connects to a sub.dat.  I'm wondering if it could connect to a text file, or an access database; and if so how?  I couldn't find a link to any examples of the TMemdataset.

Regards


Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Help with FreeSpider Web Page builder
« Reply #3 on: January 03, 2012, 02:52:06 am »
Quote
I'm wondering if it could connect to a text file, or an access database; and if so how?
You can still use everything that Object Pascal has, so is database connectivity. Search the wiki.

tjpren

  • Jr. Member
  • **
  • Posts: 67
Re: Help with FreeSpider Web Page builder
« Reply #4 on: January 03, 2012, 08:37:27 am »
Hello,

Yes I saw the wiki, but it didn't help me sufficiently.

The following code from the WebSpider example works fine:

Code: [Select]
procedure TDataModule1.SpiderPage1Tag(Sender: TObject; ATag: string;
  var TagReplacement: string);
begin
  if ATag = 'time' then
    TagReplacement:= DateTimeToStr(Now)
  else
  if ATag = 'table' then
  begin
    if FileExists('sub.dat') then
      MemDataset1.LoadFromFile('sub.dat');
    MemDataset1.Open;
    MemDataset1.FieldByName('SubName').DisplayLabel:= 'Name';
    MemDataset1.FieldByName('Address').Visible:= False;
    TagReplacement:= SpiderTable2.Contents;
  end
  else
  if ATag = 'home' then
    TagReplacement:= '<a href="./">Main</a>'
  else
  if ATag = 'month' then
    TagReplacement:= FormatDateTime('mmm', Now)
  else
  if ATag = 'year' then
    TagReplacement:= FormatDateTime('yyyy', Now);
end;                               

But if I try exactly the same code with - say a text or csv file - I get an error in the web page.

"Wrong data stream marker at position 0. Got 33648643, expected 1".

I think it has something to do with the format of the data, and the way the MemDataset reads the data.

Any thoughts?

Regards


Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Help with FreeSpider Web Page builder
« Reply #5 on: January 03, 2012, 09:52:33 am »
Have you seen this page?

tjpren

  • Jr. Member
  • **
  • Posts: 67
Re: Help with FreeSpider Web Page builder
« Reply #6 on: January 03, 2012, 10:37:27 am »
Hello Leledumbo,

Yes I did, but it was sufficiently different to the example, I could see the connection.  I note that the link shows memdataset loading from a csv, but any csv, or txt I create gives me an error.  The only thing that loads is the .dat file that was originally created in the application.

I've been trying to see what sort of flat file the .dat file is, and what 3rd party app might create it the hope that I can see what the record structures are like.

My ultimate aim is to create flat files, and read from them to a web page using the freespider.  My stumbling block is that the example has:
       
Code: [Select]
MemDataset1.LoadFromFile('sub.dat');and I'd like to use something like
Code: [Select]
MemDataset1.LoadFromFile('sub.txt');

tjpren

  • Jr. Member
  • **
  • Posts: 67
[Solved] Re: Help with FreeSpider Web Page builder
« Reply #7 on: January 04, 2012, 09:23:37 am »
Hello all,

I've had success - couldn't get memdataset working.  I couldn't find what the format of the data was, so I changed to a Dbf data set.  Hardly any code change, and it worked.  The web page displays the contents of a standard dbf file - brilliant!!.


Code: [Select]
procedure TDataModule1.SpiderPage1Tag(Sender: TObject; ATag: string;
  var TagReplacement: string);
begin
  if ATag = 'time' then
    TagReplacement:= DateTimeToStr(Now)
  else
  if ATag = 'table' then
  begin
    if FileExists('test.dbf') then
    Dbf1.TableName:= 'test.dbf';
    Dbf1.Open;

    TagReplacement:= SpiderTable2.Contents;
  end
  else
  if ATag = 'home' then
    TagReplacement:= '<a href="./">Main</a>'
  else
  if ATag = 'month' then
    TagReplacement:= FormatDateTime('mmm', Now)
  else
  if ATag = 'year' then
    TagReplacement:= FormatDateTime('yyyy', Now);
end;   

 

TinyPortal © 2005-2018