• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

how can I load a html file into a WebBrowser?

Thks
0
hidrau
Asked:
hidrau
4 Solutions
 
Scay7Commented:
You must include ShellAPI in your uses

Then call
  var myhttp : string;
  myhttp := ExtractFilePath(Application.ExeName) + 'MyFile.html'
  ShellExecute(Application.handle,nil,'myhttp',nil,nil,SW_SHOWNORMAL);

this will get the DIR of where ever the application is stored and add whatever http file you want and launch it with the default browser...

Peace Scay7
0
 
Eddie ShipmanAll-around developerCommented:
Here is code to load an HTML file directly into a TWebBrowser:

uses  ...,mshtml, ActiveX, ComObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  IDoc:      IHTMLDocument2;
  Strl:      TStringList;
  v:         Variant;
begin
  WebBrowser1.Navigate('about:blank');
  if OpenDialog1.Execute then
  begin
    Strl := TStringList.Create;
    try
      Strl.LoadFromFile(OpenDialog1.FileName);
      Idoc:=WebBrowser1.Document as IHTMLDocument2;
      try
        IDoc.designMode:='on';
        while IDoc.readyState<>'complete' do
          Application.ProcessMessages;
        v:=VarArrayCreate([0,0],VarVariant);
        v[0]:= Strl.Text;
        IDoc.write(PSafeArray(System.TVarData(v).VArray));
        IDoc.designMode:='off';
        while IDoc.readyState<>'complete' do
          Application.ProcessMessages;
      finally
        IDoc := nil;
      end;
    finally
      Strl.Free;
    end;
  end;
end;
0
 
TheRealLokiSenior DeveloperCommented:
isn't it just
var
    Flags: OLEVariant;
..
    WebBrowser1.Navigate(WideString('c:\temp\mywebpage.html'), Flags, Flags, Flags, Flags);
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now