Solved

Saving HTML form from download

Posted on 2001-08-08
2
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month7 days, 9 hours left to enroll

632 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