Solved

TWebBrowser - invoking mail client

Posted on 1998-08-18
3
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 250 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 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