User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 425,824 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,980 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 462 | Replies: 2
Reply
Join Date: May 2008
Posts: 2
Reputation: sheady is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sheady sheady is offline Offline
Newbie Poster

Help me plz File not Found yet file is there

  #1  
May 24th, 2008
I have created a Program that first searches and returns the contents of a file into a richedit then opens up the next file finds the matching record and displays that in the rich edit and then the same again with another file.
My problem is that when i search it displays an EinOut Error File Not Found but the File Is there becasuse i wrote the records to it from the program.
Just so you can get an idea here is my code for the Procedure that fails it fails at the 'reset(productfile)' and 'reset(Servicefile)' i've highlighted them in red.
Any help would be majorly appreciated because i have to get this finished thanks in advance.

procedure TForm12.Button1Click(Sender: TObject);
var found:boolean; buyer:string; warranty:string; service:string; billing:string; product:string; postcode:string; name:string;
begin
found := false;
RichEdit1.clear;
assignfile(CustomerFile, Customer);
reset(CustomerFile);
while not eof (CustomerFile) do
read(CustomerFile, CustomerRecord);
begin
if (CustomerRecord.Name = Edit1.text) or (CustomerRecord.Postcode = edit2.Text) or (CustomerRecord.Surname = edit3.Text) then
begin
Richedit1.Lines.Add('Customer Details');
Richedit1.Lines.Add('');
Richedit1.Lines.Add('Title: '+ CustomerRecord.Title);
Richedit1.Lines.Add('Name: '+ CustomerRecord.Name);
Richedit1.Lines.Add('Surname: '+ CustomerRecord.Surname);
Richedit1.Lines.Add('Street: '+ CustomerRecord.Street);
Richedit1.Lines.Add('Town: '+ CustomerRecord.Town);
Richedit1.Lines.Add('County: '+ CustomerRecord.County);
Richedit1.Lines.Add('Postcode '+ CustomerRecord.Postcode);
Richedit1.Lines.Add('Telephone '+ CustomerRecord.Telephone);
Richedit1.Lines.Add('Mobile: '+ CustomerRecord.Mobile);
Richedit1.Lines.Add('Email: '+ CustomerRecord.Email);
Richedit1.Lines.Add('Notes: '+ CustomerRecord.Notes);
Richedit1.Lines.Add('');
Richedit1.Lines.Add('');
billing := CustomerRecord.billing;
buyer := CustomerRecord.Buying;
service := CustomerRecord.Service;
warranty := CustomerRecord.Warranty;
product := CustomerRecord.ProductS;
Postcode := CustomerRecord.Postcode;
name := CustomerRecord.Name;
found := true;
end;
If billing = 'y' then
Begin
Richedit1.Lines.Add('Billing Details');
Richedit1.Lines.Add('');
Richedit1.Lines.Add('Billing Title: '+ CustomerRecord.BTitle);
Richedit1.Lines.Add('Billing Name: '+ CustomerRecord.BName);
Richedit1.Lines.Add('Billing Surname: '+ CustomerRecord.BSurname);
Richedit1.Lines.Add('Billing Street: '+ CustomerRecord.BStreet);
Richedit1.Lines.Add('Billing Town: '+ CustomerRecord.BTown);
Richedit1.Lines.Add('Billing County: '+ CustomerRecord.BCounty);
Richedit1.Lines.Add('Billing Postcode: '+ CustomerRecord.BPostcode);
Richedit1.Lines.Add('Billing Telephone: '+ CustomerRecord.BTelephone);
Richedit1.Lines.Add('Billing Mobile: '+ CustomerRecord.BMobile);
Richedit1.Lines.Add('Billing Email: '+ CustomerRecord.BEmail);
Richedit1.Lines.Add('');
Richedit1.Lines.Add('');
End;
If warranty = 'y' then
Begin
Richedit1.Lines.Add('Warranty Details');
Richedit1.Lines.Add('');
Richedit1.Lines.Add('Warranty Start: '+ CustomerRecord.Wstart);
Richedit1.Lines.Add('Warranty Length: '+ CustomerRecord.WLength);
Richedit1.Lines.Add('');
Richedit1.Lines.Add('');
End;
If service = 'y' then
Begin
Richedit1.Lines.Add('Service Details');
Richedit1.Lines.Add('');
Richedit1.Lines.Add('Installation date: '+ CustomerRecord.IDate);
Richedit1.Lines.Add('New / Refurbished: '+ CustomerRecord.NR);
Richedit1.Lines.Add('Service Interval: '+ CustomerRecord.SInterval);
Richedit1.Lines.Add('Next Service: '+ CustomerRecord.NxtSDate);
Richedit1.Lines.Add('');
Richedit1.Lines.Add('');
End;
end;
closefile(CustomerFile);

assignfile(ProductFile, Product);
reset(ProductFile);
while not eof (ProductFile) do
read(ProductFile, ProductRecord);
begin
if ProductRecord.Serial = product then
Begin
Richedit1.Lines.Add('Product Details');
Richedit1.Lines.Add('');
Richedit1.Lines.Add('Product Serial: '+ ProductRecord.Serial);
Richedit1.Lines.Add('Make / Model: '+ ProductRecord.MakeModel);
Richedit1.Lines.Add('Date Of Purchase: '+ ProductRecord.DOP);
Richedit1.Lines.Add('Colour: '+ ProductRecord.Colour);
Richedit1.Lines.Add('Elec Or Manual: '+ ProductRecord.EorM);
Richedit1.Lines.Add('Price: '+ ProductRecord.Cost);
Richedit1.Lines.Add('Reference No.: '+ ProductRecord.RefNo);
End;
end;
closefile(ProductFile);

assignfile(ServiceFile, Service);
reset(ServiceFile);
while not eof (ServiceFile) do
read(ServiceFile, ServiceRecord);
begin
if (ServiceRecord.Nameofcustomer = name) and (ServiceRecord.postcodeofcustomer = postcode) then
Begin
Richedit1.Lines.Add('Date Of Service: '+ ServiceRecord.Dateofservice);
Richedit1.Lines.Add('Parts Used: '+ ServiceRecord.PartsUsed);
Richedit1.Lines.Add('Notes: '+ ServiceRecord.Notes);
End;
end;
closefile(ServiceFile);
if found = false then
Begin
showmessage('not on the file');
End;
end;
Last edited by sheady : May 24th, 2008 at 7:20 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2007
Posts: 69
Reputation: ExplainThat is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
ExplainThat ExplainThat is offline Offline
Junior Poster in Training

Re: Help me plz File not Found yet file is there

  #2  
May 26th, 2008
Sheady,

It is never very easy pinpointing errors based on very long code listings such as yours. Having taken a brief look at your code I have several suggestions to make
  • In my book any object procedure that exceeds around 20 lines of code needs to be broken up into multiple function/procedure calls.
  • You are handling several distinct tasks in your code so you could do that quite easily - and it will result in more readable code.
  • Are you aware of the with keyword? You might be able to use it to good effect here to write code that is easier to read and to maintain
  • Doing file operations without a try..except block to handle the unexpected is very unwise. At the very least you should have that.
  • ReSet returns an error in IOResult which might do with checking when the unexpected does happen
  • You might be better of doing one of the following in place of your AssignFile, ReSet... code
  1. Read the file into a TStringStream or a TStringList
  2. Check that the file exists using FileExists
  3. If the path to your file is being generated by code make sure that the path is correct by outputting it to DebugView - or a message box if you don't feel upto DebugView
  4. Finally, when things go wrong in code such as yours and logic does not help sort out the problem it is useful to follow a "divide and rule" strategy - systematically comment out portions of your code to help pinpoint the error
Reply With Quote  
Join Date: May 2008
Posts: 4
Reputation: afripino is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
afripino afripino is offline Offline
Newbie Poster

Re: Help me plz File not Found yet file is there

  #3  
May 29th, 2008
Perhaps you need to add ExtractFilePath(param(0)) + FileName to your file calls.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 4:22 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC