Re: [twsocket] HtmlPageProducerToString in Delphi XE
Hello Péter, Thanks for your help. I have updated the source code as follow. Please check if this works for you before I commit the change to the repository. function THttpConnection.HtmlPageProducerToString( const HtmlFile : String; UserData : TObject; Tags : array of const) : String; var Stream : TMemoryStream; const NulByte : Byte = 0; begin Stream := TMemoryStream.Create; try HtmlPageProducerToStream(HtmlFile, UserData, Tags, Stream); {$IFDEf COMPILER12_UP} // For unicode char compiler (D2009 and up) // Add a nul byte at the end of string Stream.Write(NulByte, 1); Result := String(PAnsiChar(Stream.Memory)); {$ELSE} // For ansi char compiler SetLength(Result, Stream.Size); Stream.Seek(0, 0); Stream.Read(Result[1], Stream.Size); {$ENDIF} finally Stream.Free; end; end; -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be - Original Message - From: Busai Péter busai...@t-online.hu To: ICS support mailing twsocket@elists.org Sent: Monday, January 24, 2011 9:24 PM Subject: Re: [twsocket] HtmlPageProducerToString in Delphi XE One possible solution, I defined a temporary RawByteString and now it returns correct result. I have tested it on DelphiXE and BDS2006. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} function THttpConnection.HtmlPageProducerToString( const HtmlFile : String; UserData : TObject; Tags : array of const) : String; var Stream : TMemoryStream; {$IFDEF COMPILER12_UP} S : RawByteString; {$ELSE} S : String; {$END} begin Stream := TMemoryStream.Create; try HtmlPageProducerToStream(HtmlFile, UserData, Tags, Stream); SetLength(S, Stream.Size); Stream.Seek(0, 0); Stream.Read(S[1], Stream.Size); Result := S; finally Stream.Free; end; end; Regards Peter A(z) kimenő üzenetben nem található vírus. Ellenőrizte: AVG - www.avg.com Verzió: 9.0.872 / Vírus adatbázis: 271.1.1/3400 - Kiadás dátuma: 01/24/11 08:35:00 -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] HtmlPageProducerToString in Delphi XE
For a fast workaround now I use TStringStream HeaderStream := TStringStream.Create; try Client.HtmlPageProducerToStream('header.html',nil,[ 'LOCATION', SessionData.Referer, 'ISADMIN',IfThen(SessionData.IsAdmin,'','style=display:none;') ],HeaderStream); AnswerPage('','','home.html',nil,[ 'HEADER',UTF8Encode(HeaderStream.DataString) ... Peter 2011.01.24. 18:42 keltezéssel, Busai Péter írta: Hi, I have problem using the above function in unicode compiler Just tried to include a content of a file to servertime document The content of header.html: div id=header Some headerline 1/br Some headerline 2/br Some headerline 3/br /div and the result is: HTMLHEADTITLEICS WebServer Demo/TITLE/HEAD BODY eaderline 2/br Some headerline 3/br /div H2Time at server side:/H2 P2011.01.24. 18:35:17/P A HREF=/demo.htmlDemo menu/A /BODY/HTML {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { This procedure is use to generate /time.html document } procedure TWebServForm.CreateVirtualDocument_Time( Sender: TObject;{ HTTP server component } ClientCnx : TMyHttpConnection; { Client connection issuing command } var Flags : THttpGetFlag); { Tells what HTTP server has to do next } var HeaderString:String; begin HeaderString := ClientCnx.HtmlPageProducerToString('header.html',nil,[]); ClientCnx.AnswerString(Flags, '',{ Default Status '200 OK'} '',{ Default Content-Type: text/html} 'Pragma: no-cache' + #13#10 + { No client caching please } 'Expires: -1' + #13#10, { I said: no caching ! } 'HTML' + 'HEAD' + 'TITLEICS WebServer Demo/TITLE' + '/HEAD' + #13#10 + 'BODY' + HeaderString + 'H2Time at server side:/H2' + #13#10 + 'P' + DateTimeToStr(Now) +'/P' + #13#10 + 'A HREF=/demo.htmlDemo menu/A' + #13#10 + '/BODY' + '/HTML'); end; {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} function THttpConnection.HtmlPageProducerToString( const HtmlFile : String; UserData : TObject; Tags : array of const) : String; var Stream : TMemoryStream; begin Stream := TMemoryStream.Create; try HtmlPageProducerToStream(HtmlFile, UserData, Tags, Stream); SetLength(Result, Stream.Size); Stream.Seek(0, 0); If I save the stream to a file: Stream.SaveToFile('teszt.html') the file contains the expected data. Stream.Read(Result[1], Stream.Size); Here Result contains garbage. finally Stream.Free; end; end; Regards Peter -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be A(z) bejövő üzenetben nem található vírus. Ellenőrizte: AVG - www.avg.com Verzió: 9.0.872 / Vírus adatbázis: 271.1.1/3400 - Kiadás dátuma: 01/24/11 08:35:00 A(z) kimenő üzenetben nem található vírus. Ellenőrizte: AVG - www.avg.com Verzió: 9.0.872 / Vírus adatbázis: 271.1.1/3400 - Kiadás dátuma: 01/24/11 08:35:00 -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] HtmlPageProducerToString in Delphi XE
One possible solution, I defined a temporary RawByteString and now it returns correct result. I have tested it on DelphiXE and BDS2006. {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} function THttpConnection.HtmlPageProducerToString( const HtmlFile : String; UserData : TObject; Tags : array of const) : String; var Stream : TMemoryStream; {$IFDEF COMPILER12_UP} S : RawByteString; {$ELSE} S : String; {$END} begin Stream := TMemoryStream.Create; try HtmlPageProducerToStream(HtmlFile, UserData, Tags, Stream); SetLength(S, Stream.Size); Stream.Seek(0, 0); Stream.Read(S[1], Stream.Size); Result := S; finally Stream.Free; end; end; Regards Peter A(z) kimenő üzenetben nem található vírus. Ellenőrizte: AVG - www.avg.com Verzió: 9.0.872 / Vírus adatbázis: 271.1.1/3400 - Kiadás dátuma: 01/24/11 08:35:00 -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be