home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / RANGEVAL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  1.9 KB  |  84 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993 by Borland International
  3. //   source\owl\rangeval.cpp
  4. //----------------------------------------------------------------------------
  5. #pragma hdrignore SECTION
  6. #include <owl\owlpch.h>
  7. #include <owl\validate.h>
  8. #include <owl\applicat.h>
  9. #include <classlib\objstrm.h>
  10.  
  11. #if !defined(SECTION) || SECTION == 1
  12.  
  13. //
  14. // TRangeValidator
  15. //
  16.  
  17.  
  18. TRangeValidator::TRangeValidator(long min, long max)
  19.   : TFilterValidator("0-9+-")
  20. {
  21.   if (min >= 0)
  22.     ValidChars -= '-';
  23.   Min = min;
  24.   Max = max;
  25. }
  26.  
  27. void
  28. TRangeValidator::Error()
  29. {
  30.   char msg[81];
  31.   wsprintf(msg, string(*GetApplicationObject(), IDS_VALNOTINRANGE).c_str(), Min, Max);
  32.   ::MessageBox(0, msg, GetApplicationObject()->GetName(), 
  33.     MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL);
  34. }
  35.  
  36. BOOL
  37. TRangeValidator::IsValid(const char far* s)
  38. {
  39.   if (TFilterValidator::IsValid(s)) {
  40.     long value = atol(s);
  41.     if (value >= Min && value <= Max)
  42.       return TRUE;
  43.   }
  44.   return FALSE;
  45. }
  46.  
  47. UINT
  48. TRangeValidator::Transfer(char far* s, void* buffer, TTransferDirection direction)
  49. {
  50.   if (Options & voTransfer) {
  51.     if (direction == tdGetData) {
  52.       *(long*)buffer = atol(s);
  53.  
  54.     } else if (direction == tdSetData) {
  55.       wsprintf(s, "%ld", *(long*)buffer);
  56.     }
  57.     return sizeof(long);
  58.  
  59.   } else
  60.     return 0;
  61. }
  62.  
  63. #endif
  64. #if !defined(SECTION) || SECTION == 2
  65.  
  66. IMPLEMENT_STREAMABLE1(TRangeValidator, TFilterValidator);
  67.  
  68. void*
  69. TRangeValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
  70. {
  71.   ReadBaseObject((TFilterValidator*)GetObject(), is);
  72.   is >> GetObject()->Min >> GetObject()->Max;
  73.   return GetObject();
  74. }
  75.  
  76. void
  77. TRangeValidator::Streamer::Write(opstream& os) const
  78. {
  79.   WriteBaseObject((TFilterValidator*)GetObject(), os);
  80.   os << GetObject()->Min << GetObject()->Max;
  81. }
  82.  
  83. #endif
  84.