The Code is as follows:
Unit unit1;
Interface
Uses
Windows, messages, sysutils, variants, classes, graphics, controls, forms,
Dialogs, extctrls, stdctrls;
Type
Mqdatainfo = record
ID: integer;
Name: pansichar;
Value: pansichar;
Image: tbitmap;
End;
Pmqdatainfo = ^ mqdatainfo;
Type
Tform1 = Class (tform)
Memo1: tmemo;
Button1: tbutton;
Labelededit1: tlabelededit;
Labelededit2: tlabelededit;
Labelededit3: tlabelededit;
Button2: tbutton;
Button3: tbutton;
Image1: timage;
Procedure button1click (Sender: tobject );
Procedure button2click (Sender: tobject );
Procedure button3click (Sender: tobject );
Private
{Private Declarations}
Public
{Public declarations}
End;
VaR
Form1: tform1;
Implementation
{$ R *. DFM}
Uses mqi;
Const
Qm_name: mqchar48 = 'mytest' #0;
Queue_name: mqchar48 = 'test001' #0;
Procedure tform1.button1click (Sender: tobject );
VaR
Hconn: mqhconn;
Hobj: mqhobj;
Connectopts: mqcno;
Qmgrname: mqchar48;
Objdesc: mqod;
Options, compcode, reason: mqlong;
Buffer: mqdatainfo; // pansichar; // array [0 .. 1024000] of byte;
Bufferlength: integer;
Msgdesc: mqmd;
Putmsgoptions: mqpmo;
Begin
Qmgrname: = qm_name;
Connectopts: = mqcno_default;
Mqconnx (@ qmgrname, @ connectopts, @ hconn, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('connect failed ');
End
Else
Begin
Self. memo1.lines. Add ('connectedsuccessed ');
End;
Options: = mqoo_fail_if_quiescing + mqoo_output;
Objdesc: = mqod_default;
Objdesc. objectname: = queue_name;
Mqopen (hconn, @ objdesc, options, @ hobj, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('Open failed ');
End
Else
Begin
Self. memo1.lines. Add ('Open successed ');
End;
Msgdesc: = mqmd_default;
Putmsgoptions: = mqpmo_default;
Buffer. ID: = 100;
Buffer. Name: = 'name001' #0;
Buffer. Value: = 'value001' #0;
Buffer. Image: = tbitmap. Create;
Buffer. image. Assign (self. image1.picture. Bitmap );
Bufferlength: = sizeof (buffer );
Mqput (hconn, hobj, @ msgdesc, @ putmsgoptions, bufferlength, @ buffer, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('put failed ');
End
Else
Begin
Self. memo1.lines. Add ('put successed ');
End;
Options: = mqco_none;
Mqclose (hconn, @ hobj, options, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('close failed ');
End
Else
Begin
Self. memo1.lines. Add ('close successed ');
End;
Mqdisc (@ hconn, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('disconnect failed ');
End
Else
Begin
Self. memo1.lines. Add ('disconnectedsuccessed ');
End;
Self. memo1.lines. Add ('----------------------');
End;
Procedure tform1.button2click (Sender: tobject );
VaR
Hconn: mqhconn;
Hobj: mqhobj;
Connectopts: mqcno;
Qmgrname: mqchar48;
Objdesc: mqod;
Options, compcode, reason: mqlong;
Buffer: mqdatainfo; // array [0 .. 1024000] of char;
Bufferlength: integer;
Msgdesc: mqmd;
Getmsgoptions: mqgmo;
Datalength: mqlong;
Begin
Qmgrname: = qm_name;
Connectopts: = mqcno_default;
Mqconnx (@ qmgrname, @ connectopts, @ hconn, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('connect failed ');
End
Else
Begin
Self. memo1.lines. Add ('connectedsuccessed ');
End;
Options: = mqoo_fail_if_quiescing + mqoo_input_as_q_def;
Objdesc: = mqod_default;
Objdesc. objectname: = queue_name;
Mqopen (hconn, @ objdesc, options, @ hobj, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('Open failed ');
End
Else
Begin
Self. memo1.lines. Add ('Open successed ');
End;
Bufferlength: = sizeof (buffer );
Datalength: = 0;
Msgdesc: = mqmd_default;
Getmsgoptions: = mqgmo_default;
Mqget (hconn, hobj, @ msgdesc, @ getmsgoptions, bufferlength, @ buffer, @ datalength, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
// No message in the queue
If reason = mqrc_no_msg_available then
Begin
Self. memo1.lines. Add ('The queue is empty ');
End
Else
Begin
Self. memo1.lines. Add ('get failed ');
End;
End
Else
Begin
Self. labelededit1.text: = inttostr (buffer. ID );
Self. labelededit2.text: = buffer. Name;
Self. labelededit3.text: = buffer. value;
Self. image1.picture. bitmap. Assign (buffer. Image );
Self. memo1.lines. Add ('get successed ');
End;
Options: = mqco_none;
Mqclose (hconn, @ hobj, options, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('close failed ');
End
Else
Begin
Self. memo1.lines. Add ('close successed ');
End;
Mqdisc (@ hconn, @ compcode, @ reason );
If compcode <> mqcc_ OK then
Begin
Self. memo1.lines. Add ('disconnect failed ');
End
Else
Begin
Self. memo1.lines. Add ('disconnectedsuccessed ');
End;
Self. memo1.lines. Add ('----------------------');
End;
Procedure tform1.button3click (Sender: tobject );
Begin
Self. labelededit1.text: = '0 ';
Self. labelededit2.text: = '';
Self. labelededit3.text: = '';
Self. image1.picture. Assign (NiL );
End;
End.