Paradox Community

Items in pnews.paradox-programming

Subject:Re: Bet way to remove fields from a table?
Date:12 May 2021 00:10:10 -0400
From:"Kevin Zawicki" <numberjack@wi.rr.com>
Newsgroups:pnews.paradox-programming



if you copyFromArray to table, only matched elements to fields will attempt
to copy.


if you really need to do it...
something like this

(pseudo code)
method run(var eventInfo Event)
 var
  fld  string
  dynA dynarray[] anytype
  dynB dynarray[] anytype
  tc   tcursor
 endvar

 tc.open(myTable)

 forEach fld in dynA
  if tc.fieldNo(fld) = 0 then
   dynA.removeItem(fld)    ;//unassign does not exactly work here, it removes
the value but leave a n/a element
   errorclear()
  endif
 endForEach


 ;// or


 ;//transfer only what is needed to new dynarray
 forEach fld in dynA
  if tc.fieldNo(fld) > 0 then
   dynB[fld] = dynA[fld]
  else
   errorclear()
  endif
 endForEach

 ;//then use dynA to copy from


 ;// you can also enumfueldstruct of the tcursor and step through the array
and remove as needed

endMethod




Jim Short <jim@tahlinc.com> wrote:
>Too many unused fields
>
>OUTLINE
>
>const
>tbl1 = ":NABLES:CusPart"
>tbl2 = ":NTABLES:CuspartA"
>endconst
>
>var
>tc1, tc2 tcursor
>dyAr dynarray[] Anytype
>endvar
>
>tc1.open(tbl1)
>tc2.open(tbl2)
>tc2.edit()
>
>scan tc1:
>tc1.copyToArray(dyAr)
>dyAr.removeItem("FieldName")
>tc2.insertRecord()
>tc2.copyFromArray(dAR)
>tc2.unlockRecord()
>endscan
>
>tc1.close()
>tc2.close()


Copyright © 2004 thedbcommunity.com