急!!!!delphi7中两台机器怎么进行消息传递?用什么控件? delphi7中两台机器怎么进行消息传递?用什么控件? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 昨天刚刚学会一招indy控件的udp服务器和客户端 用MSMQ吧,刚刚试用过的,很好用!unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, MSMQ_TLB, ExtCtrls;type TForm1 = class(TForm) StatusBar1: TStatusBar; Panel2: TPanel; GroupBox2: TGroupBox; GroupBox1: TGroupBox; Panel1: TPanel; SendMsgLabel: TEdit; Panel3: TPanel; RecvMsg: TButton; SendMsg: TButton; Panel4: TPanel; RecvMsgLabel: TEdit; Panel5: TPanel; Panel6: TPanel; Panel7: TPanel; Panel8: TPanel; SendCoumpterName: TEdit; SendQueueName: TEdit; RecvCoumpterName: TEdit; RecvQueueName: TEdit; SendRichEdit: TRichEdit; RecvRichEdit: TRichEdit; OpenDialog1: TOpenDialog; procedure SendMsgClick(Sender: TObject); procedure RecvMsgClick(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementationuses ComObj;{$R *.dfm}procedure TForm1.SendMsgClick(Sender: TObject);var QueueName, Subject: string; Data: OleVariant; QueueInfo: IMSMQQueueInfo; Queue: IMSMQQueue; Msg: IMSMQMessage; tr: OLEVariant; O1, O2: OleVariant;begin QueueName := 'Direct=OS:'+ SendCoumpterName.Text + '\private$\'+ SendQueueName.Text; Subject := SendMsgLabel.Text + '[' + DateTimeToStr(Now) + ']'; Data := SendRichEdit.Lines.Text; try QueueInfo := CreateCOMObject(CLASS_MSMQQueueInfo) as IMSMQQueueInfo; QueueInfo.FormatName := QueueName; try Queue := QueueInfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE); except QueueInfo.PathName := SendCoumpterName.Text + '\private$\'+ SendQueueName.Text; O1 := True; O2 := False; QueueInfo.Create(O1, O2); Queue := QueueInfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE); end; if not Queue.IsOpen then StatusBar1.SimpleText := '队列没有打开或队列不存在!' else begin try Msg := CreateCOMObject(CLASS_MSMQMessage) as IMSMQMessage; Msg.Label_ := Subject; Msg.Body := Data; tr := MQ_SINGLE_MESSAGE; Msg.Send(Queue, tr); StatusBar1.SimpleText := '数据传送成功!' finally Queue.Close; end; end; except on E: exception do ShowMessage (E.Message); end;end;procedure TForm1.RecvMsgClick(Sender: TObject);var QueueName: string; Data: OleVariant; QueueInfo: IMSMQQueueInfo; Queue: IMSMQQueue; Msg: IMSMQMessage; tr, wdq, wb, rt: OleVariant;begin QueueName:= 'Direct=OS:'+ RecvCoumpterName.Text + '\private$\'+ RecvQueueName.Text; try QueueInfo := CreateCOMObject(CLASS_MSMQQueueInfo) as IMSMQQueueInfo; QueueInfo.FormatName := QueueName; Queue := QueueInfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE); if not Queue.IsOpen then StatusBar1.SimpleText := '队列打不开或不存在!' else begin try tr := MQ_SINGLE_MESSAGE; wdq := False; wb := True; rt := 1000; Msg := Queue.Receive(tr, wdq, wb, rt); if Msg <> nil then begin Data := Msg.Body; StatusBar1.SimpleText := '接收成功!'; RecvRichEdit.Lines.Text := Data; RecvMsgLabel.Text := Msg.Label_; end else StatusBar1.SimpleText := '您所打开的队列中没有消息' finally Queue.Close; end; end; except on E: Exception do ShowMessage(E.Message); end;end;end. delphi7 中可以用 Tcpsever 和Tcpclient 控件.或者用Udpsockets控件。以上控件均在internet组件板。或者用indy的一套控件 实现截屏区域选择框。。 怎样在按下一个功能键后得到键值 在DLL中怎么无法使用capCreateCaptureWindowA函数? 对主从表的从表还能进行过滤吗? 文件加密解密问题,急用在线等待。 请大家共同来帮我想想办法,非技术性问题! delphi and oracle的动态查询 导数据到excel中去怎幺老是死机? 程序崩溃救命 关于图像处理的问题 delphi的支持者,请进 怎么在delphi里面制作类似于web框架那样的界面窗口!在线等待!!!
indy控件的udp服务器和客户端
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, MSMQ_TLB, ExtCtrls;type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
Panel2: TPanel;
GroupBox2: TGroupBox;
GroupBox1: TGroupBox;
Panel1: TPanel;
SendMsgLabel: TEdit;
Panel3: TPanel;
RecvMsg: TButton;
SendMsg: TButton;
Panel4: TPanel;
RecvMsgLabel: TEdit;
Panel5: TPanel;
Panel6: TPanel;
Panel7: TPanel;
Panel8: TPanel;
SendCoumpterName: TEdit;
SendQueueName: TEdit;
RecvCoumpterName: TEdit;
RecvQueueName: TEdit;
SendRichEdit: TRichEdit;
RecvRichEdit: TRichEdit;
OpenDialog1: TOpenDialog;
procedure SendMsgClick(Sender: TObject);
procedure RecvMsgClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
implementation
uses ComObj;
{$R *.dfm}procedure TForm1.SendMsgClick(Sender: TObject);
var
QueueName, Subject: string;
Data: OleVariant;
QueueInfo: IMSMQQueueInfo;
Queue: IMSMQQueue;
Msg: IMSMQMessage;
tr: OLEVariant;
O1, O2: OleVariant;
begin
QueueName := 'Direct=OS:'+ SendCoumpterName.Text + '\private$\'+ SendQueueName.Text;
Subject := SendMsgLabel.Text + '[' + DateTimeToStr(Now) + ']';
Data := SendRichEdit.Lines.Text;
try
QueueInfo := CreateCOMObject(CLASS_MSMQQueueInfo) as IMSMQQueueInfo;
QueueInfo.FormatName := QueueName;
try
Queue := QueueInfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE);
except
QueueInfo.PathName := SendCoumpterName.Text + '\private$\'+ SendQueueName.Text;
O1 := True;
O2 := False;
QueueInfo.Create(O1, O2);
Queue := QueueInfo.Open(MQ_SEND_ACCESS, MQ_DENY_NONE);
end;
if not Queue.IsOpen then
StatusBar1.SimpleText := '队列没有打开或队列不存在!'
else begin
try
Msg := CreateCOMObject(CLASS_MSMQMessage) as IMSMQMessage;
Msg.Label_ := Subject;
Msg.Body := Data;
tr := MQ_SINGLE_MESSAGE;
Msg.Send(Queue, tr);
StatusBar1.SimpleText := '数据传送成功!'
finally
Queue.Close;
end;
end;
except
on E: exception do ShowMessage (E.Message);
end;
end;procedure TForm1.RecvMsgClick(Sender: TObject);
var
QueueName: string;
Data: OleVariant;
QueueInfo: IMSMQQueueInfo;
Queue: IMSMQQueue;
Msg: IMSMQMessage;
tr, wdq, wb, rt: OleVariant;
begin
QueueName:= 'Direct=OS:'+ RecvCoumpterName.Text + '\private$\'+ RecvQueueName.Text;
try
QueueInfo := CreateCOMObject(CLASS_MSMQQueueInfo) as IMSMQQueueInfo;
QueueInfo.FormatName := QueueName;
Queue := QueueInfo.Open(MQ_RECEIVE_ACCESS, MQ_DENY_NONE);
if not Queue.IsOpen then
StatusBar1.SimpleText := '队列打不开或不存在!'
else begin
try
tr := MQ_SINGLE_MESSAGE;
wdq := False;
wb := True;
rt := 1000;
Msg := Queue.Receive(tr, wdq, wb, rt);
if Msg <> nil then
begin
Data := Msg.Body;
StatusBar1.SimpleText := '接收成功!';
RecvRichEdit.Lines.Text := Data;
RecvMsgLabel.Text := Msg.Label_;
end
else
StatusBar1.SimpleText := '您所打开的队列中没有消息'
finally
Queue.Close;
end;
end;
except
on E: Exception do ShowMessage(E.Message);
end;
end;
end.
或者用Udpsockets控件。
以上控件均在internet组件板。
或者用indy的一套控件