Page 1 of 1

Getting SongData members at run time

Posted: Wed Jan 07, 2009 12:41 pm
by Teknojnky
Something that always bugged me that I never figured out, was if/how it would be possible to get all the songdata fields dynamically at run time, instead of coding for each individual field.

Basically, I want to get a (indexed?) list of fields, perform a search, make a change, or check for certain data types on each field (or only specific ones), then move to the next songdata item.

Re: Getting SongData members at run time

Posted: Wed Jan 07, 2009 1:00 pm
by Bex
You have to create your own function which takes a songdata object and the returns all properties as an array. You can then do stuff with the array.

E.g.

Code: Select all

Sub GetAllProperties(SongdataObj)
  Dim AllPropArray(?)
  AllPropArray(0)=SongdataObj.Artist
  AllPropArray(1)=SongdataObj.Title
  AllPropArray(2)=SongdataObj.Album
  A.s.o. to
  AllPropArray(?)=SongdataObj.???

  GetAllProperties=AllPropArray
End Function

Re: Getting SongData members at run time

Posted: Wed Jan 07, 2009 1:23 pm
by Teknojnky
but that is the same as coding for each field.

What if you did not know the fields? Yes I know they are documented, but from a programtic point of view?

Re: Getting SongData members at run time

Posted: Wed Jan 07, 2009 1:36 pm
by Bex
Yes, but you can use it multiple times and also save the code for other scripts as well. There is no automated way to retrieve this.
It would be nice though with some auto functions that returns an Arrays consisting of e.g.
All fields (get/let or get)
Editable fields (get/let)
non-editable fields (get)

But for now you need to create them manually. I believe that both Steegy and Trixmoto has made such functions in a couple of their scripts. I have a similar one which I use in ADFF's Copy/Paste Metadata.