Problem in OnSpatialData Event in Delphi 7 and Delphi 2010

Forum for Delphi Discussion
persianpatient

Problem in OnSpatialData Event in Delphi 7 and Delphi 2010

Postby persianpatient » Tue Sep 07, 2010 12:33 am

Hi ,

there is a problem in OnSpatialData event . the data should be PhidgetSpatial_SpatialEventData , but it is OleVariant .

PhidgetSpatial_SpatialEventData is :

Code: Select all

  PhidgetSpatial_SpatialEventData = packed record
    Acceleration: array[0..2] of Double;
    angularRate: array[0..2] of Double;
    magneticField: array[0..2] of Double;
    time_seconds: Integer;
    time_microseconds: Integer;
  end;

User avatar
Patrick
Lead Developer
Posts: 2943
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Problem in OnSpatialData Event in Delphi 7 and Delphi 20

Postby Patrick » Tue Sep 07, 2010 9:16 am

it's actually an array (safearray) of PhidgetSpatial_SpatialEventData. I'm not sure how Delphi represents safearrays.

-Patrick

persianpatient

Re: Problem in OnSpatialData Event in Delphi 7 and Delphi 20

Postby persianpatient » Wed Sep 08, 2010 1:07 am

Dear Patrick,

this is a part of Phidget21COM_TLB.pas :

Code: Select all

  _IPhidgetSpatialEvents = dispinterface
    ['{50484945-4745-5453-2000-000000000017}']
    procedure OnAttach; dispid 1;
    procedure OnDetach; dispid 2;
    procedure OnError(const Description: WideString; SCODE: PhidgetCOM_Error); dispid 3;
    procedure OnServerConnect; dispid 4;
    procedure OnServerDisconnect; dispid 5;
    procedure OnSpatialData(var data: {??PSafeArray}OleVariant; dataCount: Integer); dispid 6;
  end;

User avatar
Patrick
Lead Developer
Posts: 2943
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Problem in OnSpatialData Event in Delphi 7 and Delphi 20

Postby Patrick » Wed Sep 08, 2010 10:16 am


jaco
Fresh meat
Posts: 3
Joined: Thu Mar 17, 2011 11:24 am
Contact:

Re: Problem in OnSpatialData Event in Delphi 7 and Delphi 20

Postby jaco » Thu Mar 17, 2011 11:30 am

I'm running into the exact same problem: I am not able to extract the correct values in the OnSpatialData event.
Any help would be greatly appreciated in converting from OleVariant to PhidgetSpatial_SpatialEventData. The hints mentioned here are not enough for me to understand how to do that.

jaco
Fresh meat
Posts: 3
Joined: Thu Mar 17, 2011 11:24 am
Contact:

Re: Problem in OnSpatialData Event in Delphi 7 and Delphi 20

Postby jaco » Mon Mar 21, 2011 4:17 am

I think I have solved my own problem here. I'll post my solution so anyhow wondering in the future about the same issue might use this.
The typelibrary as generated by Delphi on import of the COM object generates the type PhidgetSpatial_SpatialEventData which I expected to get in the OnSpatialData event. However this event has a parameter 'data' of type OleVariant. I can access the data in the OnSpatialData event by adding the line

Code: Select all

PPhidgetSpatial_SpatialEventData = ^PhidgetSpatial_SpatialEventData;
in the generated typelibrary.

In the eventhandler I can access the data by doing this:

Code: Select all

procedure TFormMain.PhidgetSpatialSpatialData(ASender: TObject;
  var data: OleVariant; dataCount: Integer);
var
  pData: PPhidgetSpatial_SpatialEventData;
begin
  PData := PPhidgetSpatial_SpatialEventData(VarArrayLock(data));
  try
    Label1.Caption := Format('%g', [pData^.Acceleration[0]]);
    Label2.Caption:= Format('%d', [pData^.time_seconds]);
  finally
    VarArrayUnlock(data);
  end;
end;
As far as I can see this gets me the correct values. I came up with this solution by looking at the provided VB sample and googling for OleVariant handling in Delphi.
Hope this will help others in the future.
Regards
Jaco

seoman
Fresh meat
Posts: 1
Joined: Mon Mar 04, 2013 3:26 am
Contact:

Re: Problem in OnSpatialData Event in Delphi 7 and Delphi 20

Postby seoman » Mon Mar 04, 2013 3:29 am

@Jaco

Thanx!
This works for me just fine!

jaco
Fresh meat
Posts: 3
Joined: Thu Mar 17, 2011 11:24 am
Contact:

Re: Problem in OnSpatialData Event in Delphi 7 and Delphi 20

Postby jaco » Mon Mar 04, 2013 6:31 am

seoman wrote:@Jaco

Thanx!
This works for me just fine!


Cool! Thanks for the thank you :-)


Return to “Delphi”

Who is online

Users browsing this forum: No registered users and 1 guest