?
Solved

How do open up a browser...

Posted on 1998-08-28
5
Medium Priority
?
153 Views
Last Modified: 2010-04-04
I am writing a Delphi app and would like to know how to include a link to my web site and also to my e-mail.
I would like to know how to make it so that the user just clicks and the default browser opens up and goes to my site.
I know I have to use ShellExecute but how would I go about this?
0
Comment
Question by:pf2
[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
5 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1337982
Hi,

Simplest way:
uses ...ShellAPI; // don't forget

  ShellExecute( 0, 'open', 'http://www.mydomain.com/~MyName/StartPage.html', nil, nil, SW_SHOW );

/// John
0
 
LVL 1

Expert Comment

by:Greedy
ID: 1337983
You can also do this

function MyCreateProcess(sExecutableFilePath : string): string;
var
  pi: TProcessInformation;
  si: TStartupInfo;
begin
  FillMemory(@si, sizeof( si), 0 );
  si.cb := sizeof( si );
  CreateProcess(Nil, PChar(sExecutableFilePath), Nil, Nil, False,
                NORMAL_PRIORITY_CLASS, Nil, Nil, ci, pi);
  //wait until done
  CloseHandle (pi.hProcess);
  CloseHandle(pi.hThread);
end;



0
 
LVL 4

Accepted Solution

by:
itamar earned 100 total points
ID: 1337984
The answer recomended by Inprise Techinal Information:

>>>

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
      DdeMan,
     {$IFDEF WIN32}
       Registry; {We will get it from the registry}
     {$ELSE}
       IniFiles; {We will get it from the win.ini file}
     {$ENDIF}

     {$IFNDEF WIN32}
       const MAX_PATH = 144;
     {$ENDIF}

     function GetProgramAssociation (Ext : string) : string;
     var
     {$IFDEF WIN32}
       reg: TRegistry;
       s : string;
     {$ELSE}
       WinIni : TIniFile;
       WinIniFileName : array[0..MAX_PATH] of char;
       s : string;
     {$ENDIF}
     begin
     {$IFDEF WIN32}
       s := '';
       reg := TRegistry.Create;
       reg.RootKey := HKEY_CLASSES_ROOT;
       if reg.OpenKey('.' + ext + '\shell\open\command',
                      false) <> false then begin
       {The open command has been found}
         s := reg.ReadString('');
         reg.CloseKey;
       end else begin
       {perhaps thier is a system file pointer}
         if reg.OpenKey('.' + ext,
                        false) <> false then begin
           s := reg.ReadString('');
           reg.CloseKey;
           if s <> '' then begin
          {A system file pointer was found}
             if reg.OpenKey(s + '\shell\open\command',
                            false) <> false then
          {The open command has been found}
               s := reg.ReadString('');
             reg.CloseKey;
           end;
         end;
       end;
      {Delete any command line, quotes and spaces}
       if Pos('%', s) > 0 then
         Delete(s, Pos('%', s), length(s));
       if ((length(s) > 0) and
           (s[1] = '"')) then
         Delete(s, 1, 1);
       if ((length(s) > 0) and
           (pos('"', s) > 0)) then
         Delete(s, pos('"', s), Length(s));
       while ((length(s) > 0) and
              (s[length(s)] = #32)) do
         Delete(s, Length(s), 1);
     {$ELSE}
       GetWindowsDirectory(WinIniFileName, sizeof(WinIniFileName));
       StrCat(WinIniFileName, '\win.ini');
       WinIni := TIniFile.Create(WinIniFileName);
       s := WinIni.ReadString('Extensions',
                               ext,
                               '');
       WinIni.Free;
      {Delete any command line}
       if Pos(' ^', s) > 0 then
         Delete(s, Pos(' ^', s), length(s));
      {$ENDIF}
       result := s;
     end;

     procedure StartNewBrowserWindow(URL : string);
     var
       DDEConv : TDDEClientConv;
       URLFired : bool;
       App : string;
       UpApp : string;
       p : array[0..MAX_PATH] of char;
     begin
       UrlFired := false;
       App := GetProgramAssociation('HTM');
       UpApp := Uppercase(App);
       Delete(App, Pos('.EXE', UpAPP), length(App));
       if Pos('NETSCAPE.EXE',
              UpApp) > 0 then begin
         DDEConv:=TDDEClientConv.Create(nil);
         DDEConv.ServiceApplication := App;
         if DDEConv.SetLink('NETSCAPE' , 'WWW_OpenURL') then
           if DDEConv.RequestData(URL +
                                  ',,0x0,0x0') <> nil then
             if DDEConv.SetLink('NETSCAPE', 'WWW_Activate') then
               URLFired := DDEConv.RequestData('0xFFFFFFFF,0x0') <> nil;
         DDEConv.Free;
       end else
       if Pos('IEXPLORE.EXE',
              UpApp) > 0 then begin
         DDEConv:=TDDEClientConv.Create(nil);
         DDEConv.ServiceApplication := App;
         if DDEConv.SetLink('iexplore', 'WWW_OpenURL') then
           if DDEConv.RequestData(URL + ',,0') <> nil then
             if DDEConv.SetLink('iexplore', 'WWW_Activate') then
               URLFired := DDEConv.RequestData('0,0') <> nil;
         DDEConv.Free;
       end;
       if UrlFired = false then
         WinExec(StrPCopy(@p, URL), SW_SHOWNORMAL);
     end;

     procedure TForm1.Button1Click(Sender: TObject);
     begin
       Label1.Caption := GetProgramAssociation('HTM');
       StartNewBrowserWindow('http://www.borland.com');
     end;

end.

If you have problems with cutting & pasting, place a comment with yoy e-mail so I can send you the source.

IHTH
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337985
Here is how to use it.....

ShellExecute(0, 'open', 'http:\www.yahoo.com',nil,nil, SW_NORMAL);//for website...
ShellExecute(0, 'open', 'mailto:viktor@megsinet.net',nil,nil, SW_NORMAL);//for e-mail

Hope this helps =)

Regards,
Viktor Ivanov
0
 

Expert Comment

by:manolis_afentakis
ID: 1337986

uses fmxutils

(see online Help)

.
   executeFile('www.inprise.com','','',1);

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

777 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