OmniThreadLibrary forum
News: SMF - Just Installed!
 
*
Welcome, Guest. Please login or register. May 17, 2012, 06:03:13 PM


Login with username, password and session length


Pages: [1]   Go Down

Author Topic: Sending an Interface as one of multiple parameters in a Task.Comm.Send  (Read 515 times)

rshealer

  • Newbie
  • *
  • Posts: 4
    • View Profile

I have been successful in sending an interface when I send a single Interface parameter in a Task.Comm.Send, but not when it is in an array of constants.

Working Ex:
   MyIntf is a IMyIntf

   Task.Comm.Send(MSG_LABELDEF, MyIntf);

On the other side:

    MSG_LABELDEF: begin //receive the interface
      Intf := msg.MsgData.AsInterface;
      Intf.QueryInterface(IMyIntf , MyIntf );
      frmMain.PrintData(MyIntf);
    end;

What I need to do is this (below), but I haven't found a good combination yet. I've also tried variations in casting on the send side.

   MyIntf is a IMyIntf

   Task.Comm.Send(MSG_LABELDEF, [MyIntf, 'Test');

On the other side:

    MSG_LABELDEF: begin //receive the interface
      // Intf := msg.MsgData[0];                  //Gives EVariantTypeCastError Integer
                                                             //   to Unknown

      // Intf := msg.MsgData[0].AsInterface; //Gives EVariantInvalidOpError 'Invalid
                                                             //   variant operation;

      // Intf := IUnknown(msg.MsgData[0]);  //Gives EVariantTypeCastError Integer
                                                             //   to Unknown


      Intf.QueryInterface(IMyIntf , MyIntf );
      frmMain.PrintData(MyIntf);
    end;

Logged

Primoz Gabrijelcic

  • Administrator
  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • Email
Re: Sending an Interface as one of multiple parameters in a Task.Comm.Send
« Reply #1 on: January 04, 2012, 01:57:18 AM »

May be a bug. I'll check it out.
Logged

Primoz Gabrijelcic

  • Administrator
  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • Email
Re: Sending an Interface as one of multiple parameters in a Task.Comm.Send
« Reply #2 on: January 04, 2012, 02:38:30 AM »

msg.MsgData[0].AsInterface as IMyIntf

works in XE2.

Can you put together a small demo app that exhibits the problem?
Logged

rshealer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sending an Interface as one of multiple parameters in a Task.Comm.Send
« Reply #3 on: January 04, 2012, 10:58:15 AM »

I can't get that to compile in XE.  I've modified your App_2_TwoWayHello to demonstrate. I created an Interface that has a MSg property with the Getter Setter. Where should I put it?

Error:
[DCC Error] test_2_TwoWayHello.pas(151): E2015 Operator not applicable to this operand type


procedure TfrmTestTwoWayHello.HandleTaskMessage(const task: IOmniTaskControl; const msg:
  TOmniMessage);
var
 MyIntF : IMyIntF;
begin
  MyIntF := msg.MsgData[0].AsInterface as IMyIntf;  <-- Error Here
  lbLog.ItemIndex := lbLog.Items.Add(Format('[%d/%s] %d|%s',
    [task.UniqueID, task.Name, msg.MsgID, MyIntF.Msg]));
end;
Logged

Primoz Gabrijelcic

  • Administrator
  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • Email
Re: Sending an Interface as one of multiple parameters in a Task.Comm.Send
« Reply #4 on: January 04, 2012, 11:18:47 AM »

From your small fragment of code I can't tell what's going wrong at your side.

See test 50_OmniValueArray and check 'Send array' button - it sends one array element as an interface.
Logged

rshealer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sending an Interface as one of multiple parameters in a Task.Comm.Send
« Reply #5 on: January 04, 2012, 11:25:08 AM »

I don't have test 50 on my current revision (It is 1003 from October).  What revision should I use that is not part of the new 64-bit Beta?
Logged

Primoz Gabrijelcic

  • Administrator
  • Hero Member
  • *****
  • Posts: 569
    • View Profile
    • Email
Re: Sending an Interface as one of multiple parameters in a Task.Comm.Send
« Reply #6 on: January 04, 2012, 11:29:45 AM »

Latest, of course! Update to the current SVN state and then retest.
Logged

rshealer

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Sending an Interface as one of multiple parameters in a Task.Comm.Send
« Reply #7 on: January 04, 2012, 12:03:10 PM »

I guess there was something in the library that has been fixed.  It compiles now that I did the update to 1099.

For others in the future that may stumble upon this:
The following syntax variations work to assign the interface to MyIntF

  MyIntF := msg.MsgData[0].AsInterface as IMyIntf;
  msg.MsgData[0].AsInterface.QueryInterface(IMyIntF, MyIntF)

This also works if you only need a temporary reference to assign the Msg value to the string str;

  str := (msg.MsgData[0].AsInterface as IMyIntF).Msg;


Thank you.
Logged
Pages: [1]   Go Up
 
 

Powered by MySQL Powered by PHP Powered by SMF 2.0.2 | SMF © 2006-2009, Simple Machines LLC

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM