Internet/HTML

1. How can I intercept an hyperlink using NetManage's Internet Components and get the data from e.q. a database?

Use somewhere in your code a line like:

HTML1.RequestDoc( 'http://localhost/fakeurl.htm' );

You can intercept this URL in the HTML-component by using the OnRequestDoc-event. Check for the URL you'd like to intercept and pass some other information through to the DocInput object provided from within this event. Just like the following code snippit:


procedure Form1.HTML1DoRequestDoc(Sender: TObject; const URL: WideString; const Element: HTMLElement; const DocInput: DocInput; var EnableDefault: WordBool);
begin
  if CompareText(URL,'http://localhost:80/fakeurl.htm')=0 then // Of course you could also use Pos('fake.htm',lowercase(URL))>0
  begin
   // intercept fake URL and pass some other information through to the component,
   // e.q from a database memofield
   DocInput.SetData( myTable.FieldByName('MEMO').AsString );
   // Make sure you pass the data through in a 'variant'compatible manner.
   // This means a variant datatype or a datatype that the compiler can typecast to a variant (like a Delphi string)
  end;
  // else allow for default processing of an URL or intercept some more URL's
end;

The example above demonstrates that you also can provide the HTML in a Delphi string. When you solely retrieve the information from a database, then you also could have written DocInput.SetData( myTable.FieldByName('MEMO').AsVariant because SetData expects a variant.

See also the technical documents TI3144 and TI3145 for a description of the DocInput and DocOutput objects.

2. Are there alternative Internet components other then NetManage?

Yes, there are. Of course they vary in quality and ease of use, but that's up to you which you like to use.

  • Franscois Pïette wrote an Internet Component Suite for Delphi 3.
  • DHTML an ocx component by Microsoft. You'll need to install Internet Explorer 4.01 to the component use it. This also means that your users MUST install Internet Explorer 4.01 to use your program. On the other hand it's royalty free and a HTML browse and editing component.

3. How to redirect a mailto hyperlink with NetManage's HTML component?

See example 1 on howto intercept a hyperlink with the HTML component, and use the same scheme. Instead of checking for a URL with 'fake.htm', you check for the text 'mailto:' in the URL. See the code snippit hereunder:

Insert in your HTML a hyperlink constructed like this Helpdesk. In this example I included a default subject string and part of the body to use in the users mail program.


procedure Form1.HTML1DoRequestDoc(Sender: TObject; const URL: WideString; const Element: HTMLElement; const DocInput: DocInput; var EnableDefault: WordBool);
var sMailTo: string;
begin
  if Pos('mailto:',lowercase(URL))>0 then
  begin
   sMailTo := copy(URL,Pos('mailto:',lowercase(URL))+1,lenght(URL));
   if ShellExecute(handle, 'OPEN', pchar(smailto), nil, nil, SW_SHOWNORMAL) <=32 then
   // allow for default mail program e.q. Outlook Express to execute
   MessageDlg( 'Default e-mail program not found', mtError, [mbOk],0);
  end;
  // else allow for default processing of an URL or intercept some more URL's
end;

The example extract the mailto: part of the hyperlink from URL and launches the default e-mail program. The e-mail program will fill in the subject and body with the arguments specified in the mailto part of the URL.

See also the technical documents TI3144 and TI3145 for a description of the DocInput and DocOutput objects.