?
Solved

Did program suggested, but get type mismatch

Posted on 2000-03-08
9
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 49

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
Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

 
LVL 49

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 49

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 15 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

743 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