Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Moving Fields
Mon, Mar 27 2006 3:13 AMPermanent Link

"Jeremy Martin"

Hi,

Using the latest version of DBISAM and am trying to move fields in a
different order using the following code found on ng



with MyTable do
   begin
   FieldDefs.Update;
   IndexDefs.Update;
   if (<NewPosition> > <OldPosition>) then
      begin

FieldDefs.InsertFieldDef(<NewPosition>).Assign(FieldDefs[<OldPosition>];
      FieldDefs.Delete(<OldPosition>);
      end
   else
      begin

FieldDefs.InsertFieldDef(<NewPosition>).Assign(FieldDefs[<OldPosition>+1
];
      FieldDefs.Delete(<OldPosition>+1);
      end;
   AlterTable(....rest of parameters here);
   end;
  



Problem is when you try and insertfielddef we get the following error


A component with the name "FIELDNAME" already exists

Any help appreciated

Regards
Jeremy
Mon, Mar 27 2006 3:34 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Jeremy


Do the delete before the insert?

Better still use SQL for it - much better syntax and a lot easier.

Roy Lambert
Mon, Mar 27 2006 3:15 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Jeremy,

<< Problem is when you try and insertfielddef we get the following error

A component with the name "FIELDNAME" already exists >>

Roy is correct.  When moving field definitions around, you must delete the
existing field definition before adding/inserting the new one.

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Mar 27 2006 4:15 PMPermanent Link

"Iztok Lajovic"
Jeremy,

you can alter position of field (i.e. moving it to another position in
table) without loosing its content by SQL statement (example shows moving a
column named aColumn, which is a smallint type, to new position 5 regardless
where it was before - tested with DBSYS):

alter table myTable
redefine aColumn smallint at 5

HTH
Iztok Lajovic


"Jeremy Martin" <jeremy at lanwest dot com dot au> je napisal v sporocilo
news:7609C7A5-93B2-47A9-B09C-019CC3E73DA3@news.elevatesoft.com ...
>
> Hi,
>
> Using the latest version of DBISAM and am trying to move fields in a
> different order using the following code found on ng
>
>
>
> with MyTable do
>    begin
>    FieldDefs.Update;
>    IndexDefs.Update;
>    if (<NewPosition> > <OldPosition>) then
>       begin
>
> FieldDefs.InsertFieldDef(<NewPosition>).Assign(FieldDefs[<OldPosition>];
>       FieldDefs.Delete(<OldPosition>);
>       end
>    else
>       begin
>
> FieldDefs.InsertFieldDef(<NewPosition>).Assign(FieldDefs[<OldPosition>+1
> ];
>       FieldDefs.Delete(<OldPosition>+1);
>       end;
>    AlterTable(....rest of parameters here);
>    end;
>
>
>
>
> Problem is when you try and insertfielddef we get the following error
>
>
> A component with the name "FIELDNAME" already exists
>
> Any help appreciated
>
> Regards
> Jeremy

Image