|
Implementing:
ITravelLogStg
IEnumTravelLogEntry
ITravelLogEntry
IETravelLog Component makes it easy to control the session-history (travel
log) in the Webbrowser Control. You don't need to work with the
interfaces directly, since the component has some easy-to-use methods:
| function GetCount(flags: DWORD; out Entries: DWORD): HRESULT;
procedure ClearSession;
procedure EnumerateBack;
procedure EnumerateForward;
procedure Enumerate;
function Connect: Boolean;
function TravelTo(Offset: Integer): HRESULT;
function GetRelativeEntry(Offset: Integer; out Title, Url: string): HRESULT;
function CreateEntry(Offset: Integer; URL, Title: string): HRESULT;
function RemoveEntry(Offset: Integer): HRESULT;
function RemoveEntryByTitle(title: string): HRESULT;
function RemoveEntryByUrl(Url: string): HRESULT;
|
| property OnEntry
|
| Enumerating the travel log (forward and back).
|
| Navigating to specific entries in the travel log.
|
| Deleting and adding entries which meet certain criteria.
|
| Marking an entry in the travel log and then displaying the entry in
red.
|
| Associating properties with entries in the travel log.
|
| Retrieving information about the state of the travel log. For
example, you could show the previous five pages visited.
|
| Setting and retrieving custom data concerning entries in the travel
log through IPropertyBag.
|
Getting Started
function Connect: Boolean;
Use this function to obtain an interface to the
webbrowsers Travel Log. Must often you will connect as soon as a document
is loaded in the browser.
procedure TForm1.FormShow(Sender: TObject);
begin
Embeddedwb1.AssignDocument;
IETravellog1.Connect;
end;
|
If you want to work with ITravelLogStg instead of the
wrapper-component, you can do something like:
var
ISP: IServiceProvider;
Stg : ITravelLogStg;
begin
Result := FALSE;
if Assigned(Webbrowser) and Assigned(Webbrowser.Document)
then begin
if
Failed(Webbrowser.Application.QueryInterface(IServiceprovider, ISP))
then exit;
if Succeeded(ISP.QueryService(SID_STravelLogCursor,
IID_ITravelLogStg, Stg))
then Result := TRUE;
end;
end;
|
procedure EnumerateBack;
Enumerate all back-entries. You can trap the entries in
The OnEntry-Event, where you get the URL and Title for each entry. You can
also stop the enumeration by setting Cancel:=True;
procedure EnumerateForward;
Enumerate all forward-entries. You can trap the entries in
The OnEntry-Event, where you get the URL and Title for each entry. You can
also stop the enumeration by setting Cancel:=True;
procedure Enumerate;
Enumerate all entries. You can trap the entries in The
OnEntry-Event, where you get the URL and Title for each entry. You can
also stop the enumeration by setting Cancel:=True;
function TravelTo(Offset: Integer): HRESULT;
Set the travel-log Cursor somewhere else in the history-stack and send
the webbrowser to the selected URL. Offset is the position relative to the
current position.
If Offset is -2 you travel to entries back.
If Offset is 3 you travel to entries forward.
The OnClick-event for a popupmenu would look something
like this:
procedure TForm1.MyPopupHandler(Sender: TObject);
var
index: Integer;
begin
with Sender as TMenuItem do
if Goback then
Index := 0 - popupmenu1.Items.IndexOf(Sender as TmenuItem) - 1
else
Index := popupmenu1.Items.IndexOf(Sender as TmenuItem) + 1;
IETravelLog1.TravelTo(Index);
end;
|
function GetRelativeEntry(Offset: Integer; out Title, Url: string): HRESULT;
Use this function to get the url and title from an entry
in the travel log.
GetRelativeEntry(-2, Title, Url) will get the url and title two
entries back in the Travel Log.
function CreateEntry(Offset: Integer; URL, Title: string): HRESULT;
Create an entry in the Travel Log.
CreateEntry(2, 'http://www.euromind.com/iedelphi', 'IE
& Delphi') will add the url as the second forward-entry.
function RemoveEntry(Offset: Integer): HRESULT;
function RemoveEntryByTitle(title: string): HRESULT;
function RemoveEntryByUrl(Url: string): HRESULT;
Use these functions the remove entries from the Travel
Log, either by their position or by title or url.
procedure ClearSession;
Deletes all entries from the Travel Log.
function GetCount(flags: DWORD; out Entries: DWORD): HRESULT;
Count number of entries according to the flags - one or
more of the following:
- TLEF_RELATIVE_INCLUDE_CURRENT
-
Enumeration should include the current travel log
entry.
- TLEF_RELATIVE_BACK
-
Enumeration should include entries before the
current entry.
- TLEF_RELATIVE_FORE
-
Enumeration should include entries after the current
entry.
- TLEF_INCLUDE_UNINVOKEABLE
-
Enumeration should include entries which cannot be
navigated to.
- TLEF_ABSOLUTE
-
Enumeration should include all invokable entries.
|