Solved

TWebBrowser - invoking mail client

Posted on 1998-08-18
3
158 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you. It works great.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now