Solved

Did program suggested, but get type mismatch

Posted on 2000-03-08
9
159 Views
Last Modified: 2010-04-16
I did the program that sumant gave, but I'm having problems.
http://www.experts-exchange.com/jsp/qShow.jsp?ta=pascal&qid=10302613 


I get a write mismatch error on this line:

write(male, name);
0
Comment
Question by:kazooie21
  • 3
  • 3
  • 2
  • +1
9 Comments
 

Author Comment

by:kazooie21
ID: 2598057
I guess that's what he means when he says; "Use the correct open file"

re....(male)

etc.
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 2599538
write(male, customer.name);

name is inside the record customer
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599552
this old question's comments are not available for free anymore ;-) so I can't see a source, but if you use 'male' file in 'write' procedure you have to open it first, so
var
  male : text; {must be declared if you use text files}
begin
  assign( male, 'somefile.txt' );    { file name must be assigned to variable }
 rewrite( male )  {to create new file, or use append( male ) if you want to add to existing}

you can not use reset(male) because file will be opened as readonly !


0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 48

Expert Comment

by:dbrunton
ID: 2599806
type customer = record
  name : as a string;
  address : as a string;
  gender : char;
  balance : real;
end;
     

I can.  There's too much code to post here but.

He has a record structure in which name is a field of the record.
Male is a text file as you surmise.
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 2599836
Whoops!  Reread the original program.


kazooie21

How do you open the files?  As text files or record files as sumant posted.  If  you used sumant's code which uses records then you should use

write(male, customer);

You must write the whole record at once to the file.  This would explain the type mismatch.

If they are text files then my code should be correct.
0
 
LVL 3

Expert Comment

by:sumant032199
ID: 2601741
Yes, you must write entire record at once. Do not go for text files, They occupy  larger space and binary files work always work fine and fast.
0
 

Author Comment

by:kazooie21
ID: 2602889
I did the assign(male, somefile.txt') thing, but I still get the same error.
0
 
LVL 3

Accepted Solution

by:
Alisher_N earned 5 total points
ID: 2603813
kazoo! check again how your file is declared...
if it is

var
  malefile : customer;
  myrecord : customer;
{then you have to use}
begin
  assign( malefile, 'somefile.dat' );
  rewrite( malefile, 1 );
  myrecord.name := 'lastname';
  blockwrite( malefile, myrecord, sizeof( cutomer ));
  close( malefile );

another option when you declare file as Text:

var
  malefile : Text;
  myrecord : cutomer;
begin
  assign( malefile, 'somefile.dat' );
  rewrite( malefile ); { no record size!}
  myrecord.name := 'lastname';
  writeln( malefile, myrecord.name );
  close( malefile );
end.

you can not mix two these approaches!

0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2603827
BTW, first approach much better - avoid to use text files unless you going to edit them manually...
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using IdHTTP1.Get with Delphi and Indy 9/10 on a specific web server returns exception 3 2,535
Interbase BDE 4 454
How to capture screen window of a process 4 400
Conversion ? 15 89
How do we balance the user experience (UX) with reasonable security measures? It can be done, if you keep these fundamentals in mind.
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

805 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question