Solved

Saving HTML form from download

Posted on 2001-08-08
2
298 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

15 Experts available now in Live!

Get 1:1 Help Now