Board index » delphi » ADOX, Creating a Primary Key for Access 2000 DB

ADOX, Creating a Primary Key for Access 2000 DB

I try to create a primary key for an Access 2000 DB using the imported ADOX
type library. The following code snippet causes a syntax error saying that
"no value can be assigned to a ReadOnly property".

The snippet from the type library (showing the _Index section) looks to me
as these properties should not be ReadOnly. At which point should I modify
the type library unit, so that I can assign values to these properties. Are
there other solutions ??

var
    idx_Primary : _Index;

(...)

idx_Primary := CoIndex.Create;
  with idx_Primary do begin
              Name := 'PrimaryKey';
              Primary := True;
              Unique := True;
end;

Snippet from the type library unit (ADOX_tlb.pas):

  // *********************************************************************//
  _Index = interface(IDispatch)
    ['{0000061F-0000-0010-8000-00AA006D2EA4}']
    function Get_Name: WideString; safecall;
    procedure Set_Name(const pVal: WideString); safecall;
    function Get_Clustered: WordBool; safecall;
    procedure Set_Clustered(pVal: WordBool); safecall;
    function Get_IndexNulls: AllowNullsEnum; safecall;
    procedure Set_IndexNulls(pVal: AllowNullsEnum); safecall;
    function Get_PrimaryKey: WordBool; safecall;
    procedure Set_PrimaryKey(pVal: WordBool); safecall;
    function Get_Unique: WordBool; safecall;
    procedure Set_Unique(pVal: WordBool); safecall;
    function Get_Columns: Columns; safecall;
    function Get_Properties: Properties; safecall;
    property Name: WideString read Get_Name write Set_Name;
    property Clustered: WordBool read Get_Clustered write Set_Clustered;
    property IndexNulls: AllowNullsEnum read Get_IndexNulls write
      Set_IndexNulls;
    property PrimaryKey: WordBool read Get_PrimaryKey write Set_PrimaryKey;
    property Unique: WordBool read Get_Unique write Set_Unique;
    property Columns: Columns read Get_Columns;
    property Properties: Properties read Get_Properties;
  end;

  // *********************************************************************//
  // DispIntf:  _IndexDisp
  // Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
  // GUID:      {0000061F-0000-0010-8000-00AA006D2EA4}
  // *********************************************************************//
  _IndexDisp = dispinterface
    ['{0000061F-0000-0010-8000-00AA006D2EA4}']
    property Name: WideString dispid 0;
    property Clustered: WordBool dispid 1;
    property IndexNulls: AllowNullsEnum dispid 2;
    property PrimaryKey: WordBool dispid 3;
    property Unique: WordBool dispid 4;
    property Columns: Columns readonly dispid 5;
    property Properties: Properties readonly dispid 6;
  end;

Any hints are greatly appreciated.

--
Thomas Glden
Geologist

Bayerisches Geologisches Landesamt
He?stra?e 128
80797 Mnchen
Germany

E-mail:    Thomas.Guel...@gla.bayern.de

 

Re:ADOX, Creating a Primary Key for Access 2000 DB


Don't mind...

The error resulted in ambiguity of the _Index definition. My application
uses both the DAO and the ADOX type libraries, in each of them the interface
_Index is defined. Whereas in ADOX   _Index is ReadWrite, it is ReadOnly in
DAO.

QUESTION:  Why are some properties imported as ReadOnly, where they should
be in fact ReadWrite ? For example _Field.Name seems to be ReadOnly, but DDL
definitely requires ReadWrite.

Kind regards

--
Thomas Glden
Geologist

Bayerisches Geologisches Landesamt
He?stra?e 128
80797 Mnchen
Germany

E-mail:    Thomas.Guel...@gla.bayern.de

"Thomas Glden" <thomasgul...@csi.com> schrieb im Newsbeitrag
news:86fpvh$los8@bornews.borland.com...

Quote
> I try to create a primary key for an Access 2000 DB using the imported
ADOX
> type library. The following code snippet causes a syntax error saying that
> "no value can be assigned to a ReadOnly property".

> The snippet from the type library (showing the _Index section) looks to me
> as these properties should not be ReadOnly. At which point should I modify
> the type library unit, so that I can assign values to these properties.
Are
> there other solutions ??

> var
>     idx_Primary : _Index;

> (...)

> idx_Primary := CoIndex.Create;
>   with idx_Primary do begin
>               Name := 'PrimaryKey';
>               Primary := True;
>               Unique := True;
> end;

> Snippet from the type library unit (ADOX_tlb.pas):

>   //

*********************************************************************//

- Show quoted text -

Quote
>   _Index = interface(IDispatch)
>     ['{0000061F-0000-0010-8000-00AA006D2EA4}']
>     function Get_Name: WideString; safecall;
>     procedure Set_Name(const pVal: WideString); safecall;
>     function Get_Clustered: WordBool; safecall;
>     procedure Set_Clustered(pVal: WordBool); safecall;
>     function Get_IndexNulls: AllowNullsEnum; safecall;
>     procedure Set_IndexNulls(pVal: AllowNullsEnum); safecall;
>     function Get_PrimaryKey: WordBool; safecall;
>     procedure Set_PrimaryKey(pVal: WordBool); safecall;
>     function Get_Unique: WordBool; safecall;
>     procedure Set_Unique(pVal: WordBool); safecall;
>     function Get_Columns: Columns; safecall;
>     function Get_Properties: Properties; safecall;
>     property Name: WideString read Get_Name write Set_Name;
>     property Clustered: WordBool read Get_Clustered write Set_Clustered;
>     property IndexNulls: AllowNullsEnum read Get_IndexNulls write
>       Set_IndexNulls;
>     property PrimaryKey: WordBool read Get_PrimaryKey write
Set_PrimaryKey;
>     property Unique: WordBool read Get_Unique write Set_Unique;
>     property Columns: Columns read Get_Columns;
>     property Properties: Properties read Get_Properties;
>   end;

>   //

*********************************************************************//
Quote
>   // DispIntf:  _IndexDisp
>   // Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
>   // GUID:      {0000061F-0000-0010-8000-00AA006D2EA4}
>   //

*********************************************************************//

- Show quoted text -

Quote
>   _IndexDisp = dispinterface
>     ['{0000061F-0000-0010-8000-00AA006D2EA4}']
>     property Name: WideString dispid 0;
>     property Clustered: WordBool dispid 1;
>     property IndexNulls: AllowNullsEnum dispid 2;
>     property PrimaryKey: WordBool dispid 3;
>     property Unique: WordBool dispid 4;
>     property Columns: Columns readonly dispid 5;
>     property Properties: Properties readonly dispid 6;
>   end;

> Any hints are greatly appreciated.

> --
> Thomas Glden
> Geologist

> Bayerisches Geologisches Landesamt
> He?stra?e 128
> 80797 Mnchen
> Germany

> E-mail:    Thomas.Guel...@gla.bayern.de

Re:ADOX, Creating a Primary Key for Access 2000 DB


I struggled with this same problem for a good part of the day today.  Adding
an index is fairly simple using the catalog and the Indexes collection of
the _Table object.  I finally discovered the Keys collection of the _Table
object.  Use the Append method of the Keys collection to add a primary key
to a table.  The syntax is something like this if I can force my somewhat
fried brain to recall:

ADOXTable.Keys.Append('KeyName', adKeyPrimary, 'ColName');

{there might be other parms I've forgotten}

--

==================================
Ray Porter
dra...@email.unc.edu
lrpor...@mindspring.com
ray_por...@unc.edu
http://www.unc.edu/~dragon/
CHAOS Home Page: http://www.unc.edu/~dragon/chaos/

"Meddle not in the affairs of dragons,
for thou art crunchy and taste good with ketchup"

Quote
Thomas Glden <thomasgul...@csi.com> wrote in message

news:86fpvh$los8@bornews.borland.com...
Quote
> I try to create a primary key for an Access 2000 DB using the imported
ADOX
> type library. The following code snippet causes a syntax error saying that
> "no value can be assigned to a ReadOnly property".

> The snippet from the type library (showing the _Index section) looks to me
> as these properties should not be ReadOnly. At which point should I modify
> the type library unit, so that I can assign values to these properties.
Are
> there other solutions ??

> var
>     idx_Primary : _Index;

> (...)

> idx_Primary := CoIndex.Create;
>   with idx_Primary do begin
>               Name := 'PrimaryKey';
>               Primary := True;
>               Unique := True;
> end;

> Snippet from the type library unit (ADOX_tlb.pas):

>   //

*********************************************************************//

- Show quoted text -

Quote
>   _Index = interface(IDispatch)
>     ['{0000061F-0000-0010-8000-00AA006D2EA4}']
>     function Get_Name: WideString; safecall;
>     procedure Set_Name(const pVal: WideString); safecall;
>     function Get_Clustered: WordBool; safecall;
>     procedure Set_Clustered(pVal: WordBool); safecall;
>     function Get_IndexNulls: AllowNullsEnum; safecall;
>     procedure Set_IndexNulls(pVal: AllowNullsEnum); safecall;
>     function Get_PrimaryKey: WordBool; safecall;
>     procedure Set_PrimaryKey(pVal: WordBool); safecall;
>     function Get_Unique: WordBool; safecall;
>     procedure Set_Unique(pVal: WordBool); safecall;
>     function Get_Columns: Columns; safecall;
>     function Get_Properties: Properties; safecall;
>     property Name: WideString read Get_Name write Set_Name;
>     property Clustered: WordBool read Get_Clustered write Set_Clustered;
>     property IndexNulls: AllowNullsEnum read Get_IndexNulls write
>       Set_IndexNulls;
>     property PrimaryKey: WordBool read Get_PrimaryKey write
Set_PrimaryKey;
>     property Unique: WordBool read Get_Unique write Set_Unique;
>     property Columns: Columns read Get_Columns;
>     property Properties: Properties read Get_Properties;
>   end;

>   //

*********************************************************************//
Quote
>   // DispIntf:  _IndexDisp
>   // Flags:     (4544) Dual NonExtensible OleAutomation Dispatchable
>   // GUID:      {0000061F-0000-0010-8000-00AA006D2EA4}
>   //

*********************************************************************//

- Show quoted text -

Quote
>   _IndexDisp = dispinterface
>     ['{0000061F-0000-0010-8000-00AA006D2EA4}']
>     property Name: WideString dispid 0;
>     property Clustered: WordBool dispid 1;
>     property IndexNulls: AllowNullsEnum dispid 2;
>     property PrimaryKey: WordBool dispid 3;
>     property Unique: WordBool dispid 4;
>     property Columns: Columns readonly dispid 5;
>     property Properties: Properties readonly dispid 6;
>   end;

> Any hints are greatly appreciated.

> --
> Thomas Glden
> Geologist

> Bayerisches Geologisches Landesamt
> He?stra?e 128
> 80797 Mnchen
> Germany

> E-mail:    Thomas.Guel...@gla.bayern.de

Other Threads