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( StringToGU ID('ADOMD. Catalog')) as ICatalog;
Catalog1.Set_ActiveConnect ion(OleVar iant(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(n il, 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.
Ive installed MDAC components to gain access to olap cubes(with D6). Im using the following code to do that:
procedure TForm1.CubeList(DataSource
var I : Integer;
DS : WideString;
Catalog1 : ICatalog;
CubeDef1 : CubeDef;
begin
Catalog1:=CreateComObject(
Catalog1.Set_ActiveConnect
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(n
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.
you can also be more specific (and more optimized code) and do:
CoCreateInstance(CLASS_Cat alog, nil, CLSCTX_INPROC_SERVER or
CLSCTX_LOCAL_SERVER, IID_ICatalog, Catalog1);
I prefer creating com objects like that
CoCreateInstance(CLASS_Cat
CLSCTX_LOCAL_SERVER, IID_ICatalog, Catalog1);
I prefer creating com objects like that
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 -00A0C9138 CA4}']
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.
1.Catalog1.CubeDefs.Item[i
2.Catalog1.CubeDefs.Items[
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
...
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
following the link to CubeDefs would still take you to the right source file while linking a wrong dcu
ASKER
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
just do a search for the dcu file
ASKER
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.
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 ...
ASKER
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
I have no idea why you would get those compiler errors ... blame Delphi6 I guess
the compiler error was a big clue .. don't you think ?
also TheSource and CodeInsight are your friends :)