Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Saving HTML form from download

Posted on 2001-08-08
2
Medium Priority
?
327 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 200 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

688 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