Ha! ... I found it.
I found a site that archives messages from the borland newsgroups and someone had already asked about this same thing and had gotten an answer.
So if anyone outhere has a similar need, you can save the agravation of hours of searching and go directly to these links:
http://delphi.mers.com/searchsite.html and use "msmq and delphi" as the search text to get to the answer regarding this subject.
http://www.intac.com/~bly/com/index.htm utilities for enabling the use of msmq event handling.
Thanks Binh Ly
Regards,
Mario Estrella
marioestre...@e{*word*277}.com
Mario Estrella <marioestre...@e{*word*277}.com> wrote in message news:7s1ic1$3ok3@forums.borland.com...
Scott or anyone with MSMQ / Delphi,
Is it possible to define and event handler for msmq event notification in delphi to enable to asynchronous reading of messages. ???
I've searching all over the place for samples but have found none.
I have imported the type library for msmq and i'm pretty sure I can send and receive messages, but since my expertise with COM related technologies is very little I cant figure out how to setup event notification using Delphi.
I've seen the VB examples included with MSMQ but have not figured a "Dim WithEvents" equivalent in Delphi.
Using D4 C/S (U3)
Thanks for any advice you can provide.
Mario Estrella
marioestre...@e{*word*277}.com
Scott Brittain <scott_britt...@hotmail.com> wrote in message news:37D061D1.7DFEB34D@hotmail.com...
I have recently a ton of MSMQ D4 code. My biggest first recommendation would be to import
the MSMQ type library and reference the interfaces directly. This adds type checking and takes
(much) of the OleVariant headache away.
Here's a routine for looking up a random queue by its ServiceTypeGUID which you can probably
adapt. Essentially this returns a Q FormatName property which you'd use to Open the Q. Let me
know if you need more:
function TConnectorHandler.FindQRandom : string;
{
Purpose: Find the MSMQ queue formatname which matches
our service needs.
}
var
lvServiceType : OleVariant;
lQQuery : IMSMQQuery;
lQInfo : IMSMQQueueInfo;
lQInfos : IMSMQQueueInfos;
lFormatNameList : TStringList;
lPreferredList : TStringList;
lszFN : string;
begin
{ Pull the MSMQ service type from the list }
lvServiceType := // your service type guid passed in here ;
{ Query for a Q matching our type }
lQQuery := CoMSMQQuery.Create;
try
{ Get the notification q }
lQInfos := lQQuery.LookupQueue( EmptyParam, lvServiceType,
EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
EmptyParam, EmptyParam );
try
lQInfos.Reset;
lFormatNameList := TStringList.Create;
try
{ Walk through all the matching service queues }
lQInfo := lQInfos.Next;
while (lQInfo <> nil) do begin
lszFN := lQInfo.FormatName;
lFormatNameList.Add( lszFN );
lQInfo := lQInfos.Next;
end; { while }
{ We now have a list of available queues matching this service,
pick one randomly and return it. Check first that
there exist at least one service provider! }
Randomize;
if (lFormatNameList.Count > 0) then begin
{ Return the Q FormatName property which is the most efficient
way to reference a Q }
Result := lFormatNameList.Strings[Random( lFormatNameList.Count )];
end { if-then }
else begin
{ No service available, then return blank which will
NOT get written to formatname_key }
Result := '';
end; { if-else }
finally
lFormatNameList.Free
end; { try-finally }
finally
lQInfos := nil;
end; { try-finally }
finally
lQQuery := nil;
end; { try-finally }
end; { function }
Robert Baker wrote:
I am searching for a way to determine the end of the Queues in MSMQ. The
line "(VarIsNull(VarAsType(oQueueInfo,varDispatch)))" produces an access
violation. Also, if I look for a specific Queie, via "oQueueInfos :=
oquery.LookupQueue(,,'msmqtest');" I do not seem to find it. Bottom line is
that I don not understand how to work with an OleVariant and have not
located docs on how to do so. TYIA, Robert Baker - zxy...@hotmail.com
procedure TForm1.Button1Click(Sender: TObject);
var
oQuery: OleVariant;
oQueueInfos, oQueueInfo: OleVariant;
lcQueueName:string;
begin
lcQueueName := 'msmqtest';
// Try to locate queue first
oQuery := CreateOleObject('msmq.msmqquery');
oQueueInfos := oquery.LookupQueue();
oQueueInfos.Reset;
oQueueInfo := oQueueInfos.Next;
if TVarData(oQueueInfo).VType = varDispatch then Label1.caption :=
'varDispatch';
while not (VarIsNull(VarAsType(oQueueInfo,varDispatch))) do begin
Label1.caption := 'Label: ' + oQueueInfo.Label + 'Path: ' +
oQueueInfo.PathName;
oQueueInfo := oQueueInfos.Next;
end;
end;