validate.pas 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  2. { }
  3. { System independent GRAPHICAL clone of VALIDATE.PAS }
  4. { }
  5. { Interface Copyright (c) 1992 Borland International }
  6. { }
  7. { Copyright (c) 1996, 1997, 1998, 1999 by Leon de Boer }
  8. { [email protected] }
  9. { }
  10. {****************[ THIS CODE IS FREEWARE ]*****************}
  11. { }
  12. { This sourcecode is released for the purpose to }
  13. { promote the pascal language on all platforms. You may }
  14. { redistribute it and/or modify with the following }
  15. { DISCLAIMER. }
  16. { }
  17. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  18. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  19. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  20. { }
  21. {*****************[ SUPPORTED PLATFORMS ]******************}
  22. { 16 and 32 Bit compilers }
  23. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  24. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  25. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  26. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  27. { - Delphi 1.0+ (16 Bit) }
  28. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  29. { - Virtual Pascal 2.0+ (32 Bit) }
  30. { - Speedsoft Sybil 2.0+ (32 Bit) }
  31. { - FPC 0.9912+ (32 Bit) }
  32. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  33. { }
  34. {******************[ REVISION HISTORY ]********************}
  35. { Version Date Fix }
  36. { ------- --------- --------------------------------- }
  37. { 1.00 12 Jun 96 Initial DOS/DPMI code released. }
  38. { 1.10 29 Aug 97 Platform.inc sort added. }
  39. { 1.20 13 Oct 97 Delphi3 32 bit code added. }
  40. { 1.30 11 May 98 Virtual pascal 2.0 code added. }
  41. { 1.40 10 Jul 99 Sybil 2.0 code added }
  42. { 1.41 03 Nov 99 FPC windows code added }
  43. {**********************************************************}
  44. UNIT Validate;
  45. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  46. INTERFACE
  47. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  48. {====Include file to sort compiler platform out =====================}
  49. {$I Platform.inc}
  50. {====================================================================}
  51. {==== Compiler directives ===========================================}
  52. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  53. {$F-} { Short calls are okay }
  54. {$A+} { Word Align Data }
  55. {$B-} { Allow short circuit boolean evaluations }
  56. {$O+} { This unit may be overlaid }
  57. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  58. {$P-} { Normal string variables }
  59. {$N-} { No 80x87 code generation }
  60. {$E+} { Emulation is on }
  61. {$ENDIF}
  62. {$X+} { Extended syntax is ok }
  63. {$R-} { Disable range checking }
  64. {$S-} { Disable Stack Checking }
  65. {$I-} { Disable IO Checking }
  66. {$Q-} { Disable Overflow Checking }
  67. {$V-} { Turn off strict VAR strings }
  68. {====================================================================}
  69. USES FVCommon, Objects, fvconsts; { GFV standard units }
  70. {***************************************************************************}
  71. { PUBLIC CONSTANTS }
  72. {***************************************************************************}
  73. {---------------------------------------------------------------------------}
  74. { VALIDATOR STATUS CONSTANTS }
  75. {---------------------------------------------------------------------------}
  76. CONST
  77. vsOk = 0; { Validator ok }
  78. vsSyntax = 1; { Validator sytax err }
  79. {---------------------------------------------------------------------------}
  80. { VALIDATOR OPTION MASKS }
  81. {---------------------------------------------------------------------------}
  82. CONST
  83. voFill = $0001; { Validator fill }
  84. voTransfer = $0002; { Validator transfer }
  85. voOnAppend = $0004; { Validator append }
  86. voReserved = $00F8; { Clear above flags }
  87. {***************************************************************************}
  88. { RECORD DEFINITIONS }
  89. {***************************************************************************}
  90. {---------------------------------------------------------------------------}
  91. { VALIDATOR TRANSFER CONSTANTS }
  92. {---------------------------------------------------------------------------}
  93. TYPE
  94. TVTransfer = (vtDataSize, vtSetData, vtGetData); { Transfer states }
  95. {---------------------------------------------------------------------------}
  96. { PICTURE VALIDATOR RESULT CONSTANTS }
  97. {---------------------------------------------------------------------------}
  98. TYPE
  99. TPicResult = (prComplete, prIncomplete, prEmpty, prError, prSyntax,
  100. prAmbiguous, prIncompNoFill);
  101. {***************************************************************************}
  102. { OBJECT DEFINITIONS }
  103. {***************************************************************************}
  104. {---------------------------------------------------------------------------}
  105. { TValidator OBJECT - VALIDATOR ANCESTOR OBJECT }
  106. {---------------------------------------------------------------------------}
  107. TYPE
  108. TValidator = OBJECT (TObject)
  109. Status : Word; { Validator status }
  110. Options: Word; { Validator options }
  111. CONSTRUCTOR Load (Var S: TStream);
  112. FUNCTION Valid(CONST S: String): Boolean;
  113. FUNCTION IsValid (CONST S: String): Boolean; Virtual;
  114. FUNCTION IsValidInput (Var S: String;
  115. SuppressFill: Boolean): Boolean; Virtual;
  116. FUNCTION Transfer (Var S: String; Buffer: Pointer;
  117. Flag: TVTransfer): Word; Virtual;
  118. PROCEDURE Error; Virtual;
  119. PROCEDURE Store (Var S: TStream);
  120. END;
  121. PValidator = ^TValidator;
  122. {---------------------------------------------------------------------------}
  123. { TPictureValidator OBJECT - PICTURE VALIDATOR OBJECT }
  124. {---------------------------------------------------------------------------}
  125. TYPE
  126. TPXPictureValidator = OBJECT (TValidator)
  127. Pic: PString; { Picture filename }
  128. CONSTRUCTOR Init (Const APic: String; AutoFill: Boolean);
  129. CONSTRUCTOR Load (Var S: TStream);
  130. DESTRUCTOR Done; Virtual;
  131. FUNCTION IsValid (Const S: String): Boolean; Virtual;
  132. FUNCTION IsValidInput (Var S: String;
  133. SuppressFill: Boolean): Boolean; Virtual;
  134. FUNCTION Picture (Var Input: String;
  135. AutoFill: Boolean): TPicResult; Virtual;
  136. PROCEDURE Error; Virtual;
  137. PROCEDURE Store (Var S: TStream);
  138. END;
  139. PPXPictureValidator = ^TPXPictureValidator;
  140. TYPE CharSet = TCharSet;
  141. {---------------------------------------------------------------------------}
  142. { TFilterValidator OBJECT - FILTER VALIDATOR OBJECT }
  143. {---------------------------------------------------------------------------}
  144. TYPE
  145. TFilterValidator = OBJECT (TValidator)
  146. ValidChars: CharSet; { Valid char set }
  147. CONSTRUCTOR Init (AValidChars: CharSet);
  148. CONSTRUCTOR Load (Var S: TStream);
  149. FUNCTION IsValid (CONST S: String): Boolean; Virtual;
  150. FUNCTION IsValidInput (Var S: String;
  151. SuppressFill: Boolean): Boolean; Virtual;
  152. PROCEDURE Error; Virtual;
  153. PROCEDURE Store (Var S: TStream);
  154. END;
  155. PFilterValidator = ^TFilterValidator;
  156. {---------------------------------------------------------------------------}
  157. { TRangeValidator OBJECT - RANGE VALIDATOR OBJECT }
  158. {---------------------------------------------------------------------------}
  159. TYPE
  160. TRangeValidator = OBJECT (TFilterValidator)
  161. Min: LongInt; { Min valid value }
  162. Max: LongInt; { Max valid value }
  163. CONSTRUCTOR Init(AMin, AMax: LongInt);
  164. CONSTRUCTOR Load (Var S: TStream);
  165. FUNCTION IsValid (Const S: String): Boolean; Virtual;
  166. FUNCTION Transfer (Var S: String; Buffer: Pointer;
  167. Flag: TVTransfer): Word; Virtual;
  168. PROCEDURE Error; Virtual;
  169. PROCEDURE Store (Var S: TStream);
  170. END;
  171. PRangeValidator = ^TRangeValidator;
  172. {---------------------------------------------------------------------------}
  173. { TLookUpValidator OBJECT - LOOKUP VALIDATOR OBJECT }
  174. {---------------------------------------------------------------------------}
  175. TYPE
  176. TLookupValidator = OBJECT (TValidator)
  177. FUNCTION IsValid (Const S: String): Boolean; Virtual;
  178. FUNCTION Lookup (Const S: String): Boolean; Virtual;
  179. END;
  180. PLookupValidator = ^TLookupValidator;
  181. {---------------------------------------------------------------------------}
  182. { TStringLookUpValidator OBJECT - STRING LOOKUP VALIDATOR OBJECT }
  183. {---------------------------------------------------------------------------}
  184. TYPE
  185. TStringLookupValidator = OBJECT (TLookupValidator)
  186. Strings: PStringCollection;
  187. CONSTRUCTOR Init (AStrings: PStringCollection);
  188. CONSTRUCTOR Load (Var S: TStream);
  189. DESTRUCTOR Done; Virtual;
  190. FUNCTION Lookup (Const S: String): Boolean; Virtual;
  191. PROCEDURE Error; Virtual;
  192. PROCEDURE NewStringList (AStrings: PStringCollection);
  193. PROCEDURE Store (Var S: TStream);
  194. END;
  195. PStringLookupValidator = ^TStringLookupValidator;
  196. {***************************************************************************}
  197. { INTERFACE ROUTINES }
  198. {***************************************************************************}
  199. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  200. { OBJECT REGISTER ROUTINES }
  201. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  202. {-RegisterValidate---------------------------------------------------
  203. Calls RegisterType for each of the object types defined in this unit.
  204. 18May98 LdB
  205. ---------------------------------------------------------------------}
  206. PROCEDURE RegisterValidate;
  207. {***************************************************************************}
  208. { OBJECT REGISTRATION }
  209. {***************************************************************************}
  210. {---------------------------------------------------------------------------}
  211. { TPXPictureValidator STREAM REGISTRATION }
  212. {---------------------------------------------------------------------------}
  213. CONST
  214. RPXPictureValidator: TStreamRec = (
  215. ObjType: idPXPictureValidator; { Register id = 80 }
  216. {$IFDEF BP_VMTLink} { BP style VMT link }
  217. VmtLink: Ofs(TypeOf(TPXPictureValidator)^);
  218. {$ELSE} { Alt style VMT link }
  219. VmtLink: TypeOf(TPXPictureValidator);
  220. {$ENDIF}
  221. Load: @TPXPictureValidator.Load; { Object load method }
  222. Store: @TPXPictureValidator.Store { Object store method }
  223. );
  224. {---------------------------------------------------------------------------}
  225. { TFilterValidator STREAM REGISTRATION }
  226. {---------------------------------------------------------------------------}
  227. CONST
  228. RFilterValidator: TStreamRec = (
  229. ObjType: idFilterValidator; { Register id = 81 }
  230. {$IFDEF BP_VMTLink} { BP style VMT link }
  231. VmtLink: Ofs(TypeOf(TFilterValidator)^);
  232. {$ELSE} { Alt style VMT link }
  233. VmtLink: TypeOf(TFilterValidator);
  234. {$ENDIF}
  235. Load: @TFilterValidator.Load; { Object load method }
  236. Store: @TFilterValidator.Store { Object store method }
  237. );
  238. {---------------------------------------------------------------------------}
  239. { TRangeValidator STREAM REGISTRATION }
  240. {---------------------------------------------------------------------------}
  241. CONST
  242. RRangeValidator: TStreamRec = (
  243. ObjType: idRangeValidator; { Register id = 82 }
  244. {$IFDEF BP_VMTLink} { BP style VMT link }
  245. VmtLink: Ofs(TypeOf(TRangeValidator)^);
  246. {$ELSE} { Alt style VMT link }
  247. VmtLink: TypeOf(TRangeValidator);
  248. {$ENDIF}
  249. Load: @TRangeValidator.Load; { Object load method }
  250. Store: @TRangeValidator.Store { Object store method }
  251. );
  252. {---------------------------------------------------------------------------}
  253. { TStringLookupValidator STREAM REGISTRATION }
  254. {---------------------------------------------------------------------------}
  255. CONST
  256. RStringLookupValidator: TStreamRec = (
  257. ObjType: idStringLookupValidator; { Register id = 83 }
  258. {$IFDEF BP_VMTLink} { BP style VMT link }
  259. VmtLink: Ofs(TypeOf(TStringLookupValidator)^);
  260. {$ELSE} { Alt style VMT link }
  261. VmtLink: TypeOf(TStringLookupValidator);
  262. {$ENDIF}
  263. Load: @TStringLookupValidator.Load; { Object load method }
  264. Store: @TStringLookupValidator.Store { Object store method }
  265. );
  266. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  267. IMPLEMENTATION
  268. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  269. USES MsgBox; { GFV standard unit }
  270. {***************************************************************************}
  271. { PRIVATE ROUTINES }
  272. {***************************************************************************}
  273. {---------------------------------------------------------------------------}
  274. { IsNumber -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  275. {---------------------------------------------------------------------------}
  276. FUNCTION IsNumber (Chr: Char): Boolean;
  277. BEGIN
  278. If (Chr >= '0') AND (Chr <= '9') Then { Check if '0..9' }
  279. IsNumber := True Else IsNumber := False; { Return result }
  280. END;
  281. {---------------------------------------------------------------------------}
  282. { IsLetter -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  283. {---------------------------------------------------------------------------}
  284. FUNCTION IsLetter (Chr: Char): Boolean;
  285. BEGIN
  286. Chr := Char(Ord(Chr) AND $DF); { Lower to upper case }
  287. If (Chr >= 'A') AND (Chr <='Z') Then { Check if A..Z }
  288. IsLetter := True Else IsLetter := False; { Return result }
  289. END;
  290. {---------------------------------------------------------------------------}
  291. { IsComplete -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  292. {---------------------------------------------------------------------------}
  293. FUNCTION IsComplete (Rslt: TPicResult): Boolean;
  294. BEGIN
  295. IsComplete := Rslt IN [prComplete, prAmbiguous]; { Return if complete }
  296. END;
  297. {---------------------------------------------------------------------------}
  298. { IsInComplete -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  299. {---------------------------------------------------------------------------}
  300. FUNCTION IsIncomplete (Rslt: TPicResult): Boolean;
  301. BEGIN
  302. IsIncomplete := Rslt IN
  303. [prIncomplete, prIncompNoFill]; { Return if incomplete }
  304. END;
  305. {---------------------------------------------------------------------------}
  306. { NumChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  307. {---------------------------------------------------------------------------}
  308. FUNCTION NumChar (Chr: Char; Const S: String): Byte;
  309. VAR I, Total: Byte;
  310. BEGIN
  311. Total := 0; { Zero total }
  312. For I := 1 To Length(S) Do { For entire string }
  313. If (S[I] = Chr) Then Inc(Total); { Count matches of Chr }
  314. NumChar := Total; { Return char count }
  315. END;
  316. {---------------------------------------------------------------------------}
  317. { IsSpecial -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  318. {---------------------------------------------------------------------------}
  319. FUNCTION IsSpecial (Chr: Char; Const Special: String): Boolean;
  320. VAR Rslt: Boolean; I: Byte;
  321. BEGIN
  322. Rslt := False; { Preset false result }
  323. For I := 1 To Length(Special) Do
  324. If (Special[I] = Chr) Then Rslt := True; { Character found }
  325. IsSpecial := Rslt; { Return result }
  326. END;
  327. {***************************************************************************}
  328. { OBJECT METHODS }
  329. {***************************************************************************}
  330. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  331. { TValidator OBJECT METHODS }
  332. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  333. {--TValidator---------------------------------------------------------------}
  334. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  335. {---------------------------------------------------------------------------}
  336. CONSTRUCTOR TValidator.Load (Var S:TStream);
  337. BEGIN
  338. Inherited Init; { Call ancestor }
  339. S.Read(Options, SizeOf(Options)); { Read option masks }
  340. END;
  341. {--TValidator---------------------------------------------------------------}
  342. { Valid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  343. {---------------------------------------------------------------------------}
  344. FUNCTION TValidator.Valid (Const S: String): Boolean;
  345. BEGIN
  346. Valid := False; { Preset false result }
  347. If Not IsValid(S) Then Error { Check for error }
  348. Else Valid := True; { Return valid result }
  349. END;
  350. {--TValidator---------------------------------------------------------------}
  351. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  352. {---------------------------------------------------------------------------}
  353. FUNCTION TValidator.IsValid (Const S: String): Boolean;
  354. BEGIN
  355. IsValid := True; { Default return valid }
  356. END;
  357. {--TValidator---------------------------------------------------------------}
  358. { IsValidInput -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  359. {---------------------------------------------------------------------------}
  360. FUNCTION TValidator.IsValidInput (Var S: String; SuppressFill: Boolean): Boolean;
  361. BEGIN
  362. IsValidInput := True; { Default return true }
  363. END;
  364. {--TValidator---------------------------------------------------------------}
  365. { Transfer -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  366. {---------------------------------------------------------------------------}
  367. FUNCTION TValidator.Transfer (Var S: String; Buffer: Pointer;
  368. Flag: TVTransfer): Word;
  369. BEGIN
  370. Transfer := 0; { Default return zero }
  371. END;
  372. {--TValidator---------------------------------------------------------------}
  373. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  374. {---------------------------------------------------------------------------}
  375. PROCEDURE TValidator.Error;
  376. BEGIN { Abstract method }
  377. END;
  378. {--TValidator---------------------------------------------------------------}
  379. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  380. {---------------------------------------------------------------------------}
  381. PROCEDURE TValidator.Store (Var S: TStream);
  382. BEGIN
  383. S.Write(Options, SizeOf(Options)); { Write options }
  384. END;
  385. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  386. { TPXPictureValidator OBJECT METHODS }
  387. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  388. {--TPXPictureValidator------------------------------------------------------}
  389. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  390. {---------------------------------------------------------------------------}
  391. CONSTRUCTOR TPXPictureValidator.Init (Const APic: String; AutoFill: Boolean);
  392. VAR S: String;
  393. BEGIN
  394. Inherited Init; { Call ancestor }
  395. Pic := NewStr(APic); { Hold filename }
  396. Options := voOnAppend; { Preset option mask }
  397. If AutoFill Then Options := Options OR voFill; { Check/set fill mask }
  398. S := ''; { Create empty string }
  399. If (Picture(S, False) <> prEmpty) Then { Check for empty }
  400. Status := vsSyntax; { Set error mask }
  401. END;
  402. {--TPXPictureValidator------------------------------------------------------}
  403. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  404. {---------------------------------------------------------------------------}
  405. CONSTRUCTOR TPXPictureValidator.Load (Var S: TStream);
  406. BEGIN
  407. Inherited Load(S); { Call ancestor }
  408. Pic := S.ReadStr; { Read filename }
  409. END;
  410. {--TPXPictureValidator------------------------------------------------------}
  411. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  412. {---------------------------------------------------------------------------}
  413. DESTRUCTOR TPXPictureValidator.Done;
  414. BEGIN
  415. If (Pic <> Nil) Then DisposeStr(Pic); { Dispose of filename }
  416. Inherited Done; { Call ancestor }
  417. END;
  418. {--TPXPictureValidator------------------------------------------------------}
  419. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  420. {---------------------------------------------------------------------------}
  421. FUNCTION TPXPictureValidator.IsValid (Const S: String): Boolean;
  422. VAR Str: String; Rslt: TPicResult;
  423. BEGIN
  424. Str := S; { Transfer string }
  425. Rslt := Picture(Str, False); { Check for picture }
  426. IsValid := (Pic = nil) OR (Rslt = prComplete) OR
  427. (Rslt = prEmpty); { Return result }
  428. END;
  429. {--TPXPictureValidator------------------------------------------------------}
  430. { IsValidInput -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  431. {---------------------------------------------------------------------------}
  432. FUNCTION TPXPictureValidator.IsValidInput (Var S: String;
  433. SuppressFill: Boolean): Boolean;
  434. BEGIN
  435. IsValidInput := (Pic = Nil) OR (Picture(S,
  436. (Options AND voFill <> 0) AND NOT SuppressFill)
  437. <> prError); { Return input result }
  438. END;
  439. {--TPXPictureValidator------------------------------------------------------}
  440. { Picture -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  441. {---------------------------------------------------------------------------}
  442. FUNCTION TPXPictureValidator.Picture (Var Input: String; AutoFill: Boolean): TPicResult;
  443. VAR I, J: Byte; Rslt: TPicResult; Reprocess: Boolean;
  444. FUNCTION Process (TermCh: Byte): TPicResult;
  445. VAR Rslt: TPicResult; Incomp: Boolean; OldI, OldJ, IncompJ, IncompI: Byte;
  446. PROCEDURE Consume (Ch: Char);
  447. BEGIN
  448. Input[J] := Ch; { Return character }
  449. Inc(J); { Inc count J }
  450. Inc(I); { Inc count I }
  451. END;
  452. PROCEDURE ToGroupEnd (Var I: Byte);
  453. VAR BrkLevel, BrcLevel: Integer;
  454. BEGIN
  455. BrkLevel := 0; { Zero bracket level }
  456. BrcLevel := 0; { Zero bracket level }
  457. Repeat
  458. If (I <> TermCh) Then Begin { Not end }
  459. Case Pic^[I] Of
  460. '[': Inc(BrkLevel); { Inc bracket level }
  461. ']': Dec(BrkLevel); { Dec bracket level }
  462. '{': Inc(BrcLevel); { Inc bracket level }
  463. '}': Dec(BrcLevel); { Dec bracket level }
  464. ';': Inc(I); { Next character }
  465. '*': Begin
  466. Inc(I); { Next character }
  467. While IsNumber(Pic^[I]) Do Inc(I); { Search for text }
  468. ToGroupEnd(I); { Move to group end }
  469. Continue; { Now continue }
  470. End;
  471. End;
  472. Inc(I); { Next character }
  473. End;
  474. Until ((BrkLevel = 0) AND (BrcLevel = 0)) OR { Both levels must be 0 }
  475. (I = TermCh); { Terminal character }
  476. END;
  477. FUNCTION SkipToComma: Boolean;
  478. BEGIN
  479. Repeat
  480. ToGroupEnd(I); { Find group end }
  481. Until (I = TermCh) OR (Pic^[I] = ','); { Terminator found }
  482. If (Pic^[I] = ',') Then Inc(I); { Comma so continue }
  483. SkipToComma := (I < TermCh); { Return result }
  484. END;
  485. FUNCTION CalcTerm: Byte;
  486. VAR K: Byte;
  487. BEGIN
  488. K := I; { Hold count }
  489. ToGroupEnd(K); { Find group end }
  490. CalcTerm := K; { Return count }
  491. END;
  492. FUNCTION Iteration: TPicResult;
  493. VAR Itr, K, L: Byte; Rslt: TPicResult; NewTermCh: Byte;
  494. BEGIN
  495. Itr := 0; { Zero iteration }
  496. Iteration := prError; { Preset error result }
  497. Inc(I); { Skip '*' character }
  498. While (IsNumber(Pic^[I])) Do Begin { Entry is a number }
  499. Itr := Itr * 10 + Byte(Pic^[I]) - Byte('0'); { Convert to number }
  500. Inc(I); { Next character }
  501. End;
  502. If (I <= TermCh) Then Begin { Not end of name }
  503. K := I; { Hold count }
  504. NewTermCh := CalcTerm; { Calc next terminator }
  505. If (Itr <> 0) Then Begin
  506. For L := 1 To Itr Do Begin { For each character }
  507. I := K; { Reset count }
  508. Rslt := Process(NewTermCh); { Process new entry }
  509. If (NOT IsComplete(Rslt)) Then Begin { Not empty }
  510. If (Rslt = prEmpty) Then { Check result }
  511. Rslt := prIncomplete; { Return incomplete }
  512. Iteration := Rslt; { Return result }
  513. Exit; { Now exit }
  514. End;
  515. End;
  516. End Else Begin
  517. Repeat
  518. I := K; { Hold count }
  519. Rslt := Process(NewTermCh); { Process new entry }
  520. Until (NOT IsComplete(Rslt)); { Until complete }
  521. If (Rslt = prEmpty) OR (Rslt = prError) { Check for any error }
  522. Then Begin
  523. Inc(I); { Next character }
  524. Rslt := prAmbiguous; { Return result }
  525. End;
  526. End;
  527. I := NewTermCh; { Find next name }
  528. End Else Rslt := prSyntax; { Completed }
  529. Iteration := Rslt; { Return result }
  530. END;
  531. FUNCTION Group: TPicResult;
  532. VAR Rslt: TPicResult; TermCh: Byte;
  533. BEGIN
  534. TermCh := CalcTerm; { Calc new term }
  535. Inc(I); { Next character }
  536. Rslt := Process(TermCh - 1); { Process the name }
  537. If (NOT IsIncomplete(Rslt)) Then I := TermCh; { Did not complete }
  538. Group := Rslt; { Return result }
  539. END;
  540. FUNCTION CheckComplete (Rslt: TPicResult): TPicResult;
  541. VAR J: Byte;
  542. BEGIN
  543. J := I; { Hold count }
  544. If IsIncomplete(Rslt) Then Begin { Check if complete }
  545. While True Do
  546. Case Pic^[J] Of
  547. '[': ToGroupEnd(J); { Find name end }
  548. '*': If (IsNumber(Pic^[J + 1]) = False)
  549. Then Begin
  550. Inc(J); { Next name }
  551. ToGroupEnd(J); { Find name end }
  552. End Else Break;
  553. Else Break;
  554. End;
  555. If (J = TermCh) Then Rslt := prAmbiguous; { End of name }
  556. End;
  557. CheckComplete := Rslt; { Return result }
  558. END;
  559. FUNCTION Scan: TPicResult;
  560. VAR Ch: Char; Rslt: TPicResult;
  561. BEGIN
  562. Scan := prError; { Preset return error }
  563. Rslt := prEmpty; { Preset empty result }
  564. While (I <> TermCh) AND (Pic^[I] <> ',') { For each entry }
  565. Do Begin
  566. If (J > Length(Input)) Then Begin { Move beyond length }
  567. Scan := CheckComplete(Rslt); { Return result }
  568. Exit; { Now exit }
  569. End;
  570. Ch := Input[J]; { Fetch character }
  571. Case Pic^[I] of
  572. '#': If (NOT IsNumber(Ch)) Then Exit { Check is a number }
  573. Else Consume(Ch); { Transfer number }
  574. '?': If (NOT IsLetter(Ch)) Then Exit { Check is a letter }
  575. Else Consume(Ch); { Transfer character }
  576. '&': If (NOT IsLetter(Ch)) Then Exit { Check is a letter }
  577. Else Consume(UpCase(Ch)); { Transfer character }
  578. '!': Consume(UpCase(Ch)); { Transfer character }
  579. '@': Consume(Ch); { Transfer character }
  580. '*': Begin
  581. Rslt := Iteration; { Now re-iterate }
  582. If (NOT IsComplete(Rslt)) Then Begin { Check not complete }
  583. Scan := Rslt; { Return result }
  584. Exit; { Now exit }
  585. End;
  586. If (Rslt = prError) Then { Check for error }
  587. Rslt := prAmbiguous; { Return ambiguous }
  588. End;
  589. '{': Begin
  590. Rslt := Group; { Return group }
  591. If (NOT IsComplete(Rslt)) Then Begin { Not incomplete check }
  592. Scan := Rslt; { Return result }
  593. Exit; { Now exit }
  594. End;
  595. End;
  596. '[': Begin
  597. Rslt := Group; { Return group }
  598. If IsIncomplete(Rslt) Then Begin { Incomplete check }
  599. Scan := Rslt; { Return result }
  600. Exit; { Now exit }
  601. End;
  602. If (Rslt = prError) Then { Check for error }
  603. Rslt := prAmbiguous; { Return ambiguous }
  604. End;
  605. Else If Pic^[I] = ';' Then Inc(I); { Move fwd for follow }
  606. If (UpCase(Pic^[I]) <> UpCase(Ch)) Then { Characters differ }
  607. If (Ch = ' ') Then Ch := Pic^[I] { Ignore space }
  608. Else Exit;
  609. Consume(Pic^[I]); { Consume character }
  610. End; { Case }
  611. If (Rslt = prAmbiguous) Then { If ambiguous result }
  612. Rslt := prIncompNoFill { Set incomplete fill }
  613. Else Rslt := prIncomplete; { Set incomplete }
  614. End;{ While}
  615. If (Rslt = prIncompNoFill) Then { Check incomp fill }
  616. Scan := prAmbiguous Else { Return ambiguous }
  617. Scan := prComplete; { Return completed }
  618. END;
  619. BEGIN
  620. Incomp := False; { Clear incomplete }
  621. InCompJ:=0; { set to avoid a warning }
  622. OldI := I; { Hold I count }
  623. OldJ := J; { Hold J count }
  624. Repeat
  625. Rslt := Scan; { Scan names }
  626. If (Rslt IN [prComplete, prAmbiguous]) AND
  627. Incomp AND (J < IncompJ) Then Begin { Check if complete }
  628. Rslt := prIncomplete; { Return result }
  629. J := IncompJ; { Return position }
  630. End;
  631. If ((Rslt = prError) OR (Rslt = prIncomplete)) { Check no errors }
  632. Then Begin
  633. Process := Rslt; { Hold result }
  634. If ((NOT Incomp) AND (Rslt = prIncomplete)) { Check complete }
  635. Then Begin
  636. Incomp := True; { Set incomplete }
  637. IncompI := I; { Set current position }
  638. IncompJ := J; { Set current position }
  639. End;
  640. I := OldI; { Restore held value }
  641. J := OldJ; { Restore held value }
  642. If (NOT SkipToComma) Then Begin { Check not comma }
  643. If Incomp Then Begin { Check incomplete }
  644. Process := prIncomplete; { Set incomplete mask }
  645. I := IncompI; { Hold incomp position }
  646. J := IncompJ; { Hold incomp position }
  647. End;
  648. Exit; { Now exit }
  649. End;
  650. OldI := I; { Hold position }
  651. End;
  652. Until (Rslt <> prError) AND { Check for error }
  653. (Rslt <> prIncomplete); { Incomplete load }
  654. If (Rslt = prComplete) AND Incomp Then { Complete load }
  655. Process := prAmbiguous Else { Return completed }
  656. Process := Rslt; { Return result }
  657. END;
  658. FUNCTION SyntaxCheck: Boolean;
  659. VAR I, BrkLevel, BrcLevel: Integer;
  660. Begin
  661. SyntaxCheck := False; { Preset false result }
  662. If (Pic^ <> '') AND (Pic^[Length(Pic^)] <> ';') { Name is valid }
  663. AND ((Pic^[Length(Pic^)] = '*') AND
  664. (Pic^[Length(Pic^) - 1] <> ';') = False) { Not wildcard list }
  665. Then Begin
  666. I := 1; { Set count to 1 }
  667. BrkLevel := 0; { Zero bracket level }
  668. BrcLevel := 0; { Zero bracket level }
  669. While (I <= Length(Pic^)) Do Begin { For each character }
  670. Case Pic^[I] Of
  671. '[': Inc(BrkLevel); { Inc bracket level }
  672. ']': Dec(BrkLevel); { Dec bracket level }
  673. '{': Inc(BrcLevel); { Inc bracket level }
  674. '}': Dec(BrcLevel); { Dec bracket level }
  675. ';': Inc(I); { Next character }
  676. End;
  677. Inc(I); { Next character }
  678. End;
  679. If (BrkLevel = 0) AND (BrcLevel = 0) Then { Check both levels 0 }
  680. SyntaxCheck := True; { Return true syntax }
  681. End;
  682. End;
  683. BEGIN
  684. Picture := prSyntax; { Preset error default }
  685. If SyntaxCheck Then Begin { Check syntax }
  686. Picture := prEmpty; { Preset picture empty }
  687. If (Input <> '') Then Begin { We have an input }
  688. J := 1; { Set J count to 1 }
  689. I := 1; { Set I count to 1 }
  690. Rslt := Process(Length(Pic^) + 1); { Set end of name }
  691. If (Rslt <> prError) AND (Rslt <> prSyntax) AND
  692. (J <= Length(Input)) Then Rslt := prError; { Check for any error }
  693. If (Rslt = prIncomplete) AND AutoFill { Check autofill flags }
  694. Then Begin
  695. Reprocess := False; { Set reprocess false }
  696. while (I <= Length(Pic^)) AND (NOT { Not at end of name }
  697. IsSpecial(Pic^[I], '#?&!@*{}[],'#0)) { No special chars }
  698. DO Begin
  699. If Pic^[I] = ';' Then Inc(I); { Check for next mark }
  700. Input := Input + Pic^[I]; { Move to that name }
  701. Inc(I); { Inc count }
  702. Reprocess := True; { Set reprocess flag }
  703. End;
  704. J := 1; { Set J count to 1 }
  705. I := 1; { Set I count to 1 }
  706. If Reprocess Then { Check for reprocess }
  707. Rslt := Process(Length(Pic^) + 1); { Move to next name }
  708. End;
  709. If (Rslt = prAmbiguous) Then { Result ambiguous }
  710. Picture := prComplete Else { Return completed }
  711. If (Rslt = prInCompNoFill) Then { Result incomplete }
  712. Picture := prIncomplete Else { Return incomplete }
  713. Picture := Rslt; { Return result }
  714. End;
  715. End;
  716. END;
  717. {--TPXPictureValidator------------------------------------------------------}
  718. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  719. {---------------------------------------------------------------------------}
  720. PROCEDURE TPXPictureValidator.Error;
  721. CONST PXErrMsg = 'Input does not conform to picture:';
  722. VAR S: String;
  723. BEGIN
  724. If (Pic <> Nil) Then S := Pic^ Else S := 'No name';{ Transfer filename }
  725. MessageBox(PxErrMsg + #13' %s', @S, mfError OR
  726. mfOKButton); { Message box }
  727. END;
  728. {--TPXPictureValidator------------------------------------------------------}
  729. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  730. {---------------------------------------------------------------------------}
  731. PROCEDURE TPXPictureValidator.Store (Var S: TStream);
  732. BEGIN
  733. TValidator.Store(S); { TValidator.store call }
  734. S.WriteStr(Pic); { Write filename }
  735. END;
  736. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  737. { TFilterValidator OBJECT METHODS }
  738. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  739. {--TFilterValidator---------------------------------------------------------}
  740. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  741. {---------------------------------------------------------------------------}
  742. CONSTRUCTOR TFilterValidator.Init (AValidChars: CharSet);
  743. BEGIN
  744. Inherited Init; { Call ancestor }
  745. ValidChars := AValidChars; { Hold valid char set }
  746. END;
  747. {--TFilterValidator---------------------------------------------------------}
  748. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  749. {---------------------------------------------------------------------------}
  750. CONSTRUCTOR TFilterValidator.Load (Var S: TStream);
  751. BEGIN
  752. Inherited Load(S); { Call ancestor }
  753. S.Read(ValidChars, SizeOf(ValidChars)); { Read valid char set }
  754. END;
  755. {--TFilterValidator---------------------------------------------------------}
  756. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  757. {---------------------------------------------------------------------------}
  758. FUNCTION TFilterValidator.IsValid (Const S: String): Boolean;
  759. VAR I: Integer;
  760. BEGIN
  761. I := 1; { Start at position 1 }
  762. While S[I] In ValidChars Do Inc(I); { Check each char }
  763. If (I > Length(S)) Then IsValid := True Else { All characters valid }
  764. IsValid := False; { Invalid characters }
  765. END;
  766. {--TFilterValidator---------------------------------------------------------}
  767. { IsValidInput -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  768. {---------------------------------------------------------------------------}
  769. FUNCTION TFilterValidator.IsValidInput (Var S: String; SuppressFill: Boolean): Boolean;
  770. VAR I: Integer;
  771. BEGIN
  772. I := 1; { Start at position 1 }
  773. While S[I] In ValidChars Do Inc(I); { Check each char }
  774. If (I > Length(S)) Then IsValidInput := True { All characters valid }
  775. Else IsValidInput := False; { Invalid characters }
  776. END;
  777. {--TFilterValidator---------------------------------------------------------}
  778. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  779. {---------------------------------------------------------------------------}
  780. PROCEDURE TFilterValidator.Error;
  781. CONST PXErrMsg = 'Invalid character in input';
  782. BEGIN
  783. MessageBox(PXErrMsg, Nil, mfError OR mfOKButton); { Show error message }
  784. END;
  785. {--TFilterValidator---------------------------------------------------------}
  786. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  787. {---------------------------------------------------------------------------}
  788. PROCEDURE TFilterValidator.Store (Var S: TStream);
  789. BEGIN
  790. TValidator.Store(S); { TValidator.Store call }
  791. S.Write(ValidChars, SizeOf(ValidChars)); { Write valid char set }
  792. END;
  793. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  794. { TRangeValidator OBJECT METHODS }
  795. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  796. {--TRangeValidator----------------------------------------------------------}
  797. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  798. {---------------------------------------------------------------------------}
  799. CONSTRUCTOR TRangeValidator.Init (AMin, AMax: LongInt);
  800. BEGIN
  801. Inherited Init(['0'..'9','+','-']); { Call ancestor }
  802. If (AMin >= 0) Then { Check min value > 0 }
  803. ValidChars := ValidChars - ['-']; { Is so no negatives }
  804. Min := AMin; { Hold min value }
  805. Max := AMax; { Hold max value }
  806. END;
  807. {--TRangeValidator----------------------------------------------------------}
  808. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  809. {---------------------------------------------------------------------------}
  810. CONSTRUCTOR TRangeValidator.Load (Var S: TStream);
  811. BEGIN
  812. Inherited Load(S); { Call ancestor }
  813. S.Read(Min, SizeOf(Min)); { Read min value }
  814. S.Read(Max, SizeOf(Max)); { Read max value }
  815. END;
  816. {--TRangeValidator----------------------------------------------------------}
  817. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  818. {---------------------------------------------------------------------------}
  819. FUNCTION TRangeValidator.IsValid (Const S: String): Boolean;
  820. VAR Value: LongInt; Code: Sw_Integer;
  821. BEGIN
  822. IsValid := False; { Preset false result }
  823. If Inherited IsValid(S) Then Begin { Call ancestor }
  824. Val(S, Value, Code); { Convert to number }
  825. If (Value >= Min) AND (Value <= Max) { With valid range }
  826. AND (Code = 0) Then IsValid := True; { No illegal chars }
  827. End;
  828. END;
  829. {--TRangeValidator----------------------------------------------------------}
  830. { Transfer -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  831. {---------------------------------------------------------------------------}
  832. FUNCTION TRangeValidator.Transfer (Var S: String; Buffer: Pointer; Flag: TVTransfer): Word;
  833. VAR Value: LongInt; Code: Sw_Integer;
  834. BEGIN
  835. If (Options AND voTransfer <> 0) Then Begin { Tranfer mask set }
  836. Transfer := SizeOf(Value); { Transfer a longint }
  837. Case Flag Of
  838. vtGetData: Begin
  839. Val(S, Value, Code); { Convert s to number }
  840. LongInt(Buffer^) := Value; { Transfer result }
  841. End;
  842. vtSetData: Str(LongInt(Buffer^), S); { Convert to string s }
  843. End;
  844. End Else Transfer := 0; { No transfer = zero }
  845. END;
  846. {--TRangeValidator----------------------------------------------------------}
  847. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  848. {---------------------------------------------------------------------------}
  849. PROCEDURE TRangeValidator.Error;
  850. CONST PXErrMsg = 'Value not in the range';
  851. VAR Params: Array[0..1] Of Longint;
  852. BEGIN
  853. Params[0] := Min; { Transfer min value }
  854. Params[1] := Max; { Transfer max value }
  855. MessageBox(PXErrMsg+' %d to %d', @Params,
  856. mfError OR mfOKButton); { Display message }
  857. END;
  858. {--TRangeValidator----------------------------------------------------------}
  859. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  860. {---------------------------------------------------------------------------}
  861. PROCEDURE TRangeValidator.Store (Var S: TStream);
  862. BEGIN
  863. TFilterValidator.Store(S); { TFilterValidator.Store }
  864. S.Write(Min, SizeOf(Min)); { Write min value }
  865. S.Write(Max, SizeOf(Max)); { Write max value }
  866. END;
  867. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  868. { TLookUpValidator OBJECT METHODS }
  869. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  870. {--TLookUpValidator---------------------------------------------------------}
  871. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  872. {---------------------------------------------------------------------------}
  873. FUNCTION TLookUpValidator.IsValid (Const S: String): Boolean;
  874. BEGIN
  875. IsValid := LookUp(S); { Check for string }
  876. END;
  877. {--TLookUpValidator---------------------------------------------------------}
  878. { LookUp -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  879. {---------------------------------------------------------------------------}
  880. FUNCTION TLookupValidator.Lookup (Const S: String): Boolean;
  881. BEGIN
  882. Lookup := True; { Default return true }
  883. END;
  884. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  885. { TStringLookUpValidator OBJECT METHODS }
  886. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  887. {--TStringLookUpValidator---------------------------------------------------}
  888. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  889. {---------------------------------------------------------------------------}
  890. CONSTRUCTOR TStringLookUpValidator.Init (AStrings: PStringCollection);
  891. BEGIN
  892. Inherited Init; { Call ancestor }
  893. Strings := AStrings; { Hold string list }
  894. END;
  895. {--TStringLookUpValidator---------------------------------------------------}
  896. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  897. {---------------------------------------------------------------------------}
  898. CONSTRUCTOR TStringLookUpValidator.Load (Var S: TStream);
  899. BEGIN
  900. Inherited Load(S); { Call ancestor }
  901. Strings := PStringCollection(S.Get); { Fecth string list }
  902. END;
  903. {--TStringLookUpValidator---------------------------------------------------}
  904. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  905. {---------------------------------------------------------------------------}
  906. DESTRUCTOR TStringLookUpValidator.Done;
  907. BEGIN
  908. NewStringList(Nil); { Dispsoe string list }
  909. Inherited Done; { Call ancestor }
  910. END;
  911. {--TStringLookUpValidator---------------------------------------------------}
  912. { Lookup -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  913. {---------------------------------------------------------------------------}
  914. FUNCTION TStringLookUpValidator.Lookup (Const S: String): Boolean;
  915. {$IFDEF PPC_VIRTUAL} VAR Index: LongInt; {$ELSE} VAR Index: sw_Integer; {$ENDIF}
  916. BEGIN
  917. Lookup := False; { Preset false return }
  918. If (Strings <> Nil) Then
  919. Lookup := Strings^.Search(@S, Index); { Search for string }
  920. END;
  921. {--TStringLookUpValidator---------------------------------------------------}
  922. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  923. {---------------------------------------------------------------------------}
  924. PROCEDURE TStringLookUpValidator.Error;
  925. CONST PXErrMsg = 'Input not in valid-list';
  926. BEGIN
  927. MessageBox(PXErrMsg, Nil, mfError OR mfOKButton); { Display message }
  928. END;
  929. {--TStringLookUpValidator---------------------------------------------------}
  930. { NewStringList -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  931. {---------------------------------------------------------------------------}
  932. PROCEDURE TStringLookUpValidator.NewStringList (AStrings: PStringCollection);
  933. BEGIN
  934. If (Strings <> Nil) Then Dispose(Strings, Done); { Free old string list }
  935. Strings := AStrings; { Hold new string list }
  936. END;
  937. {--TStringLookUpValidator---------------------------------------------------}
  938. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  939. {---------------------------------------------------------------------------}
  940. PROCEDURE TStringLookUpValidator.Store (Var S: TStream);
  941. BEGIN
  942. TLookupValidator.Store(S); { TlookupValidator call }
  943. S.Put(Strings); { Now store strings }
  944. END;
  945. {***************************************************************************}
  946. { INTERFACE ROUTINES }
  947. {***************************************************************************}
  948. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  949. { OBJECT REGISTER ROUTINES }
  950. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  951. {---------------------------------------------------------------------------}
  952. { RegisterValidate -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  953. {---------------------------------------------------------------------------}
  954. PROCEDURE RegisterValidate;
  955. BEGIN
  956. RegisterType(RPXPictureValidator); { Register viewer }
  957. RegisterType(RFilterValidator); { Register filter }
  958. RegisterType(RRangeValidator); { Register validator }
  959. RegisterType(RStringLookupValidator); { Register str lookup }
  960. END;
  961. END.