2005. november 14., hétfő

DDE link to Netscape


Problem/Question/Abstract:

DDE link to Netscape

Answer:

Create a new application with a form Form1, put the components on it as in the following class defined (buttons, edit controls, labels and one TDDEClientConv) and link the events to the given procedures.

Button3 will have Netscape open the entered url.

unit Netscp1;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DdeMan;

type
  TForm1 = class(TForm)
    DdeClientConv1: TDdeClientConv;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    LinkStatus: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    URLName: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }

  end;

var
  Form1: TForm1;
  LinkOpened: integer;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  if LinkOpened = 0 then
  begin
    DdeClientConv1.SetLink('Netscape', 'WWW_OpenURL');
    if DdeClientConv1.OpenLink then
    begin
      LinkStatus.Text := 'Netscape Link has been opened';
      LinkOpened := 1
    end
    else
      LinkStatus.Text := 'Unable to make Netscape Link'
  end
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  LinkOpened := 0
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  DdeClientConv1.CloseLink;
  LinkOpened := 0;
  LinkStatus.Text := 'Netscape Link has been closed'
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  ItemList: string;
begin
  if LinkOpened <> 0 then
  begin
    ItemList := URLName.Text + ',,0xFFFFFFFF,0x3,,,';
    DdeClientConv1.RequestData(ItemList)
  end
end;

end.

Nincsenek megjegyzések:

Megjegyzés küldése