Solved

object not printable?

Posted on 1998-11-30
7
310 Views
Last Modified: 2010-04-16
procedure search;
begin      
    writeln('Please enter either name, date, departure or destination');
    readln(searchentry);
end;


searchentry is a predeclared type (since you cant case a string)....now when i try to run my program a get an error saying "object not printable"  pointing at the ")" after searchentry.

why is this happening and how can i fix it?
I'm not trying to print, just to read in a string.
0
Comment
Question by:yaelie
  • 3
  • 3
7 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 1216255
Can you post the edclaration of "searchentry" please?
0
 
LVL 1

Author Comment

by:yaelie
ID: 1216256
type
querytype=(name,date, departure, destination);

var
searchentry:querytype;

- and thanx for letting me know about it being posted twice
0
 
LVL 27

Accepted Solution

by:
BigRat earned 20 total points
ID: 1216257
Well yes, an enumerated type. Just as a matter of interest, what do you think the user ought to type in when your program does the Readln? And before you say "name" or "date" or "departure" or "destination" how do you think the compiler should process it?
An enumerated type cannot be "read-in" since it has no external representation.
   I admit the error message is crap but that's life. If you had actually put it in a write statement you would have got the correct error message. (You would also have had to change it to Ord(searchentry) - OK)
   The enumerated type is very nice but it does not allow for input error. I would suggest you do the following :-
var
   Option : Integer;

    Writeln('Option 1 for name');
    Writeln('Option 2 for date');
    Writeln('Option 3 for departure');
    Writeln('Option 4 for destination');
    repeat
       Write('Enter the option you require and press Enter:-');
       Readln(Option);
       if not((1<=Option) and (Option<=4)) then
          Writeln('Please enter a digit from 1 to 4 and press Enter');
   until (1<=Option) and (Option<=4);
   SearchEntry:=QueryType(Option);
   ...........
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 1

Author Comment

by:yaelie
ID: 1216258
ooh but there must be some other way...? otherwise ill just declare each as a char (for example if you want the name type in 'n') and use a case statement...and in that case i shouldnt have any problems....is there really no way to leave it declared the way i have it and read in to it?
also what i still dont understand is why is it even talking about printing?!
I'm sorry for all the questions....but thank you, the help is highly appreciated
0
 
LVL 2

Expert Comment

by:joe_h
ID: 1216259
There is always a way :) In this case, you can typecast the searchentry variable to a byte and read it in. In this case, user would enter 0 for name, 1 for date etc. You'd use something like:

var searchbyte: byte absolute searchentry; {lets you access searchentry as a byte}
.
 readln(searchbyte);
 case searchentry of
.

Works with Borland Pascal 7.0, should work on earlier versions too.

HTH, Joe
0
 
LVL 27

Expert Comment

by:BigRat
ID: 1216260
If you are not satisfied with an answer REJECT it so that others can try.
Last question first. You cannot Read nor Write variables of enumerated type without first converting them to an ordinal type (byte, integer or such). That's Pascal - go and complain to Prof. Wirth.
The compiler conplains about printing because the silly compiler writer did not take the bother of separating out two error messages from one. (I'm also very guilty of doing the same).
Lastly since you are going to have to read in something which gets converted to teh type you want, it is ALWAYS a good idea to inform the user about EXACTLY you expect him to type in. Your proposal of using the first letter is generally acceptable provided that it is unique. Here you have Date and Destination, so a "d" is not unique. Furthermore entering simple numbers is extensible - you just add a new number, and one can do it from the numeric pad which sames making tpyign mitsakse - if you see what I mean.
0
 
LVL 1

Author Comment

by:yaelie
ID: 1216261
Thank you for the last comment!!! Thats all i needed to hear...cleared it all up. thanx for the help
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

When converting a physical machine to a virtual machine using VMware vCenter Converter Standalone or vCenter Converter Enterprise, if an adapter type is not selected during the initial customization the resulting virtual machine may contain an IDE d…
If your vDisk VHD file gets deleted from the image store accidentally or on purpose, you won't be able to remove the vDisk from the PVS console. There is a known workaround that is solid.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

17 Experts available now in Live!

Get 1:1 Help Now