Solved

Did program suggested, but get type mismatch

Posted on 2000-03-08
9
156 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
In 2017, ransomware will become so virulent and widespread that if you aren’t a victim yourself, you will know someone who is.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now