Link to home
Start Free TrialLog in
Avatar of datalabdd
datalabdd

asked on

ADO MD (OLAP) - CubeDefs - how to get cube data and properties?

Hi!
Ive installed MDAC components to gain access to olap cubes(with D6). Im using the following code to do that:

procedure TForm1.CubeList(DataSource: WideString);
var I : Integer;
     DS         : WideString;
     Catalog1   : ICatalog;
     CubeDef1   : CubeDef;

begin
   Catalog1:=CreateComObject(StringToGUID('ADOMD.Catalog')) as ICatalog;
   Catalog1.Set_ActiveConnection(OleVariant(DS));
   if Catalog1.CubeDefs.Count > 0 then
   begin
       for i := 0 to Catalog1.CubeDefs.Count-1 do
       begin
            CubeDef1:= Catalog1.CubeDefs[i] as CubeDef; // it fails here
            TreeView1.Items.AddChild(nil, CubeDef1.Name);
      end;
   end;
end;

Ive searched the google up and down and couldnt find a solution to this problem. I keep getting  following error: [Error] Unit1.pas(57): Class does not have a default property.  So my question is how to access cubes propeties and data? With code plz.
btw: Funny thing is that Catalog1.CubeDefs.Count returns the right number of cubes.
 
Avatar of Lee_Nover
Lee_Nover

just do : Catalog1.CubeDefs.Items[i]
the compiler error was a big clue .. don't you think ?
also TheSource and CodeInsight are your friends :)
you can also be more specific (and more optimized code) and do:
CoCreateInstance(CLASS_Catalog, nil, CLSCTX_INPROC_SERVER or
     CLSCTX_LOCAL_SERVER, IID_ICatalog, Catalog1);

I prefer creating com objects like that
Avatar of datalabdd

ASKER

I tried every thing:
1.Catalog1.CubeDefs.Item[i]
2.Catalog1.CubeDefs.Items[i]
3.Catalog1.CubeDefs[i]
Nothing works.
In cases 1. and 2. i get [Error] Unit1.pas(57): Undeclared identifier: 'Item/Items'.
In case 3. i get [Error] Unit1.pas(57): Class does not have a default property.
It if  go trough the source of ADOmd_tlb.pas CubeDefs is declared like this:

CubeDefs = interface(MD_Collection)
    ['{2281375D-8BD3-11D0-B4EF-00A0C9138CA4}']
    function Get_Item(Index: OleVariant): CubeDef25; safecall;
    property Item[Index: OleVariant]: CubeDef25 read Get_Item; default;
end;
So it should clearly work with your code. But somehow it does not.
If i put my cursor at the end of the code and then the drop down menu is displayed, there are only few options available (none of them being Items). So there is probably something wrong with my system. I have  ADOMD_tlb in my uses class but still it doesnt work.
Thx 4 any help.

ASKER CERTIFIED SOLUTION
Avatar of Lee_Nover
Lee_Nover

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ive tried every thing. I just doesnt work. Instaled MDAC on different computer. But same error. Looks like im getting nowhere with this. Ive searched the web for a solution and found this:
...
Since ADO MD support in Delphi 5 was not implemented at the components level. We need to use the type library to access ADO MD objects. This type library resides in msadomd.dll file. To do so, choose the Project | Import Type Library command from the main menu and in the Import Type Library  dialog box select Microsoft Microsoft ActiveX Data Objects (Multi-dimensional) 1.0 Library.

If you have already imported ADOX type library, you need to avoid conflicts with already declared Delphi TCatalog class. In this case, just rename TCatalog into TADOMDCatalog. It is also better to uncheck the Generate Component Wrapper checkbox because we need only to create a *.pas file to access ADO MD objects. Then press the Create Unit button.
...

But this doesent solve my problem.
Ill give u the points since im sure that what u wrote is right.
have you checked for any conflicting units .. you might have a dcu lying around that has a bad declaration of CubeDefs
following the link to CubeDefs would still take you to the right source file while linking a wrong dcu
Hmmm ... i wouldnt know how to find this other declaration? I usualy just click the command or an object while holding down shift key and delphi takes me to the right file.  Is there any way to find double delarations?
that's for sources in the search path .. you can have a dcu in the library path and that's what will be compiled
just do a search for the dcu file
I have searched for adomd_tlb.dcu and only found one file.
I dont see how i could find out if there is another unit that has CubeDefs defined in it.
search in files *.pas;*.dcu for text CubeDefs ...
Ive searched the whole disk and only found 2 files that have cubedefs in them: adomd_tlb.pas and adomd_tlb.dcu. I performed the same search on another computer and the result was the same.
the interface that you wrote should work with any method I wrote (in the accepted answer)
I have no idea why you would get those compiler errors ... blame Delphi6 I guess