MSMQ(200分)

  • 主题发起人 主题发起人 guoyunzhi
  • 开始时间 开始时间
G

guoyunzhi

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(]专家,你好,最近在忙于用dephi控制MSMQ的方法,在网络上找了一些实列。我是引用WIN的类库,在Active中增加了一些MSMQ的控件,只能做一些基本的操作,没有办法远程创建与控制MSMQ,能否提供关于这方面的代码?谢谢。
我把最写的部部分实例提供:



unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MSMQ_TLB, OleServer,ComObj;

type
TForm1 = class(TForm)
MSMQMessage1: TMSMQMessage;
MSMQQueueInfo1: TMSMQQueueInfo;
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Label3: TLabel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Memo1: TMemo;
Memo2: TMemo;
Button2: TButton;
MSMQQueue1: TMSMQQueue;
MSMQEvent1: TMSMQEvent;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure MSMQEvent1Arrived(Sender: TObject
var Queue: OleVariant;
Cursor: Integer);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);

begin
//MSMQQueueInfo1.RemoteMachineName:='127.0.0.1';
MSMQQueueInfo1.PathName :=edit2.Text;
MSMQQueueInfo1.RemoteMachineName:='192.168.0.3';
//MSMQQueueInfo1.Label_ :='ss';
// MSMQMessage1.Label_ := '1';
MSMQMessage1.Body :=edit3.Text;
msmqqueue1.ConnectTo(MSMQQueueInfo1.Open(MQ_SEND_ACCESS, 0));
MSMQMessage1.Send(MSMQQueueInfo1.Open(MQ_SEND_ACCESS, MQ_DENY_NONE));
showmessage('已经把信息入'+edit2.Text+'消息队列中');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
msmqqueueinfo1.PathName :=edit2.Text;;
msmqqueue1.Disconnect;
msmqqueue1.ConnectTo(msmqqueueinfo1.Open(1, 0));
msmqqueue1.EnableNotification(MSMQEvent1.DefaultInterface);
end;

procedure TForm1.MSMQEvent1Arrived(Sender: TObject
var Queue: OleVariant;
Cursor: Integer);
var
Msg: Variant;
ss: string;

begin
Msg := msmqqueue1.Receive;
ss:= Msg.body;
Memo2.Lines.Add(ss);
// 处理程序
end;

procedure TForm1.Button3Click(Sender: TObject);
var
//MSMQQInfo: Variant;
MSMQ:variant;
begin
MSMQ := CreateOleObject('MSMQ.MSMQQueueInfo');
//MSMQ.RemoteMachineName:='127.0.0.1';
MSMQ.PathName := edit2.Text;
try
MSMQ.Create
//出错误提示信息
beep;
showmessage('消息队列IP为:'+edit1.Text+'中创建'+edit2.Text+'消息队列成功');
except
showmessage('消息队列IP为:'+edit1.Text+'中创建'+edit2.Text+'消息队列已存在');
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
MSMQQueue1.RemoteMachineName:='127.0.0.1';

end;

end.
 
后退
顶部