Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Delphi (http://www.programmingforums.org/forum41.html)
-   -   Index in a table (http://www.programmingforums.org/showthread.php?t=5470)

gj15987 Aug 19th, 2005 3:36 PM

Index in a table
 
How do I create an index to sort a table?! I have created an index using Database desktop, which is what I used to create the tables. However when I add a new record it then tells me that the index is out of date.

If you've read in my other post in the Working projects forum you'll know that I need to sort clock in/ out records so that when searching it will come to the newest first.

DaWei Aug 19th, 2005 3:52 PM

Don't make me want to install Delphi, now :D.

Ooble Aug 19th, 2005 4:00 PM

Quote:

Originally Posted by DaWei
Don't make me want to install Delphi, now :D.

You don't wanna do that. It's evil. Evil, I tells ya!

GJ, are you using some weird Delphi controls to interface with the database, or are you using SQL connectors? What database are you using, anyway?

gj15987 Aug 19th, 2005 4:41 PM

Hmmm...I'm using sql to update and add records on the clock in thingy. But to access the table data I'm placing the delphi TTable things on the page and then using things like table1.open, table1.next etc to search through them and stuff.

the databases are paradox 7...don't know why..thats just what the teacher told us to use at college.

Ooble Aug 19th, 2005 4:46 PM

Damn... I cannot for the life of me remember how to work databases in Delphi...

gj15987 Aug 19th, 2005 6:16 PM

Sokay...I have yet again recided to think of another way to clock in without sorting them and I think I've found a way that's simple and that works. I'll post it when I've tested it n stuff.

Ooble Aug 19th, 2005 7:34 PM

Glad to hear it.

gj15987 Aug 20th, 2005 6:06 AM

WOOOHOOO!!! Ok, this works! :D I've tried all possible cases and it works! :D

I took your idea into acount Ooble, and had a field called Active in the shift table. When no active shift is found for that employee it creates a record and sets the active field to true. Then when searching again it finds the true value and clocks it out! :D This is so much simpler than what I was trying to do before! lol

:

procedure Tfrm_clock_In.btn_enterClick(Sender: TObject);
var
        Executed:boolean;
        found:boolean;
begin
found:=false;
Executed:=false;
tbl_employees.Open;
tbl_employees.First;
Repeat
        If (Tbl_EmployeesEmployee_ID.value = strtoint(Edit_Employee_ID.text)) then
          begin
                found:=true;
                showmessage('found employee');
                Tbl_shift.Open;
                Tbl_shift.first;
                Repeat
                        If (Tbl_shiftEmployee_ID.value = strtoint(Edit_Employee_ID.text)) and (tbl_shiftActive.value=true) then
                                begin
                                        //Clock out
                                        Executed:=true;
                                        showmessage('Clocked Out')
                                end
                        else begin tbl_shift.next; showmessage('Shift Next'); end;
                Until (tbl_shift.Eof) or (executed=true);
          end
        else begin tbl_employees.Next; showmessage('employees next'); end;
Until (found = true) or (tbl_employees.Eof);

if tbl_employees.Eof then showmessage('Invalid Employee ID');

If tbl_shift.eof then
        begin
                //clock in
                showmessage('Clocked In');
        end;

end;


Ooble Aug 20th, 2005 6:16 AM

Congrats, mate. That reminds me... I really should get on with my Year 13 coursework...

gj15987 Aug 20th, 2005 7:27 AM

Tried and tested and it works perfectly! I had to add a shift_ID field to the shift table so that the sql didn't update every field when clocking out.

Really though...Ooble, are you like a child prodigy? When did you start programming? You're miles ahead of me and we're in the same year! lol.


All times are GMT -5. The time now is 9:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC