Solved

Save webbrowser component containing ONLY text as a text file (500 points)

Posted on 2006-10-24
4
251 Views
Last Modified: 2010-04-05
I  have the webbrowser component displaying the result of a cgi script - just text without any images, etc.

I want this to be saved automatically as a text file in a specific directory (ie, saved as aaa.txt in a directory called "files" which I already have in the same directory as the software).

I am using Delphi 6.  This is URGENT so I am awarding 500 points for this.  Thanks.
0
Comment
Question by:rincewind666
[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
4 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 250 total points
ID: 17794314
this works for anything from the twebrowser (text or html)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    procedure FormCreate(Sender: TObject);
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses activex;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WebBrowser1.Navigate('http://www.ciuly.com');
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
  PersistStreamInit: IPersistStreamInit;
  StreamAdapter: IStream;
  FileStream: TFileStream;
begin
  if WebBrowser1.Document.QueryInterface(IPersistStreamInit,
    PersistStreamInit) = S_OK then
  begin
      FileStream:= TFileStream.Create('c:\aaa.txt',fmCreate);
      try
        StreamAdapter:= TStreamAdapter.Create(FileStream, soOwned);
        PersistStreamInit.Save(StreamAdapter,true);
      except
        FileStream.Free;
        raise;
      end;
  end;
end;

end.
0
 
LVL 28

Expert Comment

by:2266180
ID: 17794318
ups. forgot to remove the test page. sorry for that.
0
 
LVL 28

Assisted Solution

by:TName
TName earned 250 total points
ID: 17794384
Hi, ciuly's solution is perfect, but here's another way to do it (now that I've typed it... ;)

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
var
 aText:String;
 fs:TFileStream;
 p:Pointer;
begin
  aText:=IHTMLDocument2(WebBrowser1.Document).Body.innerText;
  fs:=TFileStream.Create(ExtractFilePath(Paramstr(0))+'files\aaa.txt',fmCreate);
  p:=pointer(aText);
  fs.Write(p^, Length(aText));
  fs.Free;
end;
0
 

Author Comment

by:rincewind666
ID: 17798662
Thanks to both of you. Both work - hard to decide.  Therefore I will split the points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

623 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