Solved

TWebBrowser - invoking mail client

Posted on 1998-08-18
3
159 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 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