RTC Forums
November 24, 2024, 06:26:31 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Help
Login
Register
RTC Forums
>
Subscription
>
Support
>
Unknown Variable exception when using RtcParse to parse HTML file
Pages: [
1
]
« previous
next »
Print
Author
Topic: Unknown Variable exception when using RtcParse to parse HTML file (Read 4804 times)
kavetu
Newbie
Posts: 20
Unknown Variable exception when using RtcParse to parse HTML file
«
on:
September 26, 2010, 09:15:58 AM »
I am getting an exception when I replace tokens in
my HTML file when using RtcParse. This is the exception I am getting:
raise exception ERtcParse with message
'Unknown Variable: person_name'.
My TRtcDataProvider OnCheckRequest event is coded like this:
procedure TPage_Provider.PageProviderCheckRequest(Sender: TRtcConnection);
var
fname:string;
begin
with TRtcDataServer(Sender) do
begin
fname:=GetFullFileName(Request.FileName);
if (fname<>'') and (File_Exists(fname)) then
begin
Accept;
Request.Info['fname']:=fname;
end;
end;
end;
The OnDataReceived event is coded like this:
procedure TPage_Provider.PageProviderDataReceived(Sender: TRtcConnection);
var
Svr: TRtcDataServer;
page: TRtcParse;
fname: string;
begin
Svr := TrtcDataServer(Sender);
if Svr.Request.Complete then
begin
Svr.Request.Params.AddText(Svr.Read);
fname:=Svr.Request.Info['fname'];
if File_Exists(fname) then
begin
page := TRtcParse.Create(fname);
try
page['person_name'] := 'Manfredt Kavetu';
Svr.Write(page.Output);
finally
page.Free;
end;
end
else
Write;
end;
end;
The person_name token is wrapped in a P tag in my HTML file like this:
<P>The Deeds office has started a scanning effort of all deeds
from 1980 until present. Scan statistics.
Total to date <%person_name%>
</P>
My HTML file references external images and CSS. If I disable the line
page['person_name'] := 'Manfredt Kavetu' in my code (in the OnDataReceived event)
my HTML file is displayed nicely in the Firefox browser.
What am I doing wrong? How can I parse my HTML file and ENSURES the referenced
external images and CSS are included in the file when Outputting the
HTML file with the RtcParse object?
Manfredt Kavetu
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Unknown Variable exception when using RtcParse to parse HTML file
«
Reply #1 on:
September 26, 2010, 12:31:12 PM »
Hi Manfredt,
I have tested the TRtcParse component now in Delphi 7 and Delphi XE with the HTML text and token you have provided below, but could not reproduce the problem you have reported. In other words, it worked without raising any exceptions. It would also be very strange if a HTML tag (like <P>) would break the parser, since its main purpose is to parse HTML files.
If you are using international characters in your template file (are you?), my guess is that you have stored the file in UTF-16, UTF-32 or Unicode format, in which case the TRtcParse component would be unable to find <% and %> tags. If that is the case, you should simply open the template file in Notepad (standard Windows text editor) and save it in "UTF-8" format.
Please let me know if that was it.
Best Regards,
Danijel Tkalcec
Logged
kavetu
Newbie
Posts: 20
Re: Unknown Variable exception when using RtcParse to parse HTML file
«
Reply #2 on:
September 26, 2010, 01:12:15 PM »
Hi Danijel,
Thanks for your reply, indeed that was the problem, my HTML editor specified the HTML file
as unicode, so I replaced
<META http-equiv=Content-Type content="text/html; charset=unicode">
with
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
in the HEAD section of the HTML file as per your suggestion and it works nicely now.
Our RTC Server is solid and has been running for over 30 days without any issue.
We now have about 10 concurrent users. Initially we had a small issue (about a month
ago) than I wrapped all database access in a pool. Thanks a lot Danijel.
Manfredt Kavetu
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Dashboard
-----------------------------
=> General
=> 3rd-Party
=> Quick Start
-----------------------------
Subscription
-----------------------------
=> Support
Loading...