Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 8th, 2005, 1:44 PM   #1
Monkey_features
Newbie
 
Monkey_features's Avatar
 
Join Date: Feb 2005
Posts: 15
Rep Power: 0 Monkey_features is on a distinguished road
Help on Q..

Hey,

I'm doing computing at AS level, this is the problem i have been given:

Implement in Delphi a simple search and retrieval system for the CAR.dat file. A form will permit the user to enter car registration details, the data will be added to the file. The form should also allow the user to search for a given car, using the registration number, and then display the record details for that car.

Adding a record i can do but... for the search part, do you know how i'm supposed to associate the car registration number with the address that the record is at in the car.dat file? Because i can't work it out - i'm using the 'seek' function to look up the file like this:

AssignFile(carfile, 'car.dat');
Reset(carfile);
Seek(carfile, Edit1.text);

(edit1 being the edit box used for typing in the car registration number) I thought that because normally, you would put in where i have put in 'edit1.text' the address which you want to look up, i would be able to use the data from a edit box to search the file...

Another possible problem could be that i'm searching the file in the wrong format - the information typed into the edit box is in a string and the information is held in binary or something like that...

btw, this is the error message i get:

[Error] Unit1.pas(52): Incompatible types
[Error] Unit1.pas(56): Incompatible types: 'TLabel' and 'ShortString'
[Error] Unit1.pas(57): Incompatible types: 'TLabel' and 'ShortString'
[Error] Unit1.pas(58): Incompatible types: 'TLabel' and 'ShortString'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

Any ideas?

Last edited by Monkey_features; Feb 8th, 2005 at 5:56 PM.
Monkey_features is offline   Reply With Quote
Old Feb 8th, 2005, 2:37 PM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I'm doing AS Computing as well - I'm lovin' it, apart from the fact that we have to learn Delphi instead of a decent language. But the rest of my class get enough of my moaning - onto the problem. The Seek function doesn't find stuff for you - it simply sets the file pointer to a certain record. You need to iterate through the records until you get to the one you want, and do it from there.

var
    car: TCar;
.
.
.
while not(Eof(carfile)) and (car.registration <> Edit1.Text) do
begin
    Read(carfile, car);
end;
The "car" record will be the one you want. Make sure you change TCar to your car record type.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 8th, 2005, 2:55 PM   #3
Monkey_features
Newbie
 
Monkey_features's Avatar
 
Join Date: Feb 2005
Posts: 15
Rep Power: 0 Monkey_features is on a distinguished road
Cool - where do you study?

I implimented it like this:

type
    Tcar = record
        RegNum : string[7];
        Company : string[20];
        TyreType : string[10];
    end;

var
  Form1: TForm1;
  carfile : file;
  car : Tcar;

implementation

{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
    AssignFile(carfile, 'car.dat');
    Reset(carfile);
    while not(Eof(carfile)) and (car.RegNum <> Edit1.Text) do
        begin
          Read(carfile, car);
        end;

It gave me the following error:

[Error] Unit1.pas(58): Incompatible types: 'procedure, untyped pointer or untyped parameter' and 'Tcar'

Help?
Monkey_features is offline   Reply With Quote
Old Feb 8th, 2005, 3:29 PM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Perhaps Delphi doesn't let you use uninitialised variables - I'm not sure. Try adding this to the beginning of the procedure:
car.RegNum := '';
car.Company := '';
car.TyreType := '';
(that's two single-quotes, not one double-quote).

And I'm in St. Olave's School, in north Kent/south-east London.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 8th, 2005, 3:36 PM   #5
Monkey_features
Newbie
 
Monkey_features's Avatar
 
Join Date: Feb 2005
Posts: 15
Rep Power: 0 Monkey_features is on a distinguished road
No effect.

Just so you know, its highlighting this line in delphi:

 Read(carfile, car);
Monkey_features is offline   Reply With Quote
Old Feb 8th, 2005, 3:40 PM   #6
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Oooh... I know what it is. Change the "and" to "or".
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 8th, 2005, 3:42 PM   #7
Monkey_features
Newbie
 
Monkey_features's Avatar
 
Join Date: Feb 2005
Posts: 15
Rep Power: 0 Monkey_features is on a distinguished road
lol are you sure? Again, i'm afraid no effect. I could talk to you on MSN about this but, i don't know whether anyone else is getting this problem, i can't log in.
Monkey_features is offline   Reply With Quote
Old Feb 8th, 2005, 3:50 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Sure, why not? My MSN address is LazySod <insert @ here> gmail.com.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Feb 8th, 2005, 4:06 PM   #9
Monkey_features
Newbie
 
Monkey_features's Avatar
 
Join Date: Feb 2005
Posts: 15
Rep Power: 0 Monkey_features is on a distinguished road
well my MSN isn't working, nore is Windows messenger, nore is web messenger, nore is e-messenger... is this not a problem for anyone else? - sorry for going off topic.
Monkey_features is offline   Reply With Quote
Old Feb 8th, 2005, 4:23 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
MSN's been down a lot in England today. Got AIM? My sign-in name's Ooble666.
__________________
Me :: You :: Them

Last edited by Ooble; Feb 8th, 2005 at 4:28 PM.
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:29 AM.

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