Board index » delphi » Changing record positions in a TTable Question

Changing record positions in a TTable Question

I need to change the position of records in a table. For
example, (and arguments sake) Say I create a form with a
Table, Datasource component linked to a Database (paradox 5.0),
two DBEdit fields (linked to Name & Phone number) and a Navbar.

OK, now if I have John, Jane, and Mike in this order in the
table, what on click event should I add to a button to move the
BOF record (John) to the the EOF record (Mike) and move all the
other records up one. This would leave the records in this
order, Jane, Mike, John.

Just so you know I am trying to create a rotating list of
employees to call in for overtime. The place I work utilizes
full time employees for this but it is based on a rotating
schedule, Hence the database.

Any help would be greatly appreciated! BTW anyone also know how
to identify an empty table ie.

if Table1.Empty = True then
Showmessage ('It's all gone Pal!');

Email Zor...@Inetw.net

 

Re:Changing record positions in a TTable Question


In <4785lt$...@news.atlantic.net> Mike Cox <zor...@Inetw.net> writes:
Quote

>I need to change the position of records in a table. For
>example, (and arguments sake) Say I create a form with a
>Table, Datasource component linked to a Database (paradox 5.0),
>two DBEdit fields (linked to Name & Phone number) and a Navbar.

>OK, now if I have John, Jane, and Mike in this order in the
>table, what on click event should I add to a button to move the
>BOF record (John) to the the EOF record (Mike) and move all the
>other records up one. This would leave the records in this
>order, Jane, Mike, John.

>Just so you know I am trying to create a rotating list of
>employees to call in for overtime. The place I work utilizes
>full time employees for this but it is based on a rotating
>schedule, Hence the database.

>Any help would be greatly appreciated! BTW anyone also know how
>to identify an empty table ie.

>if Table1.Empty = True then
>Showmessage ('It's all gone Pal!');

>Email Zor...@Inetw.net

In is totally unnecessary to change the order of records in the core
file as records are not accessed during normal operation based on the
way they reside in the core file.  An index is always used in indexed
sequential files such as Paradox databases.  If you want your records
read and dispalyed in a certain way just specify that particular field
as an index or secondary index as the case may be.  If you primarily
access that file in this order you may specify that index as the
default index in the object inspector for the index property of tTable.
 You can then access the records in the file via that index without
specifying that index in your code.  To change to another index all you
do is put down:  Table1.Index := ......; before your findkey command in
your code.

As to check for an empty file just put the following code in the
AfterOpen even for your tTable.

if Table1.fieldByName('......').asString = '' then
showMessage('Go Fly A Kite');

that's it.  Just make sure that Dialogs is listed in the uses clause
for the form.

I tried E Mailing direct to you but you mailman had some problem
delivering.

Good Luck
Ben
Arrow

Re:Changing record positions in a TTable Question


Quote
arr...@ix.netcom.com (Arrow ) wrote:
>In <4785lt$...@news.atlantic.net> Mike Cox <zor...@Inetw.net> writes:
>>I need to change the position of records in a table.
>>Just so you know I am trying to create a rotating list of
>>employees to call in for overtime.
>In is totally unnecessary to change the order of records in the core
>file as records are not accessed during normal operation based on the
>way they reside in the core file.  An index is always used in indexed
>sequential files such as Paradox databases.  If you want your records
>read and dispalyed in a certain way just specify that particular field
>as an index or secondary index as the case may be.

Yup, I can go for that, but the point I think you failed to explain was which
field would make a good key. My tuppence worth is to suggest that Mike includes
a?date for the last time each employee worked overtime, and sorts by that.

Felt it needed saying.

J.

--
Justin G Otto - Sarcasm Therapist: Kids parties a speciality.
http://http2.brunel.ac.uk:8080/~cs92jgo
Mobile:(0585)065041

Re:Changing record positions in a TTable Question


Quote
In article <4785lt$...@news.atlantic.net>, Mike Cox <zor...@Inetw.net> wrote:
>I need to change the position of records in a table. For
>example, (and arguments sake) Say I create a form with a
>Table, Datasource component linked to a Database (paradox 5.0),
>two DBEdit fields (linked to Name & Phone number) and a Navbar.

>OK, now if I have John, Jane, and Mike in this order in the
>table, what on click event should I add to a button to move the
>BOF record (John) to the the EOF record (Mike) and move all the
>other records up one. This would leave the records in this
>order, Jane, Mike, John.

My suggestion would be to have the table ordered on some index.  Changing the
index value for a record would then change the records position in the table.

There may ne some faffing around needed to make sure you don't get two indexs
the same, but this is the only way I can think of.

Sean

Other Threads