📄 mqaidemo.dpr
字号:
program MQAIDemo;
// **************************************************************************
// **************************************************************************
// **************************************************************************
// MQSeries IBM library test program for Delphi
// Author: Dinko Miljak
// e-mail: dinmil@flashmail.com
// version 0.0.3
// **************************************************************************
// **************************************************************************
// **************************************************************************
{$APPTYPE CONSOLE}
{$A-} // alignment settings - aviod problems between different languages
uses
SysUtils,
CMQBPas in '..\lib\CMQBPas.pas',
CMQCFPas in '..\lib\CMQCFPas.pas',
CMQPas in '..\lib\CMQPas.pas',
CMQPSPas in '..\lib\CMQPSPas.pas',
CMQXPas in '..\lib\CMQXPas.pas',
CMQZPas in '..\lib\CMQZPas.pas';
procedure CheckCallResult(Const callText: String; cc: MQLONG; rc: MQLONG);
begin
if (cc <> MQCC_OK) then begin
Writeln(Format('%s failed: Completion Code = %d : Reason = %d"', [callText, cc, rc]));
end;
end;
function PrintBagContents(dataBag: MQHBAG; indent: Integer): Integer;
const LENGTH = 500; // Max length of string to be read
INDENT_ = 4; // Number of spaces to indent
// embedded bag display
var itemCount: MQLONG; // Number of items in the bag
itemType : MQLONG; // Type of the item
i: Integer; // Index of item in the bag
stringVal: array[0..LENGTH+1] of Char; // Value if item is a string
stringLength: MQLONG; // Length of string value
ccsid: MQLONG; // CCSID of string value
iValue: MQLONG; // Value if item is an integer
selector: MQLONG; // Selector of item
bagHandle: MQHBAG; // Value if item is a bag handle
reason: MQLONG; // reason code
compCode: MQLONG; // completion code
trimLength: MQLONG; // Length of string to be trimmed
errors: Integer; // Count of errors found
blanks: String; // Blank string used to indent display
begin
errors := 0;
blanks := ' ';
(***************************************************************************)
(* Count the number of items in the bag *)
(***************************************************************************)
mqCountItems(dataBag, MQSEL_ALL_SELECTORS, itemCount, compCode, reason);
if (compCode <> MQCC_OK) then begin
Inc(errors);
end
else begin
Writeln(Format('%.*sHandle:%d ', [indent, blanks, dataBag]));
Writeln(Format('%.*sSize:%d', [indent, blanks, itemCount]));
Writeln(Format('%.*sIndex: Selector: Value:', [indent, blanks]));
end;
(***************************************************************************)
(* If no errors found, display each item in the bag *)
(***************************************************************************)
if (errors = 0) then begin
for i := 0 to itemCount-1 do begin
(********************************************************************)
(* First inquire the type of the item for each item in the bag *)
(********************************************************************)
mqInquireItemInfo(dataBag, (* Bag handle *)
MQSEL_ANY_SELECTOR, (* Item can have any selector*)
i, (* Index position in the bag *)
selector, (* Actual value of selector *)
(* returned by call *)
itemType, (* Actual type of item *)
(* returned by call *)
compCode, (* Completion code *)
reason); (* Reason Code *)
if (compCode <> MQCC_OK) then begin
Inc(errors);
end;
case itemType of
MQIT_INTEGER: begin
(***************************************************************)
(* Item is an integer. Find its value and display its index, *)
(* selector and value. *)
(***************************************************************)
mqInquireInteger(dataBag, (* Bag handle *)
MQSEL_ANY_SELECTOR, (* Allow any selector *)
i, (* Index position in the bag *)
iValue, (* Returned integer value *)
compCode, (* Completion code *)
reason); (* Reason Code *)
if (compCode <> MQCC_OK) then begin
Inc(errors);
end
else begin
Writeln(Format('%.*s %-2d %-4d (%d)',
[indent, blanks, i, selector, iValue]));
end;
end;
MQIT_STRING: begin
(***************************************************************)
(* Item is a string. Obtain the string in a buffer, prepare *)
(* the string for displaying and display the index, selector, *)
(* string and Character Set ID. *)
(***************************************************************)
mqInquireString(dataBag, (* Bag handle *)
MQSEL_ANY_SELECTOR, (* Allow any selector *)
i, (* Index position in the bag *)
LENGTH, (* Maximum length of buffer *)
@stringVal, (* Buffer to receive string *)
stringLength, (* Actual length of string *)
ccsid, (* Coded character set id *)
compCode, (* Completion code *)
reason); (* Reason Code *)
(***************************************************************)
(* The call can return a warning if the string is too long for *)
(* the output buffer and has been truncated, so only check *)
(* explicitly for call failure. *)
(***************************************************************)
if (compCode = MQCC_FAILED) then begin
Inc(errors);
end
else begin
(************************************************************)
(* Remove trailing blanks from the string and terminate with*)
(* a null. First check that the string should not have been *)
(* longer than the maximum buffer size allowed. *)
(************************************************************)
if (stringLength > LENGTH) then begin
trimLength := LENGTH;
end
else begin
trimLength := stringLength;
end;
mqTrim(trimLength, stringVal, stringVal, compCode, reason);
Writeln(Format('%.*s %-2d %-4d "%s" %d',
[indent, blanks, i, selector, stringVal, ccsid]));
end;
end;
MQIT_BAG: begin
(***************************************************************)
(* Item is an embedded bag handle, so call the PrintBagContents*)
(* function again to display the contents. *)
(***************************************************************)
mqInquireBag(dataBag, (* Bag handle *)
MQSEL_ANY_SELECTOR, (* Allow any selector *)
i, (* Index position in the bag *)
bagHandle, (* Returned embedded bag hdle*)
compCode, (* Completion code *)
reason); (* Reason Code *)
if (compCode <> MQCC_OK) then begin
Inc(errors);
end
else begin
Writeln(Format('%.*s %-2d %-4d (%d)',
[indent, blanks, i, selector, bagHandle]));
Writeln(Format('%.*sSystem Bag:"', [indent+INDENT_, blanks]));
PrintBagContents(bagHandle, indent+INDENT_);
end;
end
else begin
Writeln(Format('%.*sUnknown item type', [indent, blanks]));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -