Board index » delphi » Help with dbiDoRestructure example?

Help with dbiDoRestructure example?

Using Delphi 5.01 and Paradox

1. I added the following procedure to the Public section.  procedure
AddField(Table: TTable; NewField: ChangeRec); Where should I declare the
code below? ChangeRec is giving me an "Undeclared Identifier" error when I
compile it in the IDE? I added BDE to my uses clause.

type
    ChangeRec = packed record
    szName: DBINAME;
    iType: word;
    iSubType: word;
    iLength: word;
    iPrecision: byte;
    file://end;

2. I'm attempting to use the #10 example from the link below to modify an
existing database structure. I want the newly "Added" field to be the 1st
field in the database. The example adds the new field to end of the table.
How do I accomplish adding the new field as the 1st field using the #10
example? http://www.borland.com/devsupport/bde/bdeapiex/index.html

Thanks,
Ernie B.

 

Re:Help with dbiDoRestructure example?


Quote
>1. I added the following procedure to the Public section.  procedure
>AddField(Table: TTable; NewField: ChangeRec); Where should I declare the
>code below? ChangeRec is giving me an "Undeclared Identifier" error when I
>compile it in the IDE? I added BDE to my uses clause.

>type
>    ChangeRec = packed record
>    szName: DBINAME;
>    iType: word;
>    iSubType: word;
>    iLength: word;
>    iPrecision: byte;
>    file://end;

I am not sure where the last line of your code came from but the code out of the
example compiles find for me with just BDE added to the uses

Quote

>2. I'm attempting to use the #10 example from the link below to modify an
>existing database structure. I want the newly "Added" field to be the 1st
>field in the database. The example adds the new field to end of the table.
>How do I accomplish adding the new field as the 1st field using the #10
>example? http://www.borland.com/devsupport/bde/bdeapiex/index.html

If you look at the example there is a For loop that copies each of the existing
fields and assigns it  a number.  After the FOR loop the new field is added and
the number is set to the next number.  You need to reverse this so that the new
field gets assigned the first number.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Help with dbiDoRestructure example?


Quote
"Ernest Brackett" <ebs...@gis.net> wrote in message

news:983akk$62m3@bornews.inprise.com...

Quote
> Using Delphi 5.01 and Paradox

> 1. I added the following procedure to the Public section.
procedure
> AddField(Table: TTable; NewField: ChangeRec); Where should I
declare the
> code below? ChangeRec is giving me an "Undeclared Identifier"
error when I
> compile it in the IDE? I added BDE to my uses clause.

> type
>     ChangeRec = packed record
>     szName: DBINAME;
>     iType: word;
>     iSubType: word;
>     iLength: word;
>     iPrecision: byte;
>     file://end;

My guess is that you put this declaration after the AddField
declaration. Change that.

Quote
> 2. I'm attempting to use the #10 example from the link below to
modify an
> existing database structure. I want the newly "Added" field to
be the 1st
> field in the database. The example adds the new field to end of
the table.
> How do I accomplish adding the new field as the 1st field using
the #10
> example?

http://www.borland.com/devsupport/bde/bdeapiex/index.html

Well, these examples can't help you there. If you don't mind
shareware, check out my TRestructure Pro component at

http://sedlan.com/table_restructure.php

With TRestructure Pro, you can add, insert (at any position),
change, move and delete fields, add, change or delete validity
checks, table lookups, add or remove referential integrity
constraints, add, change or delete primary index and add, change
or delete main and auxiliary passwords.

There's a trial version available for download. Examples of it's
use are at

http://sedlan.com/tr_easy.php

--
Jovan Sedlan
i...@sedlan.com
http://www.sedlan.com
#7 Components Home

Re:Help with dbiDoRestructure example?


Brian Bushay TeamB <BBus...@Nmpls.com> wrote in message
news:aq0batks4rsfs8rfcdh65gl9766f1li5nl@4ax.com...

Quote
> If you look at the example there is a For loop that copies each of the
existing
> fields and assigns it  a number.  After the FOR loop the new field is
added and
> the number is set to the next number.  You need to reverse this so that
the new
> field gets assigned the first number.

Thanks for the help, I got everything working EXCEPT the field is always
added as the last. I'm not sure I understand how to "reverse" the code to
add the "new" field as the first.  My attempts thus far have not worked. I
know this is probably easy but I haven't been able to get it. How do I
reverse it?

 for B := 1 to Table.FieldCount do begin
    pFlds^.iFldNum := B;
    Inc(pFlds, 1);
  end;
  try
    StrCopy(pFlds^.szName, NewField.szName);
    pFlds^.iFldType := NewField.iType;
    pFlds^.iSubType := NewField.iSubType;
    pFlds^.iUnits1  := NewField.iLength;
    pFlds^.iUnits2  := NewField.iPrecision;
    pFlds^.iFldNum  := Table.FieldCount + 1;
  finally
    Dec(pFlds, Table.FieldCount);
  end;

Thanks,
Ernie B.

Re:Help with dbiDoRestructure example?


When you want to insert a field to a specific position, you have
to do a little memory juggling with pFlds, i.e. place it where
you want the new field to be, don't just add it to the end of
pFlds^ array. I have learned this the hard way while developing
my TRestructure Pro component. You can take a look at it's
features at
http://sedlan.com/table_restructure.php

--
Jovan Sedlan
i...@sedlan.com
http://www.sedlan.com
#7 Components Home

Quote
"Ernest Brackett" <ebs...@gis.net> wrote in message

news:989epu$e9g1@bornews.inprise.com...
Quote

> Brian Bushay TeamB <BBus...@Nmpls.com> wrote in message
> news:aq0batks4rsfs8rfcdh65gl9766f1li5nl@4ax.com...
> > If you look at the example there is a For loop that copies
each of the
> existing
> > fields and assigns it  a number.  After the FOR loop the new
field is
> added and
> > the number is set to the next number.  You need to reverse
this so that
> the new
> > field gets assigned the first number.

> Thanks for the help, I got everything working EXCEPT the field
is always
> added as the last. I'm not sure I understand how to "reverse"
the code to
> add the "new" field as the first.  My attempts thus far have
not worked. I
> know this is probably easy but I haven't been able to get it.
How do I
> reverse it?

>  for B := 1 to Table.FieldCount do begin
>     pFlds^.iFldNum := B;
>     Inc(pFlds, 1);
>   end;
>   try
>     StrCopy(pFlds^.szName, NewField.szName);
>     pFlds^.iFldType := NewField.iType;
>     pFlds^.iSubType := NewField.iSubType;
>     pFlds^.iUnits1  := NewField.iLength;
>     pFlds^.iUnits2  := NewField.iPrecision;
>     pFlds^.iFldNum  := Table.FieldCount + 1;
>   finally
>     Dec(pFlds, Table.FieldCount);
>   end;

> Thanks,
> Ernie B.

Re:Help with dbiDoRestructure example?


Quote
> for B := 1 to Table.FieldCount do begin
>    pFlds^.iFldNum := B;
>    Inc(pFlds, 1);
>  end;
>  try
>    StrCopy(pFlds^.szName, NewField.szName);
>    pFlds^.iFldType := NewField.iType;
>    pFlds^.iSubType := NewField.iSubType;
>    pFlds^.iUnits1  := NewField.iLength;
>    pFlds^.iUnits2  := NewField.iPrecision;
>    pFlds^.iFldNum  := Table.FieldCount + 1;
>  finally
>    Dec(pFlds, Table.FieldCount);
>  end;

something like
 for B := 1 to Table.FieldCount do begin
    pFlds^.iFldNum := B+1;
    Inc(pFlds, 1);
  end;
  try
    StrCopy(pFlds^.szName, NewField.szName);
    pFlds^.iFldType := NewField.iType;
    pFlds^.iSubType := NewField.iSubType;
    pFlds^.iUnits1  := NewField.iLength;
    pFlds^.iUnits2  := NewField.iPrecision;
    pFlds^.iFldNum  :=  1;
  finally

Quote
>    Dec(pFlds, Table.FieldCount);
>  end;

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Help with dbiDoRestructure example?


Brian Bushay TeamB <BBus...@Nmpls.com> wrote in message
news:1a1jatgaim70sd7os5t5042dvg1pvt03ki@4ax.com...

Quote
> something like
>  for B := 1 to Table.FieldCount do begin
>     pFlds^.iFldNum := B+1;
>     Inc(pFlds, 1);
>   end;
>   try
>     StrCopy(pFlds^.szName, NewField.szName);
>     pFlds^.iFldType := NewField.iType;
>     pFlds^.iSubType := NewField.iSubType;
>     pFlds^.iUnits1  := NewField.iLength;
>     pFlds^.iUnits2  := NewField.iPrecision;
>     pFlds^.iFldNum  :=  1;
>   finally
> >    Dec(pFlds, Table.FieldCount);
> >  end;

First, thank you. I appreciate the help, the above code gives an "Invalid
Field Descriptor" error. I tried everything I can think of to modify the "
Newfield"  iFldNum position. If "B" starts with anything other than "1" it
generates the above error.

From the BDE Help :
"pFLDDesc pfldDesc Optional; used if the record structure is changing.
Specifies an array of physical field descriptors for the new record
structure. ifldNum in each pfldDesc must be 0 if the field is added.
Otherwise, it must contain the field position (1 to n) in the old record
structures. If a field is dropped, its descriptor is simply left out of the
new record structure. Additionally, any changes to dependent objects are
made automatically (that is, all single field indexes, validity checks, and
auxiliary passwords are dropped)."

Not sure if this is the problem, after reading it I'm not sure if I
understand it :)

Thanks again,
Ernie B.

Re:Help with dbiDoRestructure example?


Quote
>First, thank you. I appreciate the help, the above code gives an "Invalid
>Field Descriptor" error. I tried everything I can think of to modify the "
>Newfield"  iFldNum position. If "B" starts with anything other than "1" it
>generates the above error.

At this point I will just refer you to this utility
http://www.rksolution.cz/delphi/pxupgr.htm

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Help with dbiDoRestructure example?


Check out my TRestructure Pro at

http://sedlan.com/table_restructure.php

--
Jovan Sedlan
i...@sedlan.com
http://www.sedlan.com
#7 Components Home

Quote
"Ernest Brackett" <ebs...@gis.net> wrote in message

news:98k00l$e9q6@bornews.inprise.com...
Quote
> Brian Bushay TeamB <BBus...@Nmpls.com> wrote in message
> news:1a1jatgaim70sd7os5t5042dvg1pvt03ki@4ax.com...
> > something like
> >  for B := 1 to Table.FieldCount do begin
> >     pFlds^.iFldNum := B+1;
> >     Inc(pFlds, 1);
> >   end;
> >   try
> >     StrCopy(pFlds^.szName, NewField.szName);
> >     pFlds^.iFldType := NewField.iType;
> >     pFlds^.iSubType := NewField.iSubType;
> >     pFlds^.iUnits1  := NewField.iLength;
> >     pFlds^.iUnits2  := NewField.iPrecision;
> >     pFlds^.iFldNum  :=  1;
> >   finally
> > >    Dec(pFlds, Table.FieldCount);
> > >  end;

> First, thank you. I appreciate the help, the above code gives
an "Invalid
> Field Descriptor" error. I tried everything I can think of to
modify the "
> Newfield"  iFldNum position. If "B" starts with anything other
than "1" it
> generates the above error.

> From the BDE Help :
> "pFLDDesc pfldDesc Optional; used if the record structure is
changing.
> Specifies an array of physical field descriptors for the new
record
> structure. ifldNum in each pfldDesc must be 0 if the field is
added.
> Otherwise, it must contain the field position (1 to n) in the
old record
> structures. If a field is dropped, its descriptor is simply
left out of the
> new record structure. Additionally, any changes to dependent
objects are
> made automatically (that is, all single field indexes, validity
checks, and
> auxiliary passwords are dropped)."

> Not sure if this is the problem, after reading it I'm not sure
if I
> understand it :)

> Thanks again,
> Ernie B.

Other Threads