INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Using COM - struggeling with multiple zones...  (Read 1431 times)

widert

  • Recent member
  • *
  • Posts: 6
Using COM - struggeling with multiple zones...
« on: October 28, 2012, 05:56:37 am »

Hi, just started looking into writing a little program that detects if Media Center is playing that will be used to control on/off of an amplifier.

I'm using Delphi and the Media Center com object.

Can anybody tell me why the following code does not work:

Code: [Select]
for i := 0 to MC.GetZones.GetNumberZones do
    listbox1.Items.Append(mc.GetZones.GetZoneName(i));

Regards
Tom
Logged

eapool

  • Galactic Citizen
  • ****
  • Posts: 266
Re: Using COM - struggeling with multiple zones...
« Reply #1 on: October 28, 2012, 06:08:19 am »

Well, without knowing how you defined mc, I am assuming you successfully made the connection to mc and recieved a valid mc object.  Also, if you could tell us what the error you are recieving is, we could probably give you better information.

But, since GetZoneName is a 0 based array, you should use MC.GetNumberZones -1 as you upper limit.  If there are three zones, then they are number 0, 1, 2 and I am assuming that GetNumberZones will return a 3.

Hope this helps,

Alex
Logged

widert

  • Recent member
  • *
  • Posts: 6
Re: Using COM - struggeling with multiple zones...
« Reply #2 on: October 28, 2012, 08:57:00 am »

Thanks for your response

Updated code:
Code: [Select]
  mc.Connect;
  for i := 0 to MC.GetZones.GetNumberZones -1 do
    listbox1.Items.Append(mc.GetZones.GetZoneName(i));
  mc.Disconnect;

Connection works fine, and adding the name of the first zone works ok.

When trying to add the next name I however get:
Quote
First chance exception at $00C68FBB. Exception class $C0000005 with message 'access violation at 0x00c68fbb: write of address 0xb4000000'. Process Project1.exe (9168)

Tom
Logged
Pages: [1]   Go Up