Acess Resources in Post scripting

A forum about working with web publishing templates

Moderator: moderators

Acess Resources in Post scripting

Postby dodgetigger » 12 Jun 10 11:04

I am working on a new template, and I would like to copy a resource from the script resources to the publish folder in the post script.
This is basically my code:
Code: Select all
var
    AResource: THTMLResource;
    MyApp: WideString;
begin
  AResource := FindScriptResource ('MyResource');
  AResource.Save(Publisher.PublishFolder + 'work.exe');


The file is created, but only with 0 bytes.
What am I doing wrong here?
User avatar
dodgetigger
 
Posts: 205
Joined: 27 Feb 06 0:30
Location: Kirchheim, Germany

Re: Acess Resources in Post scripting

Postby Hert/IDimager » 14 Jun 10 11:18

Dt,

Is the resource found? Have you tried a check is the returned value is nil or not?

Hert
V5.0.7 is released....Spread the word!!
if you need additional resources
find some great IDimager tutorials here (still experimental)
visit the IDimager wiki
join us at Facebook
follow us on Twitter
User avatar
Hert/IDimager
Site Admin
 
Posts: 15857
Joined: 13 Sep 03 7:24

Re: Acess Resources in Post scripting

Postby dodgetigger » 16 Jun 10 21:36

Thanks, Hert.

I have now tried this code:
Code: Select all
AResource := FindScriptResource ('MyResource');
if AResource <> nil then
begin
  Say('Resource found');
  AResource.Save(Publisher.PublishFolder + 'work.exe');
end


I get the resource found message, but the file is zero. What I also realized now is that after the call to Save, the script just stops, code afterwards is not executed anymore (If I put a "Say" right behind the Save, I get nothing).
Also, the whole Publish process does not seem to finish correct, I never get the screen where I can choose to upload the result, show it in the browser, etc.
For whatever reason it doesn't like that "Save".

Maybe I would be better off referencing my resources in the HTML, and copy them to the publish root directory?
One resource is a temporary resource that I just need for the publishing process, the other one I need in the publish root directory.
User avatar
dodgetigger
 
Posts: 205
Joined: 27 Feb 06 0:30
Location: Kirchheim, Germany

Re: Acess Resources in Post scripting

Postby DirkS » 16 Jun 10 22:09

What I also realized now is that after the call to Save, the script just stops, code afterwards is not executed anymore (If I put a "Say" right behind the Save, I get nothing).

You could try to catch the error with something like this:

Code: Select all
try
  AResource.Save(Publisher.PublishFolder + 'work.exe')
except
  Say('Exception: ' + LastExceptionMessage);
end;


Gr.
Dirk.
DirkS
moderator
 
Posts: 4010
Joined: 25 May 08 14:28
Location: Warwickshire, UK

Re: Acess Resources in Post scripting

Postby dodgetigger » 17 Jun 10 7:38

Thank you Dirk,

This is the error message when trying to save the Resource:
idi_error_Resource.Save.jpg
Error Message when trying to save a Resource
idi_error_Resource.Save.jpg (20.6 KiB) Viewed 215 times



As a workaround, could I move the Resource file from the Resources folder to the root directory?
There is a MoveFile function on the TImageObject, how about other files?

Edit: Ah, I found it: I have tried "MoveFile", which didn't work. But "RenameFile" is working nicely. Now I just have to remember adding and removing the files in the FTPFileModel, and I think I am good to go :)

Thank you for your help. :)
User avatar
dodgetigger
 
Posts: 205
Joined: 27 Feb 06 0:30
Location: Kirchheim, Germany

Re: Acess Resources in Post scripting

Postby Hert/IDimager » 18 Jun 10 12:44

Hi Dt,

I found this and now fixed it.

In fact the resources aren't direct accessible through the FindScriptResource method, but you should instead use the Publisher.Template.Resources.FindResource (AName: String) method.

I now fixed this and by-passed the FindScriptResource method to the template's resources. That fixed the issue.

Right now you would get a result but that isn't the case. the result stored in your AResource is in fact an unassigned pointer. I also fixed that so that FindScriptResource will return a nil pointer when no handler was specified (as i*was* the case in web publishing; again the next update will do it)

Thank you
Hert
V5.0.7 is released....Spread the word!!
if you need additional resources
find some great IDimager tutorials here (still experimental)
visit the IDimager wiki
join us at Facebook
follow us on Twitter
User avatar
Hert/IDimager
Site Admin
 
Posts: 15857
Joined: 13 Sep 03 7:24

Re: Acess Resources in Post scripting

Postby dodgetigger » 19 Jun 10 12:33

Thanks, Hert, that is nice to here. :)
User avatar
dodgetigger
 
Posts: 205
Joined: 27 Feb 06 0:30
Location: Kirchheim, Germany


Return to Web Publishing and Template Building

Who is online

Users browsing this forum: No registered users and 1 guest

cron