Solved

Saving HTML form from download

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Memory leak using records in a TVirtualStringTree 11 109
ddeman not working in activex 3 93
Delphi application Soap connection 5 96
Dev Express grid collapse 2 39
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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