Solved

Saving HTML form from download

Posted on 2001-08-08
2
291 Views
Last Modified: 2010-04-06
               Hi All,
                 I have the following program that I want to save the HTML page itself. Below are
                 2 lines commented that are in the place of the actual lines of code:
                 
                  //Memo1.Text:= Doc;
                  //Memo1.Lines.SaveToFile(ExtractFilePath(Application.exeName) + 'HTMLView' + '.htm');

                 If I uncomment these 2 lines the program
                 does not get the desired 'HTMLView' + '.htm'.

                 Can you suggest some correction?


                 unit GetWebBrowserUnit1;

                 interface

                 uses
                  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, activeX,
                  StdCtrls, OleCtrls, SHDocVw_TLB;

                 type
                  TForm1 = class(TForm)
                    Memo1: TMemo;
                    Button1: TButton;
                    WebBrowser_V11: TWebBrowser_V1;
                    Button2: TButton;
                    Label1: TLabel;
                    Label2: TLabel;
                    Edit1: TEdit;
                    URL: TLabel;
                    SaveDialog1: TSaveDialog;
                    Label3: TLabel;
                    Edit2: TEdit;
                    procedure Button1Click(Sender: TObject);
                    procedure FormShow(Sender: TObject);
                    procedure Button2Click(Sender: TObject);
                  private
                                    { Private declarations }
                  public
                                    { Public declarations }
                  end;

                 var
                  Form1: TForm1;

                 implementation

                 {$R *.DFM}

                 procedure TForm1.Button1Click(Sender: TObject);
                 var
                  Doc, V, Bod: OleVariant;
                  I1, I, X: integer;
                 begin
                  webBrowser_V11.navigate(Edit1.Text, V, V, V, V);
                  while webBrowser_V11.busy do
                    application.processMessages;
                  Doc := webBrowser_V11.Document;
                  Bod := Doc.Body;

                  //Memo1.text:= Doc;
                  //Memo1.Lines.SaveToFile(ExtractFilePath(Application.exeName) + 'HTMLView' + '.htm');
                  Memo1.Text := Bod.InnerText;

                  with TFileStream.Create(ExtractFilePath(Application.exeName) + 'TextSavedSeenInView' + '.txt', fmCreate)
                 do
                  try
                    I := 0;
                    X := Memo1.Lines.Count;
                    while I < X do
                    begin
                      Memo1.Lines[I];
                      I1 := Length(Memo1.Lines[I]);
                      Write(Pointer(Memo1.Lines[I])^, I1);
                      Inc(I);
                    end;
                  finally free end;
                 end;


                 procedure TForm1.FormShow(Sender: TObject);
                 begin
                  Edit1.Text := 'http://users.swing.be/francois.piette/wsocketu.htm';
                  Edit2.Text := 'View1.html';
                 end;

                 procedure TForm1.Button2Click(Sender: TObject);
                 begin
                  Application.Terminate;
                 end;

                 end.


                 Delphi3
0
Comment
Question by:delphi3
2 Comments
 
LVL 6

Accepted Solution

by:
edey earned 50 total points
ID: 6365060
I'd try changing:

                 //Memo1.text:= Doc;
                 //Memo1.Lines.SaveToFile(ExtractFilePath(Application.exeName) + 'HTMLView' + '.htm');
                 Memo1.Text := Bod.InnerText;

                 with TFileStream.Create(ExtractFilePath(Application.exeName) + 'TextSavedSeenInView'
+ '.txt', fmCreate)
                do
                 try
                   I := 0;
                   X := Memo1.Lines.Count;
                   while I < X do
                   begin
                     Memo1.Lines[I];
                     I1 := Length(Memo1.Lines[I]);
                     Write(Pointer(Memo1.Lines[I])^, I1);
                     Inc(I);
                   end;
                 finally free end;
                end;

To:

                 Memo1.text := bod.innerHTML;
                 Memo1.Lines.SaveToFile(ExtractFilePath(Application.exeName) + 'HTMLView' + '.htm');
                 Memo1.lines.saveToFile(ExtractFilePath(Application.exeName) + 'TextSavedSeenInView'
+ '.txt', fmCreate);


GL
Mike
0
 
LVL 4

Author Comment

by:delphi3
ID: 6365719
Mike,
Thanks for your efforts to  respond again to another Q of mine.
When doing ActiveX  programming, I cannot reference my D4 help  for programming hints and there
are no auto appearing prompts for selections of what is available.

This time I wanted to get the HTML page and then the page with the text only. That way I can
use  both in various ways.

I modified your suggestions to get what I needed.

procedure TForm1.Button1Click(Sender: TObject);
var
  Doc, V, Bod: OleVariant;
begin
  webBrowser_V11.Navigate(Edit1.Text, V, V, V, V);
  while webBrowser_V11.Busy do
    Application.ProcessMessages;
  Doc := webBrowser_V11.Document;
  Bod := Doc.Body;

  Memo1.Text := Bod.InnerHTML;
  Memo1.Lines.SaveToFile(ExtractFilePath(Application.exeName) + 'HTMLView' + '.htm');

  Memo1.Clear;
  Memo1.Text := Bod.InnerText;

  Memo1.Lines.SaveToFile(ExtractFilePath(Application.exeName) + 'TextSavedSeenInView' + '.txt');
  // Changed this method to SaveToFile

end;

Thanks so much
Delphi3
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now