validate.pas 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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. { IsLetter -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  275. {---------------------------------------------------------------------------}
  276. FUNCTION IsLetter (Chr: Char): Boolean;
  277. BEGIN
  278. Chr := Char(Ord(Chr) AND $DF); { Lower to upper case }
  279. If (Chr >= 'A') AND (Chr <='Z') Then { Check if A..Z }
  280. IsLetter := True Else IsLetter := False; { Return result }
  281. END;
  282. {---------------------------------------------------------------------------}
  283. { IsComplete -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  284. {---------------------------------------------------------------------------}
  285. FUNCTION IsComplete (Rslt: TPicResult): Boolean;
  286. BEGIN
  287. IsComplete := Rslt IN [prComplete, prAmbiguous]; { Return if complete }
  288. END;
  289. {---------------------------------------------------------------------------}
  290. { IsInComplete -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  291. {---------------------------------------------------------------------------}
  292. FUNCTION IsIncomplete (Rslt: TPicResult): Boolean;
  293. BEGIN
  294. IsIncomplete := Rslt IN
  295. [prIncomplete, prIncompNoFill]; { Return if incomplete }
  296. END;
  297. {---------------------------------------------------------------------------}
  298. { NumChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  299. {---------------------------------------------------------------------------}
  300. FUNCTION NumChar (Chr: Char; Const S: String): Byte;
  301. VAR I, Total: Byte;
  302. BEGIN
  303. Total := 0; { Zero total }
  304. For I := 1 To Length(S) Do { For entire string }
  305. If (S[I] = Chr) Then Inc(Total); { Count matches of Chr }
  306. NumChar := Total; { Return char count }
  307. END;
  308. {---------------------------------------------------------------------------}
  309. { IsSpecial -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  310. {---------------------------------------------------------------------------}
  311. FUNCTION IsSpecial (Chr: Char; Const Special: String): Boolean;
  312. VAR Rslt: Boolean; I: Byte;
  313. BEGIN
  314. Rslt := False; { Preset false result }
  315. For I := 1 To Length(Special) Do
  316. If (Special[I] = Chr) Then Rslt := True; { Character found }
  317. IsSpecial := Rslt; { Return result }
  318. END;
  319. {***************************************************************************}
  320. { OBJECT METHODS }
  321. {***************************************************************************}
  322. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  323. { TValidator OBJECT METHODS }
  324. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  325. {--TValidator---------------------------------------------------------------}
  326. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  327. {---------------------------------------------------------------------------}
  328. CONSTRUCTOR TValidator.Load (Var S:TStream);
  329. BEGIN
  330. Inherited Init; { Call ancestor }
  331. S.Read(Options, SizeOf(Options)); { Read option masks }
  332. END;
  333. {--TValidator---------------------------------------------------------------}
  334. { Valid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  335. {---------------------------------------------------------------------------}
  336. FUNCTION TValidator.Valid (Const S: String): Boolean;
  337. BEGIN
  338. Valid := False; { Preset false result }
  339. If Not IsValid(S) Then Error { Check for error }
  340. Else Valid := True; { Return valid result }
  341. END;
  342. {--TValidator---------------------------------------------------------------}
  343. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  344. {---------------------------------------------------------------------------}
  345. FUNCTION TValidator.IsValid (Const S: String): Boolean;
  346. BEGIN
  347. IsValid := True; { Default return valid }
  348. END;
  349. {--TValidator---------------------------------------------------------------}
  350. { IsValidInput -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  351. {---------------------------------------------------------------------------}
  352. FUNCTION TValidator.IsValidInput (Var S: String; SuppressFill: Boolean): Boolean;
  353. BEGIN
  354. IsValidInput := True; { Default return true }
  355. END;
  356. {--TValidator---------------------------------------------------------------}
  357. { Transfer -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  358. {---------------------------------------------------------------------------}
  359. FUNCTION TValidator.Transfer (Var S: String; Buffer: Pointer;
  360. Flag: TVTransfer): Word;
  361. BEGIN
  362. Transfer := 0; { Default return zero }
  363. END;
  364. {--TValidator---------------------------------------------------------------}
  365. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  366. {---------------------------------------------------------------------------}
  367. PROCEDURE TValidator.Error;
  368. BEGIN { Abstract method }
  369. END;
  370. {--TValidator---------------------------------------------------------------}
  371. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  372. {---------------------------------------------------------------------------}
  373. PROCEDURE TValidator.Store (Var S: TStream);
  374. BEGIN
  375. S.Write(Options, SizeOf(Options)); { Write options }
  376. END;
  377. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  378. { TPXPictureValidator OBJECT METHODS }
  379. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  380. {--TPXPictureValidator------------------------------------------------------}
  381. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  382. {---------------------------------------------------------------------------}
  383. CONSTRUCTOR TPXPictureValidator.Init (Const APic: String; AutoFill: Boolean);
  384. VAR S: String;
  385. BEGIN
  386. Inherited Init; { Call ancestor }
  387. Pic := NewStr(APic); { Hold filename }
  388. Options := voOnAppend; { Preset option mask }
  389. If AutoFill Then Options := Options OR voFill; { Check/set fill mask }
  390. S := ''; { Create empty string }
  391. If (Picture(S, False) <> prEmpty) Then { Check for empty }
  392. Status := vsSyntax; { Set error mask }
  393. END;
  394. {--TPXPictureValidator------------------------------------------------------}
  395. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  396. {---------------------------------------------------------------------------}
  397. CONSTRUCTOR TPXPictureValidator.Load (Var S: TStream);
  398. BEGIN
  399. Inherited Load(S); { Call ancestor }
  400. Pic := S.ReadStr; { Read filename }
  401. END;
  402. {--TPXPictureValidator------------------------------------------------------}
  403. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  404. {---------------------------------------------------------------------------}
  405. DESTRUCTOR TPXPictureValidator.Done;
  406. BEGIN
  407. If (Pic <> Nil) Then DisposeStr(Pic); { Dispose of filename }
  408. Inherited Done; { Call ancestor }
  409. END;
  410. {--TPXPictureValidator------------------------------------------------------}
  411. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  412. {---------------------------------------------------------------------------}
  413. FUNCTION TPXPictureValidator.IsValid (Const S: String): Boolean;
  414. VAR Str: String; Rslt: TPicResult;
  415. BEGIN
  416. Str := S; { Transfer string }
  417. Rslt := Picture(Str, False); { Check for picture }
  418. IsValid := (Pic = nil) OR (Rslt = prComplete) OR
  419. (Rslt = prEmpty); { Return result }
  420. END;
  421. {--TPXPictureValidator------------------------------------------------------}
  422. { IsValidInput -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  423. {---------------------------------------------------------------------------}
  424. FUNCTION TPXPictureValidator.IsValidInput (Var S: String;
  425. SuppressFill: Boolean): Boolean;
  426. BEGIN
  427. IsValidInput := (Pic = Nil) OR (Picture(S,
  428. (Options AND voFill <> 0) AND NOT SuppressFill)
  429. <> prError); { Return input result }
  430. END;
  431. {--TPXPictureValidator------------------------------------------------------}
  432. { Picture -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  433. {---------------------------------------------------------------------------}
  434. FUNCTION TPXPictureValidator.Picture (Var Input: String; AutoFill: Boolean): TPicResult;
  435. VAR I, J: Byte; Rslt: TPicResult; Reprocess: Boolean;
  436. FUNCTION Process (TermCh: Byte): TPicResult;
  437. VAR Rslt: TPicResult; Incomp: Boolean; OldI, OldJ, IncompJ, IncompI: Byte;
  438. PROCEDURE Consume (Ch: Char);
  439. BEGIN
  440. Input[J] := Ch; { Return character }
  441. Inc(J); { Inc count J }
  442. Inc(I); { Inc count I }
  443. END;
  444. PROCEDURE ToGroupEnd (Var I: Byte);
  445. VAR BrkLevel, BrcLevel: Integer;
  446. BEGIN
  447. BrkLevel := 0; { Zero bracket level }
  448. BrcLevel := 0; { Zero bracket level }
  449. Repeat
  450. If (I <> TermCh) Then Begin { Not end }
  451. Case Pic^[I] Of
  452. '[': Inc(BrkLevel); { Inc bracket level }
  453. ']': Dec(BrkLevel); { Dec bracket level }
  454. '{': Inc(BrcLevel); { Inc bracket level }
  455. '}': Dec(BrcLevel); { Dec bracket level }
  456. ';': Inc(I); { Next character }
  457. '*': Begin
  458. Inc(I); { Next character }
  459. While Pic^[I] in ['0'..'9'] Do Inc(I); { Search for text }
  460. ToGroupEnd(I); { Move to group end }
  461. Continue; { Now continue }
  462. End;
  463. End;
  464. Inc(I); { Next character }
  465. End;
  466. Until ((BrkLevel = 0) AND (BrcLevel = 0)) OR { Both levels must be 0 }
  467. (I = TermCh); { Terminal character }
  468. END;
  469. FUNCTION SkipToComma: Boolean;
  470. BEGIN
  471. Repeat
  472. ToGroupEnd(I); { Find group end }
  473. Until (I = TermCh) OR (Pic^[I] = ','); { Terminator found }
  474. If (Pic^[I] = ',') Then Inc(I); { Comma so continue }
  475. SkipToComma := (I < TermCh); { Return result }
  476. END;
  477. FUNCTION CalcTerm: Byte;
  478. VAR K: Byte;
  479. BEGIN
  480. K := I; { Hold count }
  481. ToGroupEnd(K); { Find group end }
  482. CalcTerm := K; { Return count }
  483. END;
  484. FUNCTION Iteration: TPicResult;
  485. VAR Itr, K, L: Byte; Rslt: TPicResult; NewTermCh: Byte;
  486. BEGIN
  487. Itr := 0; { Zero iteration }
  488. Iteration := prError; { Preset error result }
  489. Inc(I); { Skip '*' character }
  490. While Pic^[I] in ['0'..'9'] Do Begin { Entry is a number }
  491. Itr := Itr * 10 + Byte(Pic^[I]) - Byte('0'); { Convert to number }
  492. Inc(I); { Next character }
  493. End;
  494. If (I <= TermCh) Then Begin { Not end of name }
  495. K := I; { Hold count }
  496. NewTermCh := CalcTerm; { Calc next terminator }
  497. If (Itr <> 0) Then Begin
  498. For L := 1 To Itr Do Begin { For each character }
  499. I := K; { Reset count }
  500. Rslt := Process(NewTermCh); { Process new entry }
  501. If (NOT IsComplete(Rslt)) Then Begin { Not empty }
  502. If (Rslt = prEmpty) Then { Check result }
  503. Rslt := prIncomplete; { Return incomplete }
  504. Iteration := Rslt; { Return result }
  505. Exit; { Now exit }
  506. End;
  507. End;
  508. End Else Begin
  509. Repeat
  510. I := K; { Hold count }
  511. Rslt := Process(NewTermCh); { Process new entry }
  512. Until (NOT IsComplete(Rslt)); { Until complete }
  513. If (Rslt = prEmpty) OR (Rslt = prError) { Check for any error }
  514. Then Begin
  515. Inc(I); { Next character }
  516. Rslt := prAmbiguous; { Return result }
  517. End;
  518. End;
  519. I := NewTermCh; { Find next name }
  520. End Else Rslt := prSyntax; { Completed }
  521. Iteration := Rslt; { Return result }
  522. END;
  523. FUNCTION Group: TPicResult;
  524. VAR Rslt: TPicResult; TermCh: Byte;
  525. BEGIN
  526. TermCh := CalcTerm; { Calc new term }
  527. Inc(I); { Next character }
  528. Rslt := Process(TermCh - 1); { Process the name }
  529. If (NOT IsIncomplete(Rslt)) Then I := TermCh; { Did not complete }
  530. Group := Rslt; { Return result }
  531. END;
  532. FUNCTION CheckComplete (Rslt: TPicResult): TPicResult;
  533. VAR J: Byte;
  534. BEGIN
  535. J := I; { Hold count }
  536. If IsIncomplete(Rslt) Then Begin { Check if complete }
  537. While True Do
  538. Case Pic^[J] Of
  539. '[': ToGroupEnd(J); { Find name end }
  540. '*': If not(Pic^[J + 1] in ['0'..'9'])
  541. Then Begin
  542. Inc(J); { Next name }
  543. ToGroupEnd(J); { Find name end }
  544. End Else Break;
  545. Else Break;
  546. End;
  547. If (J = TermCh) Then Rslt := prAmbiguous; { End of name }
  548. End;
  549. CheckComplete := Rslt; { Return result }
  550. END;
  551. FUNCTION Scan: TPicResult;
  552. VAR Ch: Char; Rslt: TPicResult;
  553. BEGIN
  554. Scan := prError; { Preset return error }
  555. Rslt := prEmpty; { Preset empty result }
  556. While (I <> TermCh) AND (Pic^[I] <> ',') { For each entry }
  557. Do Begin
  558. If (J > Length(Input)) Then Begin { Move beyond length }
  559. Scan := CheckComplete(Rslt); { Return result }
  560. Exit; { Now exit }
  561. End;
  562. Ch := Input[J]; { Fetch character }
  563. Case Pic^[I] of
  564. '#': If NOT (Ch in ['0'..'9']) Then Exit { Check is a number }
  565. Else Consume(Ch); { Transfer number }
  566. '?': If (NOT IsLetter(Ch)) Then Exit { Check is a letter }
  567. Else Consume(Ch); { Transfer character }
  568. '&': If (NOT IsLetter(Ch)) Then Exit { Check is a letter }
  569. Else Consume(UpCase(Ch)); { Transfer character }
  570. '!': Consume(UpCase(Ch)); { Transfer character }
  571. '@': Consume(Ch); { Transfer character }
  572. '*': Begin
  573. Rslt := Iteration; { Now re-iterate }
  574. If (NOT IsComplete(Rslt)) Then Begin { Check not complete }
  575. Scan := Rslt; { Return result }
  576. Exit; { Now exit }
  577. End;
  578. If (Rslt = prError) Then { Check for error }
  579. Rslt := prAmbiguous; { Return ambiguous }
  580. End;
  581. '{': Begin
  582. Rslt := Group; { Return group }
  583. If (NOT IsComplete(Rslt)) Then Begin { Not incomplete check }
  584. Scan := Rslt; { Return result }
  585. Exit; { Now exit }
  586. End;
  587. End;
  588. '[': Begin
  589. Rslt := Group; { Return group }
  590. If IsIncomplete(Rslt) Then Begin { Incomplete check }
  591. Scan := Rslt; { Return result }
  592. Exit; { Now exit }
  593. End;
  594. If (Rslt = prError) Then { Check for error }
  595. Rslt := prAmbiguous; { Return ambiguous }
  596. End;
  597. Else If Pic^[I] = ';' Then Inc(I); { Move fwd for follow }
  598. If (UpCase(Pic^[I]) <> UpCase(Ch)) Then { Characters differ }
  599. If (Ch = ' ') Then Ch := Pic^[I] { Ignore space }
  600. Else Exit;
  601. Consume(Pic^[I]); { Consume character }
  602. End; { Case }
  603. If (Rslt = prAmbiguous) Then { If ambiguous result }
  604. Rslt := prIncompNoFill { Set incomplete fill }
  605. Else Rslt := prIncomplete; { Set incomplete }
  606. End;{ While}
  607. If (Rslt = prIncompNoFill) Then { Check incomp fill }
  608. Scan := prAmbiguous Else { Return ambiguous }
  609. Scan := prComplete; { Return completed }
  610. END;
  611. BEGIN
  612. Incomp := False; { Clear incomplete }
  613. InCompJ:=0; { set to avoid a warning }
  614. OldI := I; { Hold I count }
  615. OldJ := J; { Hold J count }
  616. Repeat
  617. Rslt := Scan; { Scan names }
  618. If (Rslt IN [prComplete, prAmbiguous]) AND
  619. Incomp AND (J < IncompJ) Then Begin { Check if complete }
  620. Rslt := prIncomplete; { Return result }
  621. J := IncompJ; { Return position }
  622. End;
  623. If ((Rslt = prError) OR (Rslt = prIncomplete)) { Check no errors }
  624. Then Begin
  625. Process := Rslt; { Hold result }
  626. If ((NOT Incomp) AND (Rslt = prIncomplete)) { Check complete }
  627. Then Begin
  628. Incomp := True; { Set incomplete }
  629. IncompI := I; { Set current position }
  630. IncompJ := J; { Set current position }
  631. End;
  632. I := OldI; { Restore held value }
  633. J := OldJ; { Restore held value }
  634. If (NOT SkipToComma) Then Begin { Check not comma }
  635. If Incomp Then Begin { Check incomplete }
  636. Process := prIncomplete; { Set incomplete mask }
  637. I := IncompI; { Hold incomp position }
  638. J := IncompJ; { Hold incomp position }
  639. End;
  640. Exit; { Now exit }
  641. End;
  642. OldI := I; { Hold position }
  643. End;
  644. Until (Rslt <> prError) AND { Check for error }
  645. (Rslt <> prIncomplete); { Incomplete load }
  646. If (Rslt = prComplete) AND Incomp Then { Complete load }
  647. Process := prAmbiguous Else { Return completed }
  648. Process := Rslt; { Return result }
  649. END;
  650. FUNCTION SyntaxCheck: Boolean;
  651. VAR I, BrkLevel, BrcLevel: Integer;
  652. Begin
  653. SyntaxCheck := False; { Preset false result }
  654. If (Pic^ <> '') AND (Pic^[Length(Pic^)] <> ';') { Name is valid }
  655. AND ((Pic^[Length(Pic^)] = '*') AND
  656. (Pic^[Length(Pic^) - 1] <> ';') = False) { Not wildcard list }
  657. Then Begin
  658. I := 1; { Set count to 1 }
  659. BrkLevel := 0; { Zero bracket level }
  660. BrcLevel := 0; { Zero bracket level }
  661. While (I <= Length(Pic^)) Do Begin { For each character }
  662. Case Pic^[I] Of
  663. '[': Inc(BrkLevel); { Inc bracket level }
  664. ']': Dec(BrkLevel); { Dec bracket level }
  665. '{': Inc(BrcLevel); { Inc bracket level }
  666. '}': Dec(BrcLevel); { Dec bracket level }
  667. ';': Inc(I); { Next character }
  668. End;
  669. Inc(I); { Next character }
  670. End;
  671. If (BrkLevel = 0) AND (BrcLevel = 0) Then { Check both levels 0 }
  672. SyntaxCheck := True; { Return true syntax }
  673. End;
  674. End;
  675. BEGIN
  676. Picture := prSyntax; { Preset error default }
  677. If SyntaxCheck Then Begin { Check syntax }
  678. Picture := prEmpty; { Preset picture empty }
  679. If (Input <> '') Then Begin { We have an input }
  680. J := 1; { Set J count to 1 }
  681. I := 1; { Set I count to 1 }
  682. Rslt := Process(Length(Pic^) + 1); { Set end of name }
  683. If (Rslt <> prError) AND (Rslt <> prSyntax) AND
  684. (J <= Length(Input)) Then Rslt := prError; { Check for any error }
  685. If (Rslt = prIncomplete) AND AutoFill { Check autofill flags }
  686. Then Begin
  687. Reprocess := False; { Set reprocess false }
  688. while (I <= Length(Pic^)) AND (NOT { Not at end of name }
  689. IsSpecial(Pic^[I], '#?&!@*{}[],'#0)) { No special chars }
  690. DO Begin
  691. If Pic^[I] = ';' Then Inc(I); { Check for next mark }
  692. Input := Input + Pic^[I]; { Move to that name }
  693. Inc(I); { Inc count }
  694. Reprocess := True; { Set reprocess flag }
  695. End;
  696. J := 1; { Set J count to 1 }
  697. I := 1; { Set I count to 1 }
  698. If Reprocess Then { Check for reprocess }
  699. Rslt := Process(Length(Pic^) + 1); { Move to next name }
  700. End;
  701. If (Rslt = prAmbiguous) Then { Result ambiguous }
  702. Picture := prComplete Else { Return completed }
  703. If (Rslt = prInCompNoFill) Then { Result incomplete }
  704. Picture := prIncomplete Else { Return incomplete }
  705. Picture := Rslt; { Return result }
  706. End;
  707. End;
  708. END;
  709. {--TPXPictureValidator------------------------------------------------------}
  710. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  711. {---------------------------------------------------------------------------}
  712. PROCEDURE TPXPictureValidator.Error;
  713. CONST PXErrMsg = 'Input does not conform to picture:';
  714. VAR S: String;
  715. BEGIN
  716. If (Pic <> Nil) Then S := Pic^ Else S := 'No name';{ Transfer filename }
  717. MessageBox(PxErrMsg + #13' %s', @S, mfError OR
  718. mfOKButton); { Message box }
  719. END;
  720. {--TPXPictureValidator------------------------------------------------------}
  721. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  722. {---------------------------------------------------------------------------}
  723. PROCEDURE TPXPictureValidator.Store (Var S: TStream);
  724. BEGIN
  725. TValidator.Store(S); { TValidator.store call }
  726. S.WriteStr(Pic); { Write filename }
  727. END;
  728. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  729. { TFilterValidator OBJECT METHODS }
  730. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  731. {--TFilterValidator---------------------------------------------------------}
  732. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  733. {---------------------------------------------------------------------------}
  734. CONSTRUCTOR TFilterValidator.Init (AValidChars: CharSet);
  735. BEGIN
  736. Inherited Init; { Call ancestor }
  737. ValidChars := AValidChars; { Hold valid char set }
  738. END;
  739. {--TFilterValidator---------------------------------------------------------}
  740. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  741. {---------------------------------------------------------------------------}
  742. CONSTRUCTOR TFilterValidator.Load (Var S: TStream);
  743. BEGIN
  744. Inherited Load(S); { Call ancestor }
  745. S.Read(ValidChars, SizeOf(ValidChars)); { Read valid char set }
  746. END;
  747. {--TFilterValidator---------------------------------------------------------}
  748. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  749. {---------------------------------------------------------------------------}
  750. FUNCTION TFilterValidator.IsValid (Const S: String): Boolean;
  751. VAR I: Integer;
  752. BEGIN
  753. I := 1; { Start at position 1 }
  754. While S[I] In ValidChars Do Inc(I); { Check each char }
  755. If (I > Length(S)) Then IsValid := True Else { All characters valid }
  756. IsValid := False; { Invalid characters }
  757. END;
  758. {--TFilterValidator---------------------------------------------------------}
  759. { IsValidInput -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  760. {---------------------------------------------------------------------------}
  761. FUNCTION TFilterValidator.IsValidInput (Var S: String; SuppressFill: Boolean): Boolean;
  762. VAR I: Integer;
  763. BEGIN
  764. I := 1; { Start at position 1 }
  765. While S[I] In ValidChars Do Inc(I); { Check each char }
  766. If (I > Length(S)) Then IsValidInput := True { All characters valid }
  767. Else IsValidInput := False; { Invalid characters }
  768. END;
  769. {--TFilterValidator---------------------------------------------------------}
  770. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  771. {---------------------------------------------------------------------------}
  772. PROCEDURE TFilterValidator.Error;
  773. CONST PXErrMsg = 'Invalid character in input';
  774. BEGIN
  775. MessageBox(PXErrMsg, Nil, mfError OR mfOKButton); { Show error message }
  776. END;
  777. {--TFilterValidator---------------------------------------------------------}
  778. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  779. {---------------------------------------------------------------------------}
  780. PROCEDURE TFilterValidator.Store (Var S: TStream);
  781. BEGIN
  782. TValidator.Store(S); { TValidator.Store call }
  783. S.Write(ValidChars, SizeOf(ValidChars)); { Write valid char set }
  784. END;
  785. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  786. { TRangeValidator OBJECT METHODS }
  787. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  788. {--TRangeValidator----------------------------------------------------------}
  789. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  790. {---------------------------------------------------------------------------}
  791. CONSTRUCTOR TRangeValidator.Init (AMin, AMax: LongInt);
  792. BEGIN
  793. Inherited Init(['0'..'9','+','-']); { Call ancestor }
  794. If (AMin >= 0) Then { Check min value > 0 }
  795. ValidChars := ValidChars - ['-']; { Is so no negatives }
  796. Min := AMin; { Hold min value }
  797. Max := AMax; { Hold max value }
  798. END;
  799. {--TRangeValidator----------------------------------------------------------}
  800. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  801. {---------------------------------------------------------------------------}
  802. CONSTRUCTOR TRangeValidator.Load (Var S: TStream);
  803. BEGIN
  804. Inherited Load(S); { Call ancestor }
  805. S.Read(Min, SizeOf(Min)); { Read min value }
  806. S.Read(Max, SizeOf(Max)); { Read max value }
  807. END;
  808. {--TRangeValidator----------------------------------------------------------}
  809. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  810. {---------------------------------------------------------------------------}
  811. FUNCTION TRangeValidator.IsValid (Const S: String): Boolean;
  812. VAR Value: LongInt; Code: Sw_Integer;
  813. BEGIN
  814. IsValid := False; { Preset false result }
  815. If Inherited IsValid(S) Then Begin { Call ancestor }
  816. Val(S, Value, Code); { Convert to number }
  817. If (Value >= Min) AND (Value <= Max) { With valid range }
  818. AND (Code = 0) Then IsValid := True; { No illegal chars }
  819. End;
  820. END;
  821. {--TRangeValidator----------------------------------------------------------}
  822. { Transfer -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  823. {---------------------------------------------------------------------------}
  824. FUNCTION TRangeValidator.Transfer (Var S: String; Buffer: Pointer; Flag: TVTransfer): Word;
  825. VAR Value: LongInt; Code: Sw_Integer;
  826. BEGIN
  827. If (Options AND voTransfer <> 0) Then Begin { Tranfer mask set }
  828. Transfer := SizeOf(Value); { Transfer a longint }
  829. Case Flag Of
  830. vtGetData: Begin
  831. Val(S, Value, Code); { Convert s to number }
  832. LongInt(Buffer^) := Value; { Transfer result }
  833. End;
  834. vtSetData: Str(LongInt(Buffer^), S); { Convert to string s }
  835. End;
  836. End Else Transfer := 0; { No transfer = zero }
  837. END;
  838. {--TRangeValidator----------------------------------------------------------}
  839. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  840. {---------------------------------------------------------------------------}
  841. PROCEDURE TRangeValidator.Error;
  842. CONST PXErrMsg = 'Value not in the range';
  843. VAR Params: Array[0..1] Of Longint;
  844. BEGIN
  845. Params[0] := Min; { Transfer min value }
  846. Params[1] := Max; { Transfer max value }
  847. MessageBox(PXErrMsg+' %d to %d', @Params,
  848. mfError OR mfOKButton); { Display message }
  849. END;
  850. {--TRangeValidator----------------------------------------------------------}
  851. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  852. {---------------------------------------------------------------------------}
  853. PROCEDURE TRangeValidator.Store (Var S: TStream);
  854. BEGIN
  855. TFilterValidator.Store(S); { TFilterValidator.Store }
  856. S.Write(Min, SizeOf(Min)); { Write min value }
  857. S.Write(Max, SizeOf(Max)); { Write max value }
  858. END;
  859. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  860. { TLookUpValidator OBJECT METHODS }
  861. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  862. {--TLookUpValidator---------------------------------------------------------}
  863. { IsValid -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  864. {---------------------------------------------------------------------------}
  865. FUNCTION TLookUpValidator.IsValid (Const S: String): Boolean;
  866. BEGIN
  867. IsValid := LookUp(S); { Check for string }
  868. END;
  869. {--TLookUpValidator---------------------------------------------------------}
  870. { LookUp -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  871. {---------------------------------------------------------------------------}
  872. FUNCTION TLookupValidator.Lookup (Const S: String): Boolean;
  873. BEGIN
  874. Lookup := True; { Default return true }
  875. END;
  876. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  877. { TStringLookUpValidator OBJECT METHODS }
  878. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  879. {--TStringLookUpValidator---------------------------------------------------}
  880. { Init -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  881. {---------------------------------------------------------------------------}
  882. CONSTRUCTOR TStringLookUpValidator.Init (AStrings: PStringCollection);
  883. BEGIN
  884. Inherited Init; { Call ancestor }
  885. Strings := AStrings; { Hold string list }
  886. END;
  887. {--TStringLookUpValidator---------------------------------------------------}
  888. { Load -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  889. {---------------------------------------------------------------------------}
  890. CONSTRUCTOR TStringLookUpValidator.Load (Var S: TStream);
  891. BEGIN
  892. Inherited Load(S); { Call ancestor }
  893. Strings := PStringCollection(S.Get); { Fecth string list }
  894. END;
  895. {--TStringLookUpValidator---------------------------------------------------}
  896. { Done -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  897. {---------------------------------------------------------------------------}
  898. DESTRUCTOR TStringLookUpValidator.Done;
  899. BEGIN
  900. NewStringList(Nil); { Dispsoe string list }
  901. Inherited Done; { Call ancestor }
  902. END;
  903. {--TStringLookUpValidator---------------------------------------------------}
  904. { Lookup -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  905. {---------------------------------------------------------------------------}
  906. FUNCTION TStringLookUpValidator.Lookup (Const S: String): Boolean;
  907. {$IFDEF PPC_VIRTUAL} VAR Index: LongInt; {$ELSE} VAR Index: sw_Integer; {$ENDIF}
  908. BEGIN
  909. Lookup := False; { Preset false return }
  910. If (Strings <> Nil) Then
  911. Lookup := Strings^.Search(@S, Index); { Search for string }
  912. END;
  913. {--TStringLookUpValidator---------------------------------------------------}
  914. { Error -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  915. {---------------------------------------------------------------------------}
  916. PROCEDURE TStringLookUpValidator.Error;
  917. CONST PXErrMsg = 'Input not in valid-list';
  918. BEGIN
  919. MessageBox(PXErrMsg, Nil, mfError OR mfOKButton); { Display message }
  920. END;
  921. {--TStringLookUpValidator---------------------------------------------------}
  922. { NewStringList -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  923. {---------------------------------------------------------------------------}
  924. PROCEDURE TStringLookUpValidator.NewStringList (AStrings: PStringCollection);
  925. BEGIN
  926. If (Strings <> Nil) Then Dispose(Strings, Done); { Free old string list }
  927. Strings := AStrings; { Hold new string list }
  928. END;
  929. {--TStringLookUpValidator---------------------------------------------------}
  930. { Store -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  931. {---------------------------------------------------------------------------}
  932. PROCEDURE TStringLookUpValidator.Store (Var S: TStream);
  933. BEGIN
  934. TLookupValidator.Store(S); { TlookupValidator call }
  935. S.Put(Strings); { Now store strings }
  936. END;
  937. {***************************************************************************}
  938. { INTERFACE ROUTINES }
  939. {***************************************************************************}
  940. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  941. { OBJECT REGISTER ROUTINES }
  942. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  943. {---------------------------------------------------------------------------}
  944. { RegisterValidate -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18May98 LdB }
  945. {---------------------------------------------------------------------------}
  946. PROCEDURE RegisterValidate;
  947. BEGIN
  948. RegisterType(RPXPictureValidator); { Register viewer }
  949. RegisterType(RFilterValidator); { Register filter }
  950. RegisterType(RRangeValidator); { Register validator }
  951. RegisterType(RStringLookupValidator); { Register str lookup }
  952. END;
  953. END.