Board index » delphi » Allow zero length = True when creating Access table

Allow zero length = True when creating Access table

I am creating an Access table in a Delphi program using SQL and all
works well.  But when I create string fields for new tables from within
Access I often want to set Allow zero length = True.  Can I do this for
string fields created by my Delphi application?  Thanks.
 

Re:Allow zero length = True when creating Access table


Hi,

Yes, this can be done, but you first have to Import the ADOX type library.

Once you done that, include in your uses the newly created unit ADOX_TLB;

Here's some sample code for you to achieve what you're trying to do:

procedure SetZeroLength;
var
  Catalog: _Catalog;
  I, J: Integer;
begin
    Catalog := CoCatalog.Create;
    Catalog.Set_ActiveConnection(MyConnectionString);  // a valid connection
string

    // Loop through the tables to find the table in which the field you
wanna modify exists
    I := 0;
    while (Catalog.Tables[I].Name <> MyTable) do
        Inc(I);

    with Catalog.Tables[I] do begin
        // Now, iterate through the table's columns to find the specific
column
        J := 0;
        while (Columns[J].Name <> MyColumn
          Inc(J);
        Columns[J].Properties['Jet OLEDB:Allow Zero Length'].Value := True;
    end;
end;

Hope this helps,
Joe.

"Thomas J. Theimer" <tthei...@TheTechPart.com> wrote in message
news:3C45AFFF.4AA09886@TheTechPart.com...

Quote
> I am creating an Access table in a Delphi program using SQL and all
> works well.  But when I create string fields for new tables from within
> Access I often want to set Allow zero length = True.  Can I do this for
> string fields created by my Delphi application?  Thanks.

Re:Allow zero length = True when creating Access table


Hi Joe,

Quote
>     // Loop through the tables to find the table in which the field
you
> wanna modify exists
>     I := 0;
>     while (Catalog.Tables[I].Name <> MyTable) do
>         Inc(I);

If you just created the table and the field (and thus you know they
exist), you can use this simpler code:

Catalog1.Tables['TheTableName'].Columns['TheColumName'].Properties['Jet
OLEDB:Allow Zero Length'].Value = True;

Thrse

Re:Allow zero length = True when creating Access table


Thanks Thrse.

I did not know you could refer to the names directly like that.

It's hard to find good documentation these days! hehe

Quote
"Thrse Hanquet" <therese.hanq...@skynet.be> wrote in message

news:3c45efbf$1_1@dnews...
Quote
> Hi Joe,

> >     // Loop through the tables to find the table in which the field
> you
> > wanna modify exists
> >     I := 0;
> >     while (Catalog.Tables[I].Name <> MyTable) do
> >         Inc(I);

> If you just created the table and the field (and thus you know they
> exist), you can use this simpler code:

> Catalog1.Tables['TheTableName'].Columns['TheColumName'].Properties['Jet
> OLEDB:Allow Zero Length'].Value = True;

> Thrse

Other Threads