validate.pas 53 KB

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