Link to home
Start Free TrialLog in
Avatar of SHAHEEN_AKHTAR
SHAHEEN_AKHTARFlag for India

asked on

TWebBrowser Unicode characters as Question Marks ??????

I am getting titles from rssfeed and displaying them in a marquee in TWebBrowse control. But the titles are displayed as question marks. Look at my complete code.

WebBrowser is Navigated to Blank Page.
Downloads the RssFeed and Extract titles.
Write the HTML to WebBrowser.

Is there any string manipulation required to deal with unicode chars.
Even I tried Passing the titles to TMSUnicode Edit control. TMS Edit gets the string correctly and the same text is passed to WebBrowser. Kindly help me please. You may use the rssfeed link I am using in my code.

Thanks a lot.


procedure TRaftaar.GetHeadLines;
var
    newsxml: string;  ItemNode:IXMLNode;title:widestring; I:integer;
    nodelist:IXMLNodeList; html:widestring; link:widestring;
 
begin
  html := '<html><body scroll=no><marquee WIDTH=100% BEHAVIOR=SCROLL DIRECTION=left scrollamount=2 BGColor=yellow onmouseover=stop(); onmouseout=start();>';
 
  newsxml := IdHttp1.Get('http://www.raftaar.com/feeds/Home_News.xml');
  xmldocument1.XML.Text := newsxml;
  xmldocument1.Active := True;
  nodelist := xmldocument1.DocumentElement.ChildNodes.First.ChildNodes;
  for I:=0 to nodelist.Count-1 do
  begin
    ItemNode := nodelist[i];
    if ItemNode.NodeName='item' then
    begin
      title := itemnode.ChildNodes['title'].Text;
      link:=   itemnode.ChildNodes['link'].Text;
      html:= html+'<a name='+link+' href=#>'+title+'</a>&nbsp&nbsp||&nbsp&nbsp';
    end;
 
  end;
  html:= html+'</marquee></body></html>';
  WbNavBlank;
  LoadHtml(html,WebBrowser1);
  WbHideScrollBar(WebBrowser1);
  xmldocument1.Active := False;
end;
 
 
procedure TRaftaar.LoadHtml(html: string; WB:TWebBrowser);
   var IDoc: IHTMLDocument2;  v: OleVariant;
begin
  IDoc := WebBrowser1.Document as  IHTMLDocument2;
  v := VarArrayCreate([0, 0], varVariant);
  v[0] := html;
  IDoc.Write(PSafeArray(TVarData(v).VArray));
  IDoc.Close;
  IDoc.body.style.marginTop := -1;
  //IDoc.body.style.backgroundColor := 'Red';
  WbHideScrollBar(WebBrowser1);
  BindAnchors(IDoc);
 
end;.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JustScreenShot
JustScreenShot

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SHAHEEN_AKHTAR

ASKER

Already tried that. But all question marks displayed. I am getting the output HTML correctly. I append the HTML below:-

I think there is some thing to do with the TWebBrowser or IHTMLDocument2 Character set. I am trying that and come back.

Thanks


'<html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body scroll=no><marquee WIDTH=100% BEHAVIOR=SCROLL DIRECTION=left scrollamount=2 BGColor=yellow onmouseover=stop(); onmouseout=start();><a name=http://www.raftaar.com/IndexI.aspx?__EVENTTARGET=main&__EVENTARGUMENT=%E0%A4%97%E0%A4%82%E0%A4%97%E0%A4%BE%20%E0%A4%95%E0%A5%8B%20%E0%A4%B2%E0%A5%87%E0%A4%95%E0%A4%B0%20%E0%A4%85%E0%A4%A8%E0%A4%B6%E0%A4%A8%20%E0%A4%86%E0%A4%9C~1~IE~web~~hi~web~~~~news href=#>> K 2G0 (6( </a>&nbsp&nbsp||&nbsp&nbsp<a name=http://www.raftaar.com/IndexI.aspx?__EVENTTARGET=main&__EVENTARGUMENT=%E0%A4%97%E0%A5%80%E0%A4%A4%E0%A4%BE%20%E0%A4%B0%E0%A4%BE%E0%A4%AE%E0%A4%BE%E0%A4%AF%E0%A4%A3%20%E0%A4%94%E0%A4%B0%20%E0%A4%AA%E0%A5%81%E0%A4%B0%E0%A4%BE%E0%A4%A3%20%E0%A4%A4%E0%A4%BE%E0%A4%AE%E0%A5%8D%E0%A4%B0%E0%A4%AA%E0%A4%A4%E0%A5%8D%E0%A4%B0%20%E0%A4%AA%E0%A4%B0~1~IE~web~~hi~web~~~~news href=#>@$> 0>.>/# 0 *A0># $>.M0*$M0 *0</a>&nbsp&nbsp||&nbsp&nbsp<a name=http://www.raftaar.com/IndexI.aspx?__EVENTTARGET=main&__EVENTARGUMENT=%E0%A4%87%E0%A4%9F%E0%A4%B2%E0%A5%80%20%E0%A4%95%E0%A5%8B%20%E0%A4%B9%E0%A4%B0%E0%A4%BE%E0%A4%95%E0%A4%B0%20%E0%A4%B8%E0%A5%8D%E0%A4%AA%E0%A5%87%E0%A4%A8%20%E0%A4%B8%E0%A5%87%E0%A4%AE%E0%A5%80%E0%A4%AB%E0%A4%BC%E0%A4%BE%E0%A4%87%E0%A4%A8%E0%A4%B2%20%E0%A4%AE%E0%A5%87%E0%A4%82~1~IE~web~~hi~web~~~~news href=#>2@ K 90>0 8M*G( 8G.@+<>(2 .G</a>&nbsp&nbsp||&nbsp&nbsp<a name=http://www.raftaar.com/IndexI.aspx?__EVENTTARGET=main&__EVENTARGUMENT=%E0%A4%9C%E0%A4%B9%E0%A4%BE%E0%A4%9C%E0%A4%BC%20%E0%A4%95%E0%A5%87%2028%20%E0%A4%AF%E0%A4%BE%E0%A4%A4%E0%A5%8D%E0%A4%B0%E0%A5%80%20%E0%A4%9C%E0%A5%80%E0%A4%B5%E0%A4%BF%E0%A4%A4%20%E0%A4%AE%E0%A4%BF%E0%A4%B2%E0%A5%87~1~IE~web~~hi~web~~~~news href=#>9>< G 28 />$M0@ @5?$ .?2G</a>&nbsp&nbsp||&nbsp&nbsp</marquee></body></html>

Open in new window

It was my fault. In the Load HTML function I was passing the HTML in a string variable instead of widestring. Changing it to widestring solved the problem. Thanks