Board index » delphi » Q: Need help to add a field by DBIDoRestructure

Q: Need help to add a field by DBIDoRestructure

Hi,

i read one of your news in on of the Delphi-Newsgroups. May be you can help me
I want to ad a field to a Paradox table in Delphi 1.02. I know thaht it
should work with the DbiDoRestructure function but all my try's faild... :-(
Pls eMail me any hint....

Thanks in advance

    Andreas

--
Andreas.Kl...@e2.fh-friedberg.de
106360,2...@compuserve.com
Phone +49 (0) 6447 9229 63
Fax   +49 (0) 6447 9229 65

 

Re:Q: Need help to add a field by DBIDoRestructure


Andreas,

here's an alternative easier way: use 2 TTables, one dynamically created.
Copy the fielddefs and indexdefs from one to the other, now add a field to
the 2nd fielddef then use TTable.CreateTable!! - easy huh?

Only problem: CreateTable converts autoinc-->longint

here's some code:
unit Upd2;

interface

uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, DB, DBTables, StdCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    AddField: TButton;
    Table1: TTable;
    procedure AddFieldClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.AddFieldClick(Sender: TObject);
var Table2:TTable;
begin
      if not Table1.active then Table1.open;
      Table2:= TTable.create(nil);
      Table2.DataBaseName:= Table1.DataBaseName;
      Table2.TableType:= Table1.TableType;
      Table2.TableName:= Table1.TableName;
      Table2.exclusive:= true;
      Table1.FieldDefs.Update;
      Table2.FieldDefs.assign(Table1.FieldDefs);
      Table2.FieldDefs.Add('YourNewFieldName', ftString, 20, false);
      Table1.IndexDefs.Update;
      Table2.IndexDefs.assign(Table1.IndexDefs);
      Table2.CreateTable; {CreateTable converts autoinc-->longint}
                          {because it doesn't recognise autoinc}
      Table2.destroy;
end;

end.

--
Paul Motyer
pa...@linuxserver.pccity.com.au
SoftStuff, Croydon, Vic,  Australia, 3136.

Andreas Kloes <ark...@monet.fh-friedberg.de> wrote in article
<55pe1s$...@morisot.fh-friedberg.de>...

Quote
> Hi,

> i read one of your news in on of the Delphi-Newsgroups. May be you can
help me
> I want to ad a field to a Paradox table in Delphi 1.02. I know thaht it
> should work with the DbiDoRestructure function but all my try's faild...
:-(
> Pls eMail me any hint....

> Thanks in advance

>     Andreas

> --
> Andreas.Kl...@e2.fh-friedberg.de
> 106360,2...@compuserve.com
> Phone +49 (0) 6447 9229 63
> Fax   +49 (0) 6447 9229 65

Other Threads