Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

TWebBrowser - invoking mail client

Posted on 1998-08-18
3
Medium Priority
?
167 Views
Last Modified: 2010-04-04
When a user clicks on email links on a web page, a default mail client is invoked. This default mail client is tored somewhere in the registry.

In my application, I have two forms, one is a web browser using TWebBrowser, and the other one is a mail client. So two forms in the one application.  Instead of invoking a different exe mail client when the user clicks on a mail link, I want to have the MailForm.Show called.

Thank you.
0
Comment
Question by:sharons
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 1000 total points
ID: 1337184
Yo,
do it like this:

// form code
object Form1: TForm1
  Left = 200
  Top = 108
  Width = 783
  Height = 551
  Caption = 'Form1'
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object WebBrowser1: TWebBrowser
    Left = 0
    Top = 41
    Width = 775
    Height = 483
    Align = alClient
    TabOrder = 0
    OnBeforeNavigate2 = WebBrowser1BeforeNavigate2
    ControlData = {
      4C00000019500000EB3100000100000005000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      000000000000000001000000000000000000000000000000}
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 775
    Height = 41
    Align = alTop
    TabOrder = 1
    object Edit1: TEdit
      Left = 8
      Top = 8
      Width = 537
      Height = 21
      TabOrder = 0
    end
    object Button1: TButton
      Left = 564
      Top = 8
      Width = 75
      Height = 25
      Caption = 'Go!'
      TabOrder = 1
      OnClick = Edit1Enter
    end
  end
end

// unit code
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OleCtrls, SHDocVw_TLB, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Panel1: TPanel;
    Edit1: TEdit;
    Button1: TButton;
    procedure Edit1Enter(Sender: TObject);
    procedure WebBrowser1BeforeNavigate2(Sender: TObject; pDisp: IDispatch;
      var URL, Flags, TargetFrameName, PostData, Headers: OleVariant;
      var Cancel: WordBool);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Edit1Enter(Sender: TObject);
var V1, V2, V3, V4 : OLEVariant;
begin
  V1 := 0;
  V2 := 0;
  V3 := 0;
  V4 := 0;
  WebBrowser1.Navigate(WideString(Edit1.Text), V1, V2, V3, V4);
//  WebBrowser1.Navigate(WideString(Edit1.Text), );
end;

procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
  pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
var URLString : string;
begin
  URLString := URL;
  if Pos('mailto', URLString) <> 0 then
   begin
     // mailto clicked
     Cancel := true;
     // invoke mail window with URLString
   end;
end;

end.

// project code
program Project1;

uses
  Forms,
  unit1 in 'unit1.pas' {Form1};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

Have fun,
Slash/d003303
0
 
LVL 4

Expert Comment

by:d003303
ID: 1337185
or, to be more safe, instead of

  if Pos('mailto', URLString) <> 0 then

use

  if UpperCase(Copy(URL, 1, 7)) = 'MAILTO:' then

Slash/d003303
0
 

Author Comment

by:sharons
ID: 1337186
Thank you. It works great.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Integration Management Part 2
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 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