![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 15
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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; |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2005
Posts: 15
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
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 := ''; And I'm in St. Olave's School, in north Kent/south-east London. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Feb 2005
Posts: 15
Rep Power: 0
![]() |
No effect.
Just so you know, its highlighting this line in delphi: Read(carfile, car); |
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Oooh... I know what it is. Change the "and" to "or".
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Feb 2005
Posts: 15
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Sure, why not? My MSN address is LazySod <insert @ here> gmail.com.
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Feb 2005
Posts: 15
Rep Power: 0
![]() |
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.
![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|