@SilverWarior,
Ok, this is what I got. I can now click on the local links and they will open up properly inside the frame of the help system. SWEET! Now, the last nagging thing is getting the javascript to work.
Code:
procedure TForm2.FormCreate(Sender: TObject);begin
FMimeTable := TIdMimeTable.Create;
NewHttpProtocolHandler('lgp', MyProtocolHandler);
WebBrowser1.Silent := True;
WebBrowser1.Navigate('lgp://index.html');
end;
procedure TForm2.MyProtocolHandler(aURL: string; var aMIMEType: string;
const aPostMIMEType: string; const aPostData: array of byte;
aMemoryStream: TCustomMemoryStream); // TProtocolCallback
procedure WriteOutString(const aStr: string);
var
utf8Out: UTF8String;
begin
utf8Out := UTF8Encode(aStr);
aMemoryStream.WriteBuffer(Pointer(utf8Out)^,
Length(utf8Out) * SizeOf(AnsiChar));
end;
procedure WriteOutFile(const aFilename: string);
var
ms: TMemoryStream;
begin
ms := TMemoryStream.Create;
try
ms.LoadFromFile(aFilename);
ms.SaveToStream(aMemoryStream);
finally
ms.Free;
end;
end;
procedure WriteOutTextFile(const aFilename: string);
var
ms: TStringList;
begin
ms := TStringList.Create;
try
ms.LoadFromFile(aFilename);
WriteOutString(ms.Text);
finally
ms.Free;
end;
end;
function FindMimeType(const url: WideString): string;
var
mimetype: PWideChar;
begin
mimetype := nil;
FindMimeFromData(nil, PWideChar(URL), nil, 0, nil, 0, mimetype, 0);
Result := mimetype;
end;
function GenFilename(url: string): string;
begin
Result := TPath.Combine(TPath.GetDirectoryName(ParamStr(0)), 'HTML\' + url);
end;
begin
// remove any slashes from the front
while (aURL <> '') and (aURL[1] = '/') do
Delete(aURL, 1, 1);
// remove any slashes from the back
while (aURL <> '') and (aURL[Length(aURL)] = '/') do
Delete(aURL, Length(aURL), 1);
// index.html/? indicate a frame operation
if aURL.Contains('index.html/?') then
begin
// remove index.html/? from the url
aURL := aURL.Replace('index.html/?', '');
// load in the frame
WriteOutFile(GenFilename('index.html'));
end;
// check for index.html/
if aURL.Contains('index.html/') then
begin
// remove from url
aURL := aURL.Replace('index.html/', '');
end;
// if empty endpoint is the frame index else endpoint is a specific file
if aURL.IsEmpty then
aURL := 'index.html';
// get mime type of file
aMIMEType := FindMimeType(aURL);
// load the file
WriteOutFile(GenFilename(aURL));
end;
procedure TForm2.WebBrowser1BeforeNavigate2(ASender: TObject; const pDisp: IDispatch;
const URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
var Cancel: WordBool);
begin
//
Statusbar1.SimpleText := URL;
end;
procedure TForm2.WebBrowser1NewWindow3(ASender: TObject; var ppDisp: IDispatch;
var Cancel: WordBool; dwFlags: Cardinal; const bstrUrlContext,
bstrUrl: WideString);
var
s: string;
begin
// cancel new window operation
Cancel := True;
// get the url
s := bstrURL;
// modify url to indicate a frame load operation,
s := s.Replace('index.html/', 'index.html?');
// navigate to modified url that indicates a frame load operation
WebBrowser1.Navigate(s);
end;
Bookmarks