Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Post an HTML document 1

Status
Not open for further replies.

WayneStev

Programmer
Jan 3, 2006
21
US
How do I post an HTML document (as html source) from TWebBrowser to a control like memo or rich edit in the form of html source code I have tried sever suggestions but none of the seem to dor the job. I am using Delphi 7.0? Any HELP please.

 
It simply did not work. I thought that it would work also logicaly it looked ok. Just did not work... To recap the program that I am developeing is a brouser that will post the standard web page on an other pannal I need to post the same page as the html source don't post.
 
Of course it works!

What problem are you having with it?

buho (A).
 
Well For some resion the html source code don't show up in the source window or I am using the memo control that you suggested.. Logicaly the code should work but it is not for me... I wish thair would be some way I could get yoy the relative code... Thes try this this is the relative code :

unit Main;

interface

uses Windows, Classes, Graphics, Forms, Controls, Menus,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, ImgList, StdActns,
ActnList, ToolWin, OleCtrls, SHDocVw, Grids, MSHTML_TLB;

type
TfrmMain = class(TForm)
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
ToolBar1: TToolBar;
ToolButton9: TToolButton;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ActionList1: TActionList;
FileNew1: TAction;
FileOpen1: TAction;
FileSave1: TAction;
FileSaveAs1: TAction;
FileExit1: TAction;
EditCut1: TEditCut;
EditCopy1: TEditCopy;
EditPaste1: TEditPaste;
HelpAbout1: TAction;
StatusBar: TStatusBar;
ImageList1: TImageList;
MainMenu1: TMainMenu;
File1: TMenuItem;
FileOpenItem: TMenuItem;
FileSaveItem: TMenuItem;
FileSaveAsItem: TMenuItem;
N1: TMenuItem;
FileExitItem: TMenuItem;
Edit1: TMenuItem;
CutItem: TMenuItem;
CopyItem: TMenuItem;
PasteItem: TMenuItem;
Help1: TMenuItem;
HelpAboutItem: TMenuItem;
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Splitter1: TSplitter;
cbURL: TComboBox;
cmdGo: TSpeedButton;
pcView: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
tabNotes: TTabSheet;
RENotes: TRichEdit;
ImageList2: TImageList;
cmdBack: TSpeedButton;
cmdStop: TSpeedButton;
cmdForward: TSpeedButton;
cmdHome: TSpeedButton;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
gedHistory: TStringGrid;
grpBookMark: TStringGrid;
RESource: TRichEdit;
Panel4: TPanel;
Panel5: TPanel;
cmdBookMark: TBitBtn;
Panel6: TPanel;
Splitter2: TSplitter;
REScreen: TRichEdit;
Panel7: TPanel;
cmdNotSave: TButton;
cmdSourceSave: TButton;
cmdClearHTML: TButton;
cmdScriptSave: TButton;
cmdLoadScript: TButton;
cmdRunScript: TButton;
cmdClearScript: TButton;
cmdClearNotes: TButton;
cmdLoadNotes: TButton;
webb: TWebBrowser;
Scriptlet1: TScriptlet;
reHTMLSource: TMemo;
procedure FileNew1Execute(Sender: TObject);
procedure FileOpen1Execute(Sender: TObject);
procedure FileSave1Execute(Sender: TObject);
procedure FileExit1Execute(Sender: TObject);
procedure HelpAbout1Execute(Sender: TObject);
procedure cmdGoClick(Sender: TObject);
procedure Source1Click(Sender: TObject);
procedure cmdBackClick(Sender: TObject);
procedure cmdStopClick(Sender: TObject);
procedure cmdForwardClick(Sender: TObject);
procedure cmdHomeClick(Sender: TObject);
procedure webbTitleChange(Sender: TObject; const Text: WideString);
procedure cmdBookMarkClick(Sender: TObject);
procedure gedHistorySelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure grpBookMarkSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure cmdNotSaveClick(Sender: TObject);
procedure cmdScriptSaveClick(Sender: TObject);
procedure cmdLoadNotesClick(Sender: TObject);
procedure cmdClearNotesClick(Sender: TObject);
procedure cmdLoadScriptClick(Sender: TObject);
procedure cmdClearScriptClick(Sender: TObject);
procedure cmdRunScriptClick(Sender: TObject);
procedure cmdClearHTMLClick(Sender: TObject);
procedure cmdSourceSaveClick(Sender: TObject);
//procedure webbNavigateComplete2(Sender: TObject;
// const pDisp: IDispatch; var URL: OleVariant);

private
{ Private declarations }
public
{ Public declarations }
end;

var
frmMain: TfrmMain;

implementation

uses about;

{$R *.dfm}
//*************************************************

procedure GetHtml;
var
iall : IHTMLElement;
begin
if Assigned(frmMain.webb.Document) then
begin
iall :=(frmMain.webb.Document AS IHTMLDocument2).body;
while iall.parentElement <> nil do
begin
iall := iall.parentElement;
end;
frmMain.reHTMLSource.Text := iall.outerHTML;
end;
end;


If you need more let me know.
 
Well, I used this piece of code myself to get html sourcecodes:

Requires component TidHTTP:

procedure GetHTMLSource(thisSite: string);
var SS: TStringStream;
begin
SS := TStringStream.Create('');
idHTTP1.Get(thisSite,SS);
Memo1.Text := SS.DataString;
end;

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
Got it ! First time you helped me you did not suggest using that made all the differance. One though for some resion don't show the compleat page just the header, body no html in the body.. Must be something I let out. I think I can take from this point... Thanks so much for you help.
 
1) This is not the code I posted.

2) It works too.

3) From where and when are you calling your GetHTML procedure?

buho (A).
 
Probably your problem is where and when you are calling the procedure.

You need to be sure you are synchronized with the browser (the doc being not nil is not the same as the doc being fully loaded and processed) and you need to decide what you want to do with the pages having frames.

In my example I used the DocCompleted function to wait for the frames completion and show the frameset page. If you want to show the frame pages individually you need to call the procedure every time the OnDocumentCompleted fires, whitout making the DocCompleted check I've used.

Don't forget the "while Browser.Busy do Sleep(xx);" line, it can save you some headaches, depending on what the exact IE version and build is in the machine.

buho (A).

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top