PB170
Well-known member
Has anyone here successfully run the Reminder app from Dave Mark's and Cartwright Reed's "Macintosh C Programming Primer, Volume 1, Second edition"?
When checking the syntax, Think C complains that "Pointer types do not match" in the two lines below.
GetDItem( dialog, iLaunchCheckBox, &itemType, &itemHandle, &itemRect );
if ( reminder->launch = GetCtlValue( (ControlHandle)itemHandle ) )
reminder->notify.nmResp = &LaunchResponse;
else
reminder->notify.nmResp = &NormalResponse;
I find this peculiar since I'm using the very same version of Think C as in the book (version 5), although there's a setting to turn off the pointer check that might explain it. After looking into it, I fixed it with a typecast (NMProcPtr) in front of &LaunchResponse and &NormalResponse so that the program compiles.
However, the program doesn't work like it's supposed to. This far all the example programs have worked fine (except from a small omission in the book at one point). Since I haven't got access to the source codes, I've (painstakingly) copied them from the OCR-scanned version at vintageapple.org and manually gone though and corrected and structured them, so it's possibly that some typo remains, although I've gone through the code so many times now that I doubt it, and it compiles just fine.
Are there bugs in the printed code, or could it be some setting in Think C that causes the issues?
The following happens:
Algorithm:
Interface:
I'm assuming the two first issues are related to this part of the code in some way:
GetDItem( dialog, iHoursPopup, &itemType, &itemHandle, &itemRect );
val = GetCtlValue( (ControlHandle)itemHandle );
NumToString( (long)val, string );
StringToNum( string, &tmp );
reminder->hour = tmp;
reminder->menuString[0] = 0;
ConcatString( reminder->menuString, string );
ConcatString( reminder->menuString, "\p:" );
GetDItem( dialog, iMinutesPopup, &itemType, &itemHandle, &itemRect );
val = GetCtlValue( (ControlHandle)itemHandle );
menu = GetMHandle( mMinutes );
GetItem( menu, val, string );
StringToNum( string, &tmp );
reminder->minute = tmp;
ConcatString( reminder->menuString, string );
ConcatString( reminder->menuString, "\p " );
GetDItem( dialog, iAMorPMPopup, &itemType, &itemHandle, &itemRect );
val = GetCtlValue( (ControlHandle)itemHandle );
if ( val == kPM )
reminder->hour += 12;
menu = GetMenu( mAMorPM );
GetItem( menu, val, string );
ConcatString( reminder->menuString, string );
reminder->notify.qType = nmType;
reminder->notify.nmMark = kMarkApp;
}
// ConcatString
void ConcatString( Str255 str1, Str255 str2 )
{
short i;
for (i=str1[0]; i<str2[0]+str1[0]; i++)
{
str1[i+1] = str2[i-str1[0]+1];
}
str1[0] = i;
}
Does anyone have any thoughts about this? Kind of frustrating to have to debug the example code
I've attached the complete source code and resource file for reference.
View attachment Reminder.c
View attachment Reminder.π.rsrc.sit
When checking the syntax, Think C complains that "Pointer types do not match" in the two lines below.
GetDItem( dialog, iLaunchCheckBox, &itemType, &itemHandle, &itemRect );
if ( reminder->launch = GetCtlValue( (ControlHandle)itemHandle ) )
reminder->notify.nmResp = &LaunchResponse;
else
reminder->notify.nmResp = &NormalResponse;
I find this peculiar since I'm using the very same version of Think C as in the book (version 5), although there's a setting to turn off the pointer check that might explain it. After looking into it, I fixed it with a typecast (NMProcPtr) in front of &LaunchResponse and &NormalResponse so that the program compiles.
However, the program doesn't work like it's supposed to. This far all the example programs have worked fine (except from a small omission in the book at one point). Since I haven't got access to the source codes, I've (painstakingly) copied them from the OCR-scanned version at vintageapple.org and manually gone though and corrected and structured them, so it's possibly that some typo remains, although I've gone through the code so many times now that I doubt it, and it compiles just fine.
Are there bugs in the printed code, or could it be some setting in Think C that causes the issues?
The following happens:
Algorithm:
- When setting reminders, the minutes are not copied properly to the submenu and sometimes results in a long string of random text (seems to happen when the minutes popup is set to '00').
- The reminders go off at the wrong time (it seems like the minutes setting is ignored)
- The OK button doesn't get greyed out when the text field is empty unless of the checkboxes are clicked
- The Edit menu isn't initially disabled like it's supposed to (don't know where in the code/resource this should take place this at this point)
Interface:
- The texts don't fit in the popups like in the book (although they do so when running the app under Mac OS 9…).
I'm assuming the two first issues are related to this part of the code in some way:
GetDItem( dialog, iHoursPopup, &itemType, &itemHandle, &itemRect );
val = GetCtlValue( (ControlHandle)itemHandle );
NumToString( (long)val, string );
StringToNum( string, &tmp );
reminder->hour = tmp;
reminder->menuString[0] = 0;
ConcatString( reminder->menuString, string );
ConcatString( reminder->menuString, "\p:" );
GetDItem( dialog, iMinutesPopup, &itemType, &itemHandle, &itemRect );
val = GetCtlValue( (ControlHandle)itemHandle );
menu = GetMHandle( mMinutes );
GetItem( menu, val, string );
StringToNum( string, &tmp );
reminder->minute = tmp;
ConcatString( reminder->menuString, string );
ConcatString( reminder->menuString, "\p " );
GetDItem( dialog, iAMorPMPopup, &itemType, &itemHandle, &itemRect );
val = GetCtlValue( (ControlHandle)itemHandle );
if ( val == kPM )
reminder->hour += 12;
menu = GetMenu( mAMorPM );
GetItem( menu, val, string );
ConcatString( reminder->menuString, string );
reminder->notify.qType = nmType;
reminder->notify.nmMark = kMarkApp;
}
// ConcatString
void ConcatString( Str255 str1, Str255 str2 )
{
short i;
for (i=str1[0]; i<str2[0]+str1[0]; i++)
{
str1[i+1] = str2[i-str1[0]+1];
}
str1[0] = i;
}
Does anyone have any thoughts about this? Kind of frustrating to have to debug the example code
I've attached the complete source code and resource file for reference.
View attachment Reminder.c
View attachment Reminder.π.rsrc.sit