dbf_parser.pas 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753
  1. unit dbf_parser;
  2. interface
  3. {$I dbf_common.inc}
  4. uses
  5. SysUtils,
  6. Classes,
  7. {$ifdef KYLIX}
  8. Libc,
  9. {$endif}
  10. {$ifndef WIN32}
  11. dbf_wtil,
  12. {$endif}
  13. db,
  14. dbf_prscore,
  15. dbf_common,
  16. dbf_fields,
  17. dbf_prsdef,
  18. dbf_prssupp;
  19. type
  20. TDbfParser = class(TCustomExpressionParser)
  21. private
  22. FDbfFile: Pointer;
  23. FFieldVarList: TStringList;
  24. FResultLen: Integer;
  25. FIsExpression: Boolean; // expression or simple field?
  26. FFieldType: TExpressionType;
  27. FCaseInsensitive: Boolean;
  28. FRawStringFields: Boolean;
  29. FPartialMatch: boolean;
  30. protected
  31. FCurrentExpression: string;
  32. procedure FillExpressList; override;
  33. procedure HandleUnknownVariable(VarName: string); override;
  34. function GetVariableInfo(VarName: string): TDbfFieldDef;
  35. function CurrentExpression: string; override;
  36. function GetResultType: TExpressionType; override;
  37. procedure SetCaseInsensitive(NewInsensitive: Boolean);
  38. procedure SetRawStringFields(NewRawFields: Boolean);
  39. procedure SetPartialMatch(NewPartialMatch: boolean);
  40. public
  41. constructor Create(ADbfFile: Pointer);
  42. destructor Destroy; override;
  43. procedure ClearExpressions; override;
  44. procedure ParseExpression(Expression: string); virtual;
  45. function ExtractFromBuffer(Buffer: PChar): PChar; virtual;
  46. property DbfFile: Pointer read FDbfFile write FDbfFile;
  47. property Expression: string read FCurrentExpression;
  48. property ResultLen: Integer read FResultLen;
  49. property CaseInsensitive: Boolean read FCaseInsensitive write SetCaseInsensitive;
  50. property RawStringFields: Boolean read FRawStringFields write SetRawStringFields;
  51. property PartialMatch: boolean read FPartialMatch write SetPartialMatch;
  52. end;
  53. //--Expression functions-----------------------------------------------------
  54. procedure FuncFloatToStr(Param: PExpressionRec);
  55. procedure FuncIntToStr_Gen(Param: PExpressionRec; Val: Integer);
  56. procedure FuncIntToStr(Param: PExpressionRec);
  57. procedure FuncDateToStr(Param: PExpressionRec);
  58. procedure FuncSubString(Param: PExpressionRec);
  59. procedure FuncUppercase(Param: PExpressionRec);
  60. procedure FuncLowercase(Param: PExpressionRec);
  61. procedure FuncAdd_F_FF(Param: PExpressionRec);
  62. procedure FuncAdd_F_FI(Param: PExpressionRec);
  63. procedure FuncAdd_F_II(Param: PExpressionRec);
  64. procedure FuncAdd_F_IF(Param: PExpressionRec);
  65. {$ifdef SUPPORT_INT64}
  66. procedure FuncAdd_F_FL(Param: PExpressionRec);
  67. procedure FuncAdd_F_IL(Param: PExpressionRec);
  68. procedure FuncAdd_F_LL(Param: PExpressionRec);
  69. procedure FuncAdd_F_LF(Param: PExpressionRec);
  70. procedure FuncAdd_F_LI(Param: PExpressionRec);
  71. {$endif}
  72. procedure FuncSub_F_FF(Param: PExpressionRec);
  73. procedure FuncSub_F_FI(Param: PExpressionRec);
  74. procedure FuncSub_F_II(Param: PExpressionRec);
  75. procedure FuncSub_F_IF(Param: PExpressionRec);
  76. {$ifdef SUPPORT_INT64}
  77. procedure FuncSub_F_FL(Param: PExpressionRec);
  78. procedure FuncSub_F_IL(Param: PExpressionRec);
  79. procedure FuncSub_F_LL(Param: PExpressionRec);
  80. procedure FuncSub_F_LF(Param: PExpressionRec);
  81. procedure FuncSub_F_LI(Param: PExpressionRec);
  82. {$endif}
  83. procedure FuncMul_F_FF(Param: PExpressionRec);
  84. procedure FuncMul_F_FI(Param: PExpressionRec);
  85. procedure FuncMul_F_II(Param: PExpressionRec);
  86. procedure FuncMul_F_IF(Param: PExpressionRec);
  87. {$ifdef SUPPORT_INT64}
  88. procedure FuncMul_F_FL(Param: PExpressionRec);
  89. procedure FuncMul_F_IL(Param: PExpressionRec);
  90. procedure FuncMul_F_LL(Param: PExpressionRec);
  91. procedure FuncMul_F_LF(Param: PExpressionRec);
  92. procedure FuncMul_F_LI(Param: PExpressionRec);
  93. {$endif}
  94. procedure FuncDiv_F_FF(Param: PExpressionRec);
  95. procedure FuncDiv_F_FI(Param: PExpressionRec);
  96. procedure FuncDiv_F_II(Param: PExpressionRec);
  97. procedure FuncDiv_F_IF(Param: PExpressionRec);
  98. {$ifdef SUPPORT_INT64}
  99. procedure FuncDiv_F_FL(Param: PExpressionRec);
  100. procedure FuncDiv_F_IL(Param: PExpressionRec);
  101. procedure FuncDiv_F_LL(Param: PExpressionRec);
  102. procedure FuncDiv_F_LF(Param: PExpressionRec);
  103. procedure FuncDiv_F_LI(Param: PExpressionRec);
  104. {$endif}
  105. procedure FuncStrI_EQ(Param: PExpressionRec);
  106. procedure FuncStrI_NEQ(Param: PExpressionRec);
  107. procedure FuncStrI_LT(Param: PExpressionRec);
  108. procedure FuncStrI_GT(Param: PExpressionRec);
  109. procedure FuncStrI_LTE(Param: PExpressionRec);
  110. procedure FuncStrI_GTE(Param: PExpressionRec);
  111. procedure FuncStr_EQ(Param: PExpressionRec);
  112. procedure FuncStr_NEQ(Param: PExpressionRec);
  113. procedure FuncStr_LT(Param: PExpressionRec);
  114. procedure FuncStr_GT(Param: PExpressionRec);
  115. procedure FuncStr_LTE(Param: PExpressionRec);
  116. procedure FuncStr_GTE(Param: PExpressionRec);
  117. procedure Func_FF_EQ(Param: PExpressionRec);
  118. procedure Func_FF_NEQ(Param: PExpressionRec);
  119. procedure Func_FF_LT(Param: PExpressionRec);
  120. procedure Func_FF_GT(Param: PExpressionRec);
  121. procedure Func_FF_LTE(Param: PExpressionRec);
  122. procedure Func_FF_GTE(Param: PExpressionRec);
  123. procedure Func_FI_EQ(Param: PExpressionRec);
  124. procedure Func_FI_NEQ(Param: PExpressionRec);
  125. procedure Func_FI_LT(Param: PExpressionRec);
  126. procedure Func_FI_GT(Param: PExpressionRec);
  127. procedure Func_FI_LTE(Param: PExpressionRec);
  128. procedure Func_FI_GTE(Param: PExpressionRec);
  129. procedure Func_II_EQ(Param: PExpressionRec);
  130. procedure Func_II_NEQ(Param: PExpressionRec);
  131. procedure Func_II_LT(Param: PExpressionRec);
  132. procedure Func_II_GT(Param: PExpressionRec);
  133. procedure Func_II_LTE(Param: PExpressionRec);
  134. procedure Func_II_GTE(Param: PExpressionRec);
  135. procedure Func_IF_EQ(Param: PExpressionRec);
  136. procedure Func_IF_NEQ(Param: PExpressionRec);
  137. procedure Func_IF_LT(Param: PExpressionRec);
  138. procedure Func_IF_GT(Param: PExpressionRec);
  139. procedure Func_IF_LTE(Param: PExpressionRec);
  140. procedure Func_IF_GTE(Param: PExpressionRec);
  141. {$ifdef SUPPORT_INT64}
  142. procedure Func_LL_EQ(Param: PExpressionRec);
  143. procedure Func_LL_NEQ(Param: PExpressionRec);
  144. procedure Func_LL_LT(Param: PExpressionRec);
  145. procedure Func_LL_GT(Param: PExpressionRec);
  146. procedure Func_LL_LTE(Param: PExpressionRec);
  147. procedure Func_LL_GTE(Param: PExpressionRec);
  148. procedure Func_LF_EQ(Param: PExpressionRec);
  149. procedure Func_LF_NEQ(Param: PExpressionRec);
  150. procedure Func_LF_LT(Param: PExpressionRec);
  151. procedure Func_LF_GT(Param: PExpressionRec);
  152. procedure Func_LF_LTE(Param: PExpressionRec);
  153. procedure Func_LF_GTE(Param: PExpressionRec);
  154. procedure Func_FL_EQ(Param: PExpressionRec);
  155. procedure Func_FL_NEQ(Param: PExpressionRec);
  156. procedure Func_FL_LT(Param: PExpressionRec);
  157. procedure Func_FL_GT(Param: PExpressionRec);
  158. procedure Func_FL_LTE(Param: PExpressionRec);
  159. procedure Func_FL_GTE(Param: PExpressionRec);
  160. procedure Func_LI_EQ(Param: PExpressionRec);
  161. procedure Func_LI_NEQ(Param: PExpressionRec);
  162. procedure Func_LI_LT(Param: PExpressionRec);
  163. procedure Func_LI_GT(Param: PExpressionRec);
  164. procedure Func_LI_LTE(Param: PExpressionRec);
  165. procedure Func_LI_GTE(Param: PExpressionRec);
  166. procedure Func_IL_EQ(Param: PExpressionRec);
  167. procedure Func_IL_NEQ(Param: PExpressionRec);
  168. procedure Func_IL_LT(Param: PExpressionRec);
  169. procedure Func_IL_GT(Param: PExpressionRec);
  170. procedure Func_IL_LTE(Param: PExpressionRec);
  171. procedure Func_IL_GTE(Param: PExpressionRec);
  172. {$endif}
  173. procedure Func_AND(Param: PExpressionRec);
  174. procedure Func_OR(Param: PExpressionRec);
  175. procedure Func_NOT(Param: PExpressionRec);
  176. implementation
  177. uses
  178. dbf,
  179. dbf_dbffile,
  180. dbf_str
  181. {$ifdef WIN32}
  182. ,Windows
  183. {$endif}
  184. ;
  185. type
  186. // TFieldVar aids in retrieving field values from records
  187. // in their proper type
  188. TFieldVar = class(TObject)
  189. private
  190. FFieldDef: TDbfFieldDef;
  191. FDbfFile: TDbfFile;
  192. FFieldName: string;
  193. protected
  194. function GetFieldVal: Pointer; virtual; abstract;
  195. function GetFieldType: TExpressionType; virtual; abstract;
  196. public
  197. constructor Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  198. procedure Refresh(Buffer: PChar); virtual; abstract;
  199. property FieldVal: Pointer read GetFieldVal;
  200. property FieldDef: TDbfFieldDef read FFieldDef;
  201. property FieldType: TExpressionType read GetFieldType;
  202. property DbfFile: TDbfFile read FDbfFile;
  203. property FieldName: string read FFieldName;
  204. end;
  205. TStringFieldVar = class(TFieldVar)
  206. protected
  207. FFieldVal: PChar;
  208. function GetFieldVal: Pointer; override;
  209. function GetFieldType: TExpressionType; override;
  210. end;
  211. TRawStringFieldVar = class(TStringFieldVar)
  212. public
  213. constructor Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  214. procedure Refresh(Buffer: PChar); override;
  215. end;
  216. TAnsiStringFieldVar = class(TStringFieldVar)
  217. public
  218. constructor Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  219. destructor Destroy; override;
  220. procedure Refresh(Buffer: PChar); override;
  221. end;
  222. TFloatFieldVar = class(TFieldVar)
  223. private
  224. FFieldVal: Double;
  225. protected
  226. function GetFieldVal: Pointer; override;
  227. function GetFieldType: TExpressionType; override;
  228. public
  229. constructor Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  230. procedure Refresh(Buffer: PChar); override;
  231. end;
  232. TIntegerFieldVar = class(TFieldVar)
  233. private
  234. FFieldVal: Integer;
  235. protected
  236. function GetFieldVal: Pointer; override;
  237. function GetFieldType: TExpressionType; override;
  238. public
  239. constructor Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  240. procedure Refresh(Buffer: PChar); override;
  241. end;
  242. {$ifdef SUPPORT_INT64}
  243. TLargeIntFieldVar = class(TFieldVar)
  244. private
  245. FFieldVal: Int64;
  246. protected
  247. function GetFieldVal: Pointer; override;
  248. function GetFieldType: TExpressionType; override;
  249. public
  250. constructor Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  251. procedure Refresh(Buffer: PChar); override;
  252. end;
  253. {$endif}
  254. TDateTimeFieldVar = class(TFieldVar)
  255. private
  256. FFieldVal: TDateTimeRec;
  257. function GetFieldType: TExpressionType; override;
  258. protected
  259. function GetFieldVal: Pointer; override;
  260. public
  261. constructor Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  262. procedure Refresh(Buffer: PChar); override;
  263. end;
  264. //--TFieldVar----------------------------------------------------------------
  265. constructor TFieldVar.Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  266. begin
  267. inherited Create;
  268. // store field
  269. FFieldDef := UseFieldDef;
  270. FDbfFile := ADbfFile;
  271. FFieldName := UseFieldDef.FieldName;
  272. end;
  273. //--TStringFieldVar-------------------------------------------------------------
  274. function TStringFieldVar.GetFieldVal: Pointer;
  275. begin
  276. Result := @FFieldVal;
  277. end;
  278. function TStringFieldVar.GetFieldType: TExpressionType;
  279. begin
  280. Result := etString;
  281. end;
  282. //--TRawStringFieldVar----------------------------------------------------------
  283. constructor TRawStringFieldVar.Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  284. begin
  285. inherited;
  286. end;
  287. procedure TRawStringFieldVar.Refresh(Buffer: PChar);
  288. begin
  289. FFieldVal := Buffer + FieldDef.Offset;
  290. end;
  291. //--TAnsiStringFieldVar---------------------------------------------------------
  292. constructor TAnsiStringFieldVar.Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  293. begin
  294. inherited;
  295. GetMem(FFieldVal, UseFieldDef.Size+1);
  296. end;
  297. destructor TAnsiStringFieldVar.Destroy;
  298. begin
  299. FreeMem(FFieldVal);
  300. inherited;
  301. end;
  302. procedure TAnsiStringFieldVar.Refresh(Buffer: PChar);
  303. var
  304. Len: Integer;
  305. begin
  306. // copy field data
  307. Len := FieldDef.Size;
  308. Move(Buffer[FieldDef.Offset], FFieldVal[0], Len);
  309. // trim right side spaces by null-termination
  310. while (Len >= 1) and (FFieldVal[Len-1] = ' ') do Dec(Len);
  311. FFieldVal[Len] := #0;
  312. // translate to ANSI
  313. TranslateString(DbfFile.UseCodePage, GetACP, FFieldVal, FFieldVal, Len);
  314. end;
  315. //--TFloatFieldVar-----------------------------------------------------------
  316. constructor TFloatFieldVar.Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  317. begin
  318. inherited;
  319. end;
  320. function TFloatFieldVar.GetFieldVal: Pointer;
  321. begin
  322. Result := @FFieldVal;
  323. end;
  324. function TFloatFieldVar.GetFieldType: TExpressionType;
  325. begin
  326. Result := etFloat;
  327. end;
  328. procedure TFloatFieldVar.Refresh(Buffer: PChar);
  329. begin
  330. // database width is default 64-bit double
  331. if not FDbfFile.GetFieldDataFromDef(FieldDef, FieldDef.FieldType, Buffer, @FFieldVal) then
  332. FFieldVal := 0.0;
  333. end;
  334. //--TIntegerFieldVar----------------------------------------------------------
  335. constructor TIntegerFieldVar.Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  336. begin
  337. inherited;
  338. end;
  339. function TIntegerFieldVar.GetFieldVal: Pointer;
  340. begin
  341. Result := @FFieldVal;
  342. end;
  343. function TIntegerFieldVar.GetFieldType: TExpressionType;
  344. begin
  345. Result := etInteger;
  346. end;
  347. procedure TIntegerFieldVar.Refresh(Buffer: PChar);
  348. begin
  349. FFieldVal := 0;
  350. FDbfFile.GetFieldDataFromDef(FieldDef, FieldDef.FieldType, Buffer, @FFieldVal);
  351. end;
  352. {$ifdef SUPPORT_INT64}
  353. //--TLargeIntFieldVar----------------------------------------------------------
  354. constructor TLargeIntFieldVar.Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  355. begin
  356. inherited;
  357. end;
  358. function TLargeIntFieldVar.GetFieldVal: Pointer;
  359. begin
  360. Result := @FFieldVal;
  361. end;
  362. function TLargeIntFieldVar.GetFieldType: TExpressionType;
  363. begin
  364. Result := etLargeInt;
  365. end;
  366. procedure TLargeIntFieldVar.Refresh(Buffer: PChar);
  367. begin
  368. if not FDbfFile.GetFieldDataFromDef(FieldDef, FieldDef.FieldType, Buffer, @FFieldVal) then
  369. FFieldVal := 0;
  370. end;
  371. {$endif}
  372. //--TDateTimeFieldVar---------------------------------------------------------
  373. constructor TDateTimeFieldVar.Create(UseFieldDef: TDbfFieldDef; ADbfFile: TDbfFile);
  374. begin
  375. inherited;
  376. end;
  377. function TDateTimeFieldVar.GetFieldVal: Pointer;
  378. begin
  379. Result := @FFieldVal;
  380. end;
  381. function TDateTimeFieldVar.GetFieldType: TExpressionType;
  382. begin
  383. Result := etDateTime;
  384. end;
  385. procedure TDateTimeFieldVar.Refresh(Buffer: PChar);
  386. begin
  387. if not FDbfFile.GetFieldDataFromDef(FieldDef, ftDateTime, Buffer, @FFieldVal) then
  388. FFieldVal.DateTime := 0.0;
  389. end;
  390. //--Expression functions-----------------------------------------------------
  391. procedure FuncFloatToStr(Param: PExpressionRec);
  392. var
  393. width, numDigits, resWidth: Integer;
  394. extVal: Extended;
  395. begin
  396. with Param^ do
  397. begin
  398. // get params;
  399. numDigits := 0;
  400. if Args[1] <> nil then
  401. width := PInteger(Args[1])^
  402. else
  403. width := 18;
  404. if Args[2] <> nil then
  405. numDigits := PInteger(Args[2])^;
  406. // convert to string
  407. Res.AssureSpace(width);
  408. extVal := PDouble(Args[0])^;
  409. resWidth := FloatToText(Res.MemoryPos^, extVal, {$ifndef FPC_VERSION}fvExtended,{$endif} ffFixed, 18, numDigits);
  410. // always use dot as decimal separator
  411. if numDigits > 0 then
  412. Res.MemoryPos^[resWidth-numDigits-1] := '.';
  413. // result width smaller than requested width? -> add space to compensate
  414. if (Args[1] <> nil) and (resWidth < width) then
  415. begin
  416. // move string so that it's right-aligned
  417. Move(Res.MemoryPos^^, (Res.MemoryPos^)[width-resWidth], resWidth);
  418. // fill gap with spaces
  419. FillChar(Res.MemoryPos^^, width-resWidth, ' ');
  420. // resWidth has been padded, update
  421. resWidth := width;
  422. end else if resWidth > width then begin
  423. // result width more than requested width, cut
  424. resWidth := width;
  425. end;
  426. // advance pointer
  427. Inc(Res.MemoryPos^, resWidth);
  428. // null-terminate
  429. Res.MemoryPos^^ := #0;
  430. end;
  431. end;
  432. procedure FuncIntToStr_Gen(Param: PExpressionRec; Val: Integer);
  433. var
  434. width: Integer;
  435. begin
  436. with Param^ do
  437. begin
  438. // width specified?
  439. if Args[1] <> nil then
  440. begin
  441. // convert to string
  442. width := PInteger(Args[1])^;
  443. GetStrFromInt_Width(Val, width, Res.MemoryPos^, #32);
  444. // advance pointer
  445. Inc(Res.MemoryPos^, width);
  446. // need to add decimal?
  447. if Args[2] <> nil then
  448. begin
  449. // get number of digits
  450. width := PInteger(Args[2])^;
  451. // add decimal dot
  452. Res.MemoryPos^^ := '.';
  453. Inc(Res.MemoryPos^);
  454. // add zeroes
  455. FillChar(Res.MemoryPos^^, width, '0');
  456. // go to end
  457. Inc(Res.MemoryPos^, width);
  458. end;
  459. end else begin
  460. // convert to string
  461. width := GetStrFromInt(Val, Res.MemoryPos^);
  462. // advance pointer
  463. Inc(Param^.Res.MemoryPos^, width);
  464. end;
  465. // null-terminate
  466. Res.MemoryPos^^ := #0;
  467. end;
  468. end;
  469. procedure FuncIntToStr(Param: PExpressionRec);
  470. begin
  471. FuncIntToStr_Gen(Param, PInteger(Param^.Args[0])^);
  472. end;
  473. procedure FuncDateToStr(Param: PExpressionRec);
  474. var
  475. TempStr: string;
  476. begin
  477. with Param^ do
  478. begin
  479. // create in temporary string
  480. DateTimeToString(TempStr, 'yyyymmdd', PDateTimeRec(Args[0])^.DateTime);
  481. // copy to buffer
  482. Res.Append(PChar(TempStr), Length(TempStr));
  483. end;
  484. end;
  485. procedure FuncSubString(Param: PExpressionRec);
  486. var
  487. srcLen, index, count: Integer;
  488. begin
  489. with Param^ do
  490. begin
  491. srcLen := StrLen(Args[0]);
  492. index := PInteger(Args[1])^ - 1;
  493. count := PInteger(Args[2])^;
  494. if index + count <= srcLen then
  495. Res.Append(Args[0]+index, count)
  496. else
  497. Res.MemoryPos^^ := #0;
  498. end;
  499. end;
  500. procedure FuncUppercase(Param: PExpressionRec);
  501. var
  502. dest: PChar;
  503. begin
  504. with Param^ do
  505. begin
  506. // first copy
  507. dest := (Res.MemoryPos)^;
  508. Res.Append(Args[0], StrLen(Args[0]));
  509. // make uppercase
  510. AnsiStrUpper(dest);
  511. end;
  512. end;
  513. procedure FuncLowercase(Param: PExpressionRec);
  514. var
  515. dest: PChar;
  516. begin
  517. with Param^ do
  518. begin
  519. // first copy
  520. dest := (Res.MemoryPos)^;
  521. Res.Append(Args[0], StrLen(Args[0]));
  522. // make lowercase
  523. AnsiStrLower(dest);
  524. end;
  525. end;
  526. procedure FuncAdd_F_FF(Param: PExpressionRec);
  527. begin
  528. with Param^ do
  529. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ + PDouble(Args[1])^;
  530. end;
  531. procedure FuncAdd_F_FI(Param: PExpressionRec);
  532. begin
  533. with Param^ do
  534. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ + PInteger(Args[1])^;
  535. end;
  536. procedure FuncAdd_F_II(Param: PExpressionRec);
  537. begin
  538. with Param^ do
  539. PInteger(Res.MemoryPos^)^ := PInteger(Args[0])^ + PInteger(Args[1])^;
  540. end;
  541. procedure FuncAdd_F_IF(Param: PExpressionRec);
  542. begin
  543. with Param^ do
  544. PDouble(Res.MemoryPos^)^ := PInteger(Args[0])^ + PDouble(Args[1])^;
  545. end;
  546. {$ifdef SUPPORT_INT64}
  547. procedure FuncAdd_F_FL(Param: PExpressionRec);
  548. begin
  549. with Param^ do
  550. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ + PInt64(Args[1])^;
  551. end;
  552. procedure FuncAdd_F_IL(Param: PExpressionRec);
  553. begin
  554. with Param^ do
  555. PInt64(Res.MemoryPos^)^ := PInteger(Args[0])^ + PInt64(Args[1])^;
  556. end;
  557. procedure FuncAdd_F_LL(Param: PExpressionRec);
  558. begin
  559. with Param^ do
  560. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ + PInt64(Args[1])^;
  561. end;
  562. procedure FuncAdd_F_LF(Param: PExpressionRec);
  563. begin
  564. with Param^ do
  565. PDouble(Res.MemoryPos^)^ := PInt64(Args[0])^ + PDouble(Args[1])^;
  566. end;
  567. procedure FuncAdd_F_LI(Param: PExpressionRec);
  568. begin
  569. with Param^ do
  570. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ + PInteger(Args[1])^;
  571. end;
  572. {$endif}
  573. procedure FuncSub_F_FF(Param: PExpressionRec);
  574. begin
  575. with Param^ do
  576. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ - PDouble(Args[1])^;
  577. end;
  578. procedure FuncSub_F_FI(Param: PExpressionRec);
  579. begin
  580. with Param^ do
  581. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ - PInteger(Args[1])^;
  582. end;
  583. procedure FuncSub_F_II(Param: PExpressionRec);
  584. begin
  585. with Param^ do
  586. PInteger(Res.MemoryPos^)^ := PInteger(Args[0])^ - PInteger(Args[1])^;
  587. end;
  588. procedure FuncSub_F_IF(Param: PExpressionRec);
  589. begin
  590. with Param^ do
  591. PDouble(Res.MemoryPos^)^ := PInteger(Args[0])^ - PDouble(Args[1])^;
  592. end;
  593. {$ifdef SUPPORT_INT64}
  594. procedure FuncSub_F_FL(Param: PExpressionRec);
  595. begin
  596. with Param^ do
  597. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ - PInt64(Args[1])^;
  598. end;
  599. procedure FuncSub_F_IL(Param: PExpressionRec);
  600. begin
  601. with Param^ do
  602. PInt64(Res.MemoryPos^)^ := PInteger(Args[0])^ - PInt64(Args[1])^;
  603. end;
  604. procedure FuncSub_F_LL(Param: PExpressionRec);
  605. begin
  606. with Param^ do
  607. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ - PInt64(Args[1])^;
  608. end;
  609. procedure FuncSub_F_LF(Param: PExpressionRec);
  610. begin
  611. with Param^ do
  612. PDouble(Res.MemoryPos^)^ := PInt64(Args[0])^ - PDouble(Args[1])^;
  613. end;
  614. procedure FuncSub_F_LI(Param: PExpressionRec);
  615. begin
  616. with Param^ do
  617. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ - PInteger(Args[1])^;
  618. end;
  619. {$endif}
  620. procedure FuncMul_F_FF(Param: PExpressionRec);
  621. begin
  622. with Param^ do
  623. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ * PDouble(Args[1])^;
  624. end;
  625. procedure FuncMul_F_FI(Param: PExpressionRec);
  626. begin
  627. with Param^ do
  628. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ * PInteger(Args[1])^;
  629. end;
  630. procedure FuncMul_F_II(Param: PExpressionRec);
  631. begin
  632. with Param^ do
  633. PInteger(Res.MemoryPos^)^ := PInteger(Args[0])^ * PInteger(Args[1])^;
  634. end;
  635. procedure FuncMul_F_IF(Param: PExpressionRec);
  636. begin
  637. with Param^ do
  638. PDouble(Res.MemoryPos^)^ := PInteger(Args[0])^ * PDouble(Args[1])^;
  639. end;
  640. {$ifdef SUPPORT_INT64}
  641. procedure FuncMul_F_FL(Param: PExpressionRec);
  642. begin
  643. with Param^ do
  644. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ * PInt64(Args[1])^;
  645. end;
  646. procedure FuncMul_F_IL(Param: PExpressionRec);
  647. begin
  648. with Param^ do
  649. PInt64(Res.MemoryPos^)^ := PInteger(Args[0])^ * PInt64(Args[1])^;
  650. end;
  651. procedure FuncMul_F_LL(Param: PExpressionRec);
  652. begin
  653. with Param^ do
  654. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ * PInt64(Args[1])^;
  655. end;
  656. procedure FuncMul_F_LF(Param: PExpressionRec);
  657. begin
  658. with Param^ do
  659. PDouble(Res.MemoryPos^)^ := PInt64(Args[0])^ * PDouble(Args[1])^;
  660. end;
  661. procedure FuncMul_F_LI(Param: PExpressionRec);
  662. begin
  663. with Param^ do
  664. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ * PInteger(Args[1])^;
  665. end;
  666. {$endif}
  667. procedure FuncDiv_F_FF(Param: PExpressionRec);
  668. begin
  669. with Param^ do
  670. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ / PDouble(Args[1])^;
  671. end;
  672. procedure FuncDiv_F_FI(Param: PExpressionRec);
  673. begin
  674. with Param^ do
  675. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ / PInteger(Args[1])^;
  676. end;
  677. procedure FuncDiv_F_II(Param: PExpressionRec);
  678. begin
  679. with Param^ do
  680. PInteger(Res.MemoryPos^)^ := PInteger(Args[0])^ div PInteger(Args[1])^;
  681. end;
  682. procedure FuncDiv_F_IF(Param: PExpressionRec);
  683. begin
  684. with Param^ do
  685. PDouble(Res.MemoryPos^)^ := PInteger(Args[0])^ / PDouble(Args[1])^;
  686. end;
  687. {$ifdef SUPPORT_INT64}
  688. procedure FuncDiv_F_FL(Param: PExpressionRec);
  689. begin
  690. with Param^ do
  691. PDouble(Res.MemoryPos^)^ := PDouble(Args[0])^ / PInt64(Args[1])^;
  692. end;
  693. procedure FuncDiv_F_IL(Param: PExpressionRec);
  694. begin
  695. with Param^ do
  696. PInt64(Res.MemoryPos^)^ := PInteger(Args[0])^ div PInt64(Args[1])^;
  697. end;
  698. procedure FuncDiv_F_LL(Param: PExpressionRec);
  699. begin
  700. with Param^ do
  701. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ div PInt64(Args[1])^;
  702. end;
  703. procedure FuncDiv_F_LF(Param: PExpressionRec);
  704. begin
  705. with Param^ do
  706. PDouble(Res.MemoryPos^)^ := PInt64(Args[0])^ / PDouble(Args[1])^;
  707. end;
  708. procedure FuncDiv_F_LI(Param: PExpressionRec);
  709. begin
  710. with Param^ do
  711. PInt64(Res.MemoryPos^)^ := PInt64(Args[0])^ div PInteger(Args[1])^;
  712. end;
  713. {$endif}
  714. procedure FuncStrI_EQ(Param: PExpressionRec);
  715. begin
  716. with Param^ do
  717. Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) = 0);
  718. end;
  719. procedure FuncStrIP_EQ(Param: PExpressionRec);
  720. var
  721. arg0len, arg1len: integer;
  722. match: boolean;
  723. str0, str1: string;
  724. begin
  725. with Param^ do
  726. begin
  727. arg1len := StrLen(Args[1]);
  728. if Args[1][0] = '*' then
  729. begin
  730. if Args[1][arg1len-1] = '*' then
  731. begin
  732. str0 := AnsiStrUpper(Args[0]);
  733. str1 := AnsiStrUpper(Args[1]+1);
  734. setlength(str1, arg1len-2);
  735. match := AnsiPos(str0, str1) = 0;
  736. end else begin
  737. arg0len := StrLen(Args[0]);
  738. // at least length without asterisk
  739. match := arg0len >= arg1len - 1;
  740. if match then
  741. match := AnsiStrLIComp(Args[0]+(arg0len-arg1len+1), Args[1]+1, arg1len-1) = 0;
  742. end;
  743. end else
  744. if Args[1][arg1len-1] = '*' then
  745. begin
  746. arg0len := StrLen(Args[0]);
  747. match := arg1len >= arg0len - 1;
  748. if match then
  749. match := AnsiStrLIComp(Args[0], Args[1], arg1len-1) = 0;
  750. end else begin
  751. match := AnsiStrIComp(Args[0], Args[1]) = 0;
  752. end;
  753. Res.MemoryPos^^ := Char(match);
  754. end;
  755. end;
  756. procedure FuncStrI_NEQ(Param: PExpressionRec);
  757. begin
  758. with Param^ do
  759. Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) <> 0);
  760. end;
  761. procedure FuncStrI_LT(Param: PExpressionRec);
  762. begin
  763. with Param^ do
  764. Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) < 0);
  765. end;
  766. procedure FuncStrI_GT(Param: PExpressionRec);
  767. begin
  768. with Param^ do
  769. Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) > 0);
  770. end;
  771. procedure FuncStrI_LTE(Param: PExpressionRec);
  772. begin
  773. with Param^ do
  774. Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) <= 0);
  775. end;
  776. procedure FuncStrI_GTE(Param: PExpressionRec);
  777. begin
  778. with Param^ do
  779. Res.MemoryPos^^ := Char(AnsiStrIComp(Args[0], Args[1]) >= 0);
  780. end;
  781. procedure FuncStrP_EQ(Param: PExpressionRec);
  782. var
  783. arg0len, arg1len: integer;
  784. match: boolean;
  785. begin
  786. with Param^ do
  787. begin
  788. arg1len := StrLen(Args[1]);
  789. if Args[1][0] = '*' then
  790. begin
  791. if Args[1][arg1len-1] = '*' then
  792. begin
  793. Args[1][arg1len-1] := #0;
  794. match := AnsiStrPos(Args[0], Args[1]+1) <> nil;
  795. Args[1][arg1len-1] := '*';
  796. end else begin
  797. arg0len := StrLen(Args[0]);
  798. // at least length without asterisk
  799. match := arg0len >= arg1len - 1;
  800. if match then
  801. match := AnsiStrLComp(Args[0]+(arg0len-arg1len+1), Args[1]+1, arg1len-1) = 0;
  802. end;
  803. end else
  804. if Args[1][arg1len-1] = '*' then
  805. begin
  806. arg0len := StrLen(Args[0]);
  807. match := arg1len >= arg0len - 1;
  808. if match then
  809. match := AnsiStrLComp(Args[0], Args[1], arg1len-1) = 0;
  810. end else begin
  811. match := AnsiStrComp(Args[0], Args[1]) = 0;
  812. end;
  813. Res.MemoryPos^^ := Char(match);
  814. end;
  815. end;
  816. procedure FuncStr_EQ(Param: PExpressionRec);
  817. begin
  818. with Param^ do
  819. Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) = 0);
  820. end;
  821. procedure FuncStr_NEQ(Param: PExpressionRec);
  822. begin
  823. with Param^ do
  824. Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) <> 0);
  825. end;
  826. procedure FuncStr_LT(Param: PExpressionRec);
  827. begin
  828. with Param^ do
  829. Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) < 0);
  830. end;
  831. procedure FuncStr_GT(Param: PExpressionRec);
  832. begin
  833. with Param^ do
  834. Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) > 0);
  835. end;
  836. procedure FuncStr_LTE(Param: PExpressionRec);
  837. begin
  838. with Param^ do
  839. Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) <= 0);
  840. end;
  841. procedure FuncStr_GTE(Param: PExpressionRec);
  842. begin
  843. with Param^ do
  844. Res.MemoryPos^^ := Char(AnsiStrComp(Args[0], Args[1]) >= 0);
  845. end;
  846. procedure Func_FF_EQ(Param: PExpressionRec);
  847. begin
  848. with Param^ do
  849. Res.MemoryPos^^ := Char(PDouble(Args[0])^ = PDouble(Args[1])^);
  850. end;
  851. procedure Func_FF_NEQ(Param: PExpressionRec);
  852. begin
  853. with Param^ do
  854. Res.MemoryPos^^ := Char(PDouble(Args[0])^ <> PDouble(Args[1])^);
  855. end;
  856. procedure Func_FF_LT(Param: PExpressionRec);
  857. begin
  858. with Param^ do
  859. Res.MemoryPos^^ := Char(PDouble(Args[0])^ < PDouble(Args[1])^);
  860. end;
  861. procedure Func_FF_GT(Param: PExpressionRec);
  862. begin
  863. with Param^ do
  864. Res.MemoryPos^^ := Char(PDouble(Args[0])^ > PDouble(Args[1])^);
  865. end;
  866. procedure Func_FF_LTE(Param: PExpressionRec);
  867. begin
  868. with Param^ do
  869. Res.MemoryPos^^ := Char(PDouble(Args[0])^ <= PDouble(Args[1])^);
  870. end;
  871. procedure Func_FF_GTE(Param: PExpressionRec);
  872. begin
  873. with Param^ do
  874. Res.MemoryPos^^ := Char(PDouble(Args[0])^ >= PDouble(Args[1])^);
  875. end;
  876. procedure Func_FI_EQ(Param: PExpressionRec);
  877. begin
  878. with Param^ do
  879. Res.MemoryPos^^ := Char(PDouble(Args[0])^ = PInteger(Args[1])^);
  880. end;
  881. procedure Func_FI_NEQ(Param: PExpressionRec);
  882. begin
  883. with Param^ do
  884. Res.MemoryPos^^ := Char(PDouble(Args[0])^ <> PInteger(Args[1])^);
  885. end;
  886. procedure Func_FI_LT(Param: PExpressionRec);
  887. begin
  888. with Param^ do
  889. Res.MemoryPos^^ := Char(PDouble(Args[0])^ < PInteger(Args[1])^);
  890. end;
  891. procedure Func_FI_GT(Param: PExpressionRec);
  892. begin
  893. with Param^ do
  894. Res.MemoryPos^^ := Char(PDouble(Args[0])^ > PInteger(Args[1])^);
  895. end;
  896. procedure Func_FI_LTE(Param: PExpressionRec);
  897. begin
  898. with Param^ do
  899. Res.MemoryPos^^ := Char(PDouble(Args[0])^ <= PInteger(Args[1])^);
  900. end;
  901. procedure Func_FI_GTE(Param: PExpressionRec);
  902. begin
  903. with Param^ do
  904. Res.MemoryPos^^ := Char(PDouble(Args[0])^ >= PInteger(Args[1])^);
  905. end;
  906. procedure Func_II_EQ(Param: PExpressionRec);
  907. begin
  908. with Param^ do
  909. Res.MemoryPos^^ := Char(PInteger(Args[0])^ = PInteger(Args[1])^);
  910. end;
  911. procedure Func_II_NEQ(Param: PExpressionRec);
  912. begin
  913. with Param^ do
  914. Res.MemoryPos^^ := Char(PInteger(Args[0])^ <> PInteger(Args[1])^);
  915. end;
  916. procedure Func_II_LT(Param: PExpressionRec);
  917. begin
  918. with Param^ do
  919. Res.MemoryPos^^ := Char(PInteger(Args[0])^ < PInteger(Args[1])^);
  920. end;
  921. procedure Func_II_GT(Param: PExpressionRec);
  922. begin
  923. with Param^ do
  924. Res.MemoryPos^^ := Char(PInteger(Args[0])^ > PInteger(Args[1])^);
  925. end;
  926. procedure Func_II_LTE(Param: PExpressionRec);
  927. begin
  928. with Param^ do
  929. Res.MemoryPos^^ := Char(PInteger(Args[0])^ <= PInteger(Args[1])^);
  930. end;
  931. procedure Func_II_GTE(Param: PExpressionRec);
  932. begin
  933. with Param^ do
  934. Res.MemoryPos^^ := Char(PInteger(Args[0])^ >= PInteger(Args[1])^);
  935. end;
  936. procedure Func_IF_EQ(Param: PExpressionRec);
  937. begin
  938. with Param^ do
  939. Res.MemoryPos^^ := Char(PInteger(Args[0])^ = PDouble(Args[1])^);
  940. end;
  941. procedure Func_IF_NEQ(Param: PExpressionRec);
  942. begin
  943. with Param^ do
  944. Res.MemoryPos^^ := Char(PInteger(Args[0])^ <> PDouble(Args[1])^);
  945. end;
  946. procedure Func_IF_LT(Param: PExpressionRec);
  947. begin
  948. with Param^ do
  949. Res.MemoryPos^^ := Char(PInteger(Args[0])^ < PDouble(Args[1])^);
  950. end;
  951. procedure Func_IF_GT(Param: PExpressionRec);
  952. begin
  953. with Param^ do
  954. Res.MemoryPos^^ := Char(PInteger(Args[0])^ > PDouble(Args[1])^);
  955. end;
  956. procedure Func_IF_LTE(Param: PExpressionRec);
  957. begin
  958. with Param^ do
  959. Res.MemoryPos^^ := Char(PInteger(Args[0])^ <= PDouble(Args[1])^);
  960. end;
  961. procedure Func_IF_GTE(Param: PExpressionRec);
  962. begin
  963. with Param^ do
  964. Res.MemoryPos^^ := Char(PInteger(Args[0])^ >= PDouble(Args[1])^);
  965. end;
  966. {$ifdef SUPPORT_INT64}
  967. procedure Func_LL_EQ(Param: PExpressionRec);
  968. begin
  969. with Param^ do
  970. Res.MemoryPos^^ := Char(PInt64(Args[0])^ = PInt64(Args[1])^);
  971. end;
  972. procedure Func_LL_NEQ(Param: PExpressionRec);
  973. begin
  974. with Param^ do
  975. Res.MemoryPos^^ := Char(PInt64(Args[0])^ <> PInt64(Args[1])^);
  976. end;
  977. procedure Func_LL_LT(Param: PExpressionRec);
  978. begin
  979. with Param^ do
  980. Res.MemoryPos^^ := Char(PInt64(Args[0])^ < PInt64(Args[1])^);
  981. end;
  982. procedure Func_LL_GT(Param: PExpressionRec);
  983. begin
  984. with Param^ do
  985. Res.MemoryPos^^ := Char(PInt64(Args[0])^ > PInt64(Args[1])^);
  986. end;
  987. procedure Func_LL_LTE(Param: PExpressionRec);
  988. begin
  989. with Param^ do
  990. Res.MemoryPos^^ := Char(PInt64(Args[0])^ <= PInt64(Args[1])^);
  991. end;
  992. procedure Func_LL_GTE(Param: PExpressionRec);
  993. begin
  994. with Param^ do
  995. Res.MemoryPos^^ := Char(PInt64(Args[0])^ >= PInt64(Args[1])^);
  996. end;
  997. procedure Func_LF_EQ(Param: PExpressionRec);
  998. begin
  999. with Param^ do
  1000. Res.MemoryPos^^ := Char(PInt64(Args[0])^ = PDouble(Args[1])^);
  1001. end;
  1002. procedure Func_LF_NEQ(Param: PExpressionRec);
  1003. begin
  1004. with Param^ do
  1005. Res.MemoryPos^^ := Char(PInt64(Args[0])^ <> PDouble(Args[1])^);
  1006. end;
  1007. procedure Func_LF_LT(Param: PExpressionRec);
  1008. begin
  1009. with Param^ do
  1010. Res.MemoryPos^^ := Char(PInt64(Args[0])^ < PDouble(Args[1])^);
  1011. end;
  1012. procedure Func_LF_GT(Param: PExpressionRec);
  1013. begin
  1014. with Param^ do
  1015. Res.MemoryPos^^ := Char(PInt64(Args[0])^ > PDouble(Args[1])^);
  1016. end;
  1017. procedure Func_LF_LTE(Param: PExpressionRec);
  1018. begin
  1019. with Param^ do
  1020. Res.MemoryPos^^ := Char(PInt64(Args[0])^ <= PDouble(Args[1])^);
  1021. end;
  1022. procedure Func_LF_GTE(Param: PExpressionRec);
  1023. begin
  1024. with Param^ do
  1025. Res.MemoryPos^^ := Char(PInt64(Args[0])^ >= PDouble(Args[1])^);
  1026. end;
  1027. procedure Func_FL_EQ(Param: PExpressionRec);
  1028. begin
  1029. with Param^ do
  1030. Res.MemoryPos^^ := Char(PDouble(Args[0])^ = PInt64(Args[1])^);
  1031. end;
  1032. procedure Func_FL_NEQ(Param: PExpressionRec);
  1033. begin
  1034. with Param^ do
  1035. Res.MemoryPos^^ := Char(PDouble(Args[0])^ <> PInt64(Args[1])^);
  1036. end;
  1037. procedure Func_FL_LT(Param: PExpressionRec);
  1038. begin
  1039. with Param^ do
  1040. Res.MemoryPos^^ := Char(PDouble(Args[0])^ < PInt64(Args[1])^);
  1041. end;
  1042. procedure Func_FL_GT(Param: PExpressionRec);
  1043. begin
  1044. with Param^ do
  1045. Res.MemoryPos^^ := Char(PDouble(Args[0])^ > PInt64(Args[1])^);
  1046. end;
  1047. procedure Func_FL_LTE(Param: PExpressionRec);
  1048. begin
  1049. with Param^ do
  1050. Res.MemoryPos^^ := Char(PDouble(Args[0])^ <= PInt64(Args[1])^);
  1051. end;
  1052. procedure Func_FL_GTE(Param: PExpressionRec);
  1053. begin
  1054. with Param^ do
  1055. Res.MemoryPos^^ := Char(PDouble(Args[0])^ >= PInt64(Args[1])^);
  1056. end;
  1057. procedure Func_LI_EQ(Param: PExpressionRec);
  1058. begin
  1059. with Param^ do
  1060. Res.MemoryPos^^ := Char(PInt64(Args[0])^ = PInteger(Args[1])^);
  1061. end;
  1062. procedure Func_LI_NEQ(Param: PExpressionRec);
  1063. begin
  1064. with Param^ do
  1065. Res.MemoryPos^^ := Char(PInt64(Args[0])^ <> PInteger(Args[1])^);
  1066. end;
  1067. procedure Func_LI_LT(Param: PExpressionRec);
  1068. begin
  1069. with Param^ do
  1070. Res.MemoryPos^^ := Char(PInt64(Args[0])^ < PInteger(Args[1])^);
  1071. end;
  1072. procedure Func_LI_GT(Param: PExpressionRec);
  1073. begin
  1074. with Param^ do
  1075. Res.MemoryPos^^ := Char(PInt64(Args[0])^ > PInteger(Args[1])^);
  1076. end;
  1077. procedure Func_LI_LTE(Param: PExpressionRec);
  1078. begin
  1079. with Param^ do
  1080. Res.MemoryPos^^ := Char(PInt64(Args[0])^ <= PInteger(Args[1])^);
  1081. end;
  1082. procedure Func_LI_GTE(Param: PExpressionRec);
  1083. begin
  1084. with Param^ do
  1085. Res.MemoryPos^^ := Char(PInt64(Args[0])^ >= PInteger(Args[1])^);
  1086. end;
  1087. procedure Func_IL_EQ(Param: PExpressionRec);
  1088. begin
  1089. with Param^ do
  1090. Res.MemoryPos^^ := Char(PInteger(Args[0])^ = PInt64(Args[1])^);
  1091. end;
  1092. procedure Func_IL_NEQ(Param: PExpressionRec);
  1093. begin
  1094. with Param^ do
  1095. Res.MemoryPos^^ := Char(PInteger(Args[0])^ <> PInt64(Args[1])^);
  1096. end;
  1097. procedure Func_IL_LT(Param: PExpressionRec);
  1098. begin
  1099. with Param^ do
  1100. Res.MemoryPos^^ := Char(PInteger(Args[0])^ < PInt64(Args[1])^);
  1101. end;
  1102. procedure Func_IL_GT(Param: PExpressionRec);
  1103. begin
  1104. with Param^ do
  1105. Res.MemoryPos^^ := Char(PInteger(Args[0])^ > PInt64(Args[1])^);
  1106. end;
  1107. procedure Func_IL_LTE(Param: PExpressionRec);
  1108. begin
  1109. with Param^ do
  1110. Res.MemoryPos^^ := Char(PInteger(Args[0])^ <= PInt64(Args[1])^);
  1111. end;
  1112. procedure Func_IL_GTE(Param: PExpressionRec);
  1113. begin
  1114. with Param^ do
  1115. Res.MemoryPos^^ := Char(PInteger(Args[0])^ >= PInt64(Args[1])^);
  1116. end;
  1117. {$endif}
  1118. procedure Func_AND(Param: PExpressionRec);
  1119. begin
  1120. with Param^ do
  1121. Res.MemoryPos^^ := Char(Boolean(Args[0]^) and Boolean(Args[1]^));
  1122. end;
  1123. procedure Func_OR(Param: PExpressionRec);
  1124. begin
  1125. with Param^ do
  1126. Res.MemoryPos^^ := Char(Boolean(Args[0]^) or Boolean(Args[1]^));
  1127. end;
  1128. procedure Func_NOT(Param: PExpressionRec);
  1129. begin
  1130. with Param^ do
  1131. Res.MemoryPos^^ := Char(not Boolean(Args[0]^));
  1132. end;
  1133. //--TDbfParser---------------------------------------------------------------
  1134. var
  1135. DbfWordsSensGeneralList, DbfWordsInsensGeneralList: TExpressList;
  1136. DbfWordsSensPartialList, DbfWordsInsensPartialList: TExpressList;
  1137. DbfWordsSensNoPartialList, DbfWordsInsensNoPartialList: TExpressList;
  1138. DbfWordsGeneralList: TExpressList;
  1139. constructor TDbfParser.Create(ADbfFile: Pointer);
  1140. begin
  1141. FDbfFile := ADbfFile;
  1142. FFieldVarList := TStringList.Create;
  1143. FCaseInsensitive := true;
  1144. FRawStringFields := true;
  1145. inherited Create;
  1146. end;
  1147. destructor TDbfParser.Destroy;
  1148. begin
  1149. ClearExpressions;
  1150. inherited;
  1151. FreeAndNil(FFieldVarList);
  1152. end;
  1153. function TDbfParser.GetResultType: TExpressionType;
  1154. begin
  1155. // if not a real expression, return type ourself
  1156. if FIsExpression then
  1157. Result := inherited GetResultType
  1158. else
  1159. Result := FFieldType;
  1160. end;
  1161. procedure TDbfParser.SetCaseInsensitive(NewInsensitive: Boolean);
  1162. begin
  1163. if FCaseInsensitive <> NewInsensitive then
  1164. begin
  1165. // clear and regenerate functions
  1166. FCaseInsensitive := NewInsensitive;
  1167. FillExpressList;
  1168. if Length(Expression) > 0 then
  1169. ParseExpression(Expression);
  1170. end;
  1171. end;
  1172. procedure TDbfParser.SetPartialMatch(NewPartialMatch: boolean);
  1173. begin
  1174. if FPartialMatch <> NewPartialMatch then
  1175. begin
  1176. // refill function list
  1177. FPartialMatch := NewPartialMatch;
  1178. FillExpressList;
  1179. if Length(Expression) > 0 then
  1180. ParseExpression(Expression);
  1181. end;
  1182. end;
  1183. procedure TDbfParser.SetRawStringFields(NewRawFields: Boolean);
  1184. begin
  1185. if FRawStringFields <> NewRawFields then
  1186. begin
  1187. // clear and regenerate functions, custom fields will be deleted too
  1188. FRawStringFields := NewRawFields;
  1189. if Length(Expression) > 0 then
  1190. ParseExpression(Expression);
  1191. end;
  1192. end;
  1193. procedure TDbfParser.FillExpressList;
  1194. begin
  1195. FWordsList.FreeAll;
  1196. FWordsList.AddList(DbfWordsGeneralList, 0, DbfWordsGeneralList.Count - 1);
  1197. if FCaseInsensitive then
  1198. begin
  1199. FWordsList.AddList(DbfWordsInsensGeneralList, 0, DbfWordsInsensGeneralList.Count - 1);
  1200. if FPartialMatch then
  1201. begin
  1202. FWordsList.AddList(DbfWordsInsensPartialList, 0, DbfWordsInsensPartialList.Count - 1);
  1203. end else begin
  1204. FWordsList.AddList(DbfWordsInsensNoPartialList, 0, DbfWordsInsensNoPartialList.Count - 1);
  1205. end;
  1206. end else begin
  1207. FWordsList.AddList(DbfWordsSensGeneralList, 0, DbfWordsSensGeneralList.Count - 1);
  1208. if FPartialMatch then
  1209. begin
  1210. FWordsList.AddList(DbfWordsSensPartialList, 0, DbfWordsSensPartialList.Count - 1);
  1211. end else begin
  1212. FWordsList.AddList(DbfWordsSensNoPartialList, 0, DbfWordsSensNoPartialList.Count - 1);
  1213. end;
  1214. end;
  1215. end;
  1216. function TDbfParser.GetVariableInfo(VarName: string): TDbfFieldDef;
  1217. begin
  1218. Result := TDbfFile(FDbfFile).GetFieldInfo(VarName);
  1219. end;
  1220. procedure TDbfParser.HandleUnknownVariable(VarName: string);
  1221. var
  1222. FieldInfo: TDbfFieldDef;
  1223. TempFieldVar: TFieldVar;
  1224. begin
  1225. // is this variable a fieldname?
  1226. FieldInfo := GetVariableInfo(VarName);
  1227. if FieldInfo = nil then
  1228. raise EDbfError.CreateFmt(STRING_INDEX_BASED_ON_UNKNOWN_FIELD, [VarName]);
  1229. // define field in parser
  1230. case FieldInfo.FieldType of
  1231. ftString, ftBoolean:
  1232. begin
  1233. if RawStringFields then
  1234. begin
  1235. { raw string fields have fixed length, not null-terminated }
  1236. TempFieldVar := TRawStringFieldVar.Create(FieldInfo, TDbfFile(FDbfFile));
  1237. DefineStringVariableFixedLen(VarName, TempFieldVar.FieldVal, FieldInfo.Size);
  1238. end else begin
  1239. { ansi string field function translates and null-terminates field value }
  1240. TempFieldVar := TAnsiStringFieldVar.Create(FieldInfo, TDbfFile(FDbfFile));
  1241. DefineStringVariable(VarName, TempFieldVar.FieldVal);
  1242. end;
  1243. end;
  1244. ftFloat:
  1245. begin
  1246. TempFieldVar := TFloatFieldVar.Create(FieldInfo, TDbfFile(FDbfFile));
  1247. DefineFloatVariable(VarName, TempFieldVar.FieldVal);
  1248. end;
  1249. ftAutoInc, ftInteger, ftSmallInt:
  1250. begin
  1251. TempFieldVar := TIntegerFieldVar.Create(FieldInfo, TDbfFile(FDbfFile));
  1252. DefineIntegerVariable(VarName, TempFieldVar.FieldVal);
  1253. end;
  1254. {
  1255. ftSmallInt:
  1256. begin
  1257. TempFieldVar := TSmallIntFieldVar.Create(FieldInfo, TDbfFile(FDbfFile));
  1258. DefineSmallIntVariable(VarName, TempFieldVar.FieldVal);
  1259. end;
  1260. }
  1261. {$ifdef SUPPORT_INT64}
  1262. ftLargeInt:
  1263. begin
  1264. TempFieldVar := TLargeIntFieldVar.Create(FieldInfo, TDbfFile(FDbfFile));
  1265. DefineLargeIntVariable(VarName, TempFieldVar.FieldVal);
  1266. end;
  1267. {$endif}
  1268. ftDate, ftDateTime:
  1269. begin
  1270. TempFieldVar := TDateTimeFieldVar.Create(FieldInfo, TDbfFile(FDbfFile));
  1271. DefineDateTimeVariable(VarName, TempFieldVar.FieldVal);
  1272. end;
  1273. else
  1274. raise EDbfError.CreateFmt(STRING_INDEX_BASED_ON_INVALID_FIELD, [VarName]);
  1275. end;
  1276. // add to our own list
  1277. FFieldVarList.AddObject(VarName, TempFieldVar);
  1278. end;
  1279. function TDbfParser.CurrentExpression: string;
  1280. begin
  1281. Result := FCurrentExpression;
  1282. end;
  1283. procedure TDbfParser.ClearExpressions;
  1284. var
  1285. I: Integer;
  1286. begin
  1287. inherited;
  1288. // test if already freed
  1289. if FFieldVarList <> nil then
  1290. begin
  1291. // free field list
  1292. for I := 0 to FFieldVarList.Count - 1 do
  1293. begin
  1294. // replacing with nil = undefining variable
  1295. ReplaceFunction(TFieldVar(FFieldVarList.Objects[I]).FieldName, nil);
  1296. TFieldVar(FFieldVarList.Objects[I]).Free;
  1297. end;
  1298. FFieldVarList.Clear;
  1299. end;
  1300. // clear expression
  1301. FCurrentExpression := EmptyStr;
  1302. end;
  1303. procedure TDbfParser.ParseExpression(Expression: string);
  1304. var
  1305. TempBuffer: array[0..4000] of Char;
  1306. begin
  1307. // clear any current expression
  1308. ClearExpressions;
  1309. // is this a simple field or complex expression?
  1310. FIsExpression := GetVariableInfo(Expression) = nil;
  1311. if FIsExpression then
  1312. begin
  1313. // parse requested
  1314. CompileExpression(Expression);
  1315. // determine length of string length expressions
  1316. if ResultType = etString then
  1317. begin
  1318. // make empty record
  1319. TDbfFile(FDbfFile).InitRecord(@TempBuffer[0]);
  1320. FResultLen := StrLen(ExtractFromBuffer(@TempBuffer[0]));
  1321. end;
  1322. end else begin
  1323. // simple field, create field variable for it
  1324. HandleUnknownVariable(Expression);
  1325. FFieldType := TFieldVar(FFieldVarList.Objects[0]).FieldType;
  1326. // set result len of variable length fields
  1327. if FFieldType = etString then
  1328. FResultLen := TFieldVar(FFieldVarList.Objects[0]).FieldDef.Size
  1329. end;
  1330. // set result len for fixed length expressions / fields
  1331. case ResultType of
  1332. etBoolean: FResultLen := 1;
  1333. etInteger: FResultLen := 4;
  1334. etFloat: FResultLen := 8;
  1335. etDateTime: FResultLen := 8;
  1336. end;
  1337. // check if expression not too long
  1338. if FResultLen > 100 then
  1339. raise EDbfError.CreateFmt(STRING_INDEX_EXPRESSION_TOO_LONG, [Expression, FResultLen]);
  1340. // if no errors, assign current expression
  1341. FCurrentExpression := Expression;
  1342. end;
  1343. function TDbfParser.ExtractFromBuffer(Buffer: PChar): PChar;
  1344. var
  1345. I: Integer;
  1346. begin
  1347. // prepare all field variables
  1348. for I := 0 to FFieldVarList.Count - 1 do
  1349. TFieldVar(FFieldVarList.Objects[I]).Refresh(Buffer);
  1350. // complex expression?
  1351. if FIsExpression then
  1352. begin
  1353. // execute expression
  1354. EvaluateCurrent;
  1355. Result := ExpResult;
  1356. end else begin
  1357. // simple field, get field result
  1358. Result := TFieldVar(FFieldVarList.Objects[0]).FieldVal;
  1359. // if string then dereference
  1360. if FFieldType = etString then
  1361. Result := PPChar(Result)^;
  1362. end;
  1363. end;
  1364. initialization
  1365. DbfWordsGeneralList := TExpressList.Create;
  1366. DbfWordsInsensGeneralList := TExpressList.Create;
  1367. DbfWordsInsensNoPartialList := TExpressList.Create;
  1368. DbfWordsInsensPartialList := TExpressList.Create;
  1369. DbfWordsSensGeneralList := TExpressList.Create;
  1370. DbfWordsSensNoPartialList := TExpressList.Create;
  1371. DbfWordsSensPartialList := TExpressList.Create;
  1372. with DbfWordsGeneralList do
  1373. begin
  1374. // basic function functionality
  1375. Add(TLeftBracket.Create('(', nil));
  1376. Add(TRightBracket.Create(')', nil));
  1377. Add(TComma.Create(',', nil));
  1378. // operators - name, param types, result type, func addr, precedence
  1379. Add(TFunction.CreateOper('+', 'SS', etString, nil, 40));
  1380. Add(TFunction.CreateOper('+', 'FF', etFloat, FuncAdd_F_FF, 40));
  1381. Add(TFunction.CreateOper('+', 'FI', etFloat, FuncAdd_F_FI, 40));
  1382. Add(TFunction.CreateOper('+', 'IF', etFloat, FuncAdd_F_IF, 40));
  1383. Add(TFunction.CreateOper('+', 'II', etInteger, FuncAdd_F_II, 40));
  1384. {$ifdef SUPPORT_INT64}
  1385. Add(TFunction.CreateOper('+', 'FL', etFloat, FuncAdd_F_FL, 40));
  1386. Add(TFunction.CreateOper('+', 'IL', etLargeInt, FuncAdd_F_IL, 40));
  1387. Add(TFunction.CreateOper('+', 'LF', etFloat, FuncAdd_F_LF, 40));
  1388. Add(TFunction.CreateOper('+', 'LL', etLargeInt, FuncAdd_F_LI, 40));
  1389. Add(TFunction.CreateOper('+', 'LI', etLargeInt, FuncAdd_F_LL, 40));
  1390. {$endif}
  1391. Add(TFunction.CreateOper('-', 'FF', etFloat, FuncSub_F_FF, 40));
  1392. Add(TFunction.CreateOper('-', 'FI', etFloat, FuncSub_F_FI, 40));
  1393. Add(TFunction.CreateOper('-', 'IF', etFloat, FuncSub_F_IF, 40));
  1394. Add(TFunction.CreateOper('-', 'II', etInteger, FuncSub_F_II, 40));
  1395. {$ifdef SUPPORT_INT64}
  1396. Add(TFunction.CreateOper('-', 'FL', etFloat, FuncSub_F_FL, 40));
  1397. Add(TFunction.CreateOper('-', 'IL', etLargeInt, FuncSub_F_IL, 40));
  1398. Add(TFunction.CreateOper('-', 'LF', etFloat, FuncSub_F_LF, 40));
  1399. Add(TFunction.CreateOper('-', 'LL', etLargeInt, FuncSub_F_LI, 40));
  1400. Add(TFunction.CreateOper('-', 'LI', etLargeInt, FuncSub_F_LL, 40));
  1401. {$endif}
  1402. Add(TFunction.CreateOper('*', 'FF', etFloat, FuncMul_F_FF, 40));
  1403. Add(TFunction.CreateOper('*', 'FI', etFloat, FuncMul_F_FI, 40));
  1404. Add(TFunction.CreateOper('*', 'IF', etFloat, FuncMul_F_IF, 40));
  1405. Add(TFunction.CreateOper('*', 'II', etInteger, FuncMul_F_II, 40));
  1406. {$ifdef SUPPORT_INT64}
  1407. Add(TFunction.CreateOper('*', 'FL', etFloat, FuncMul_F_FL, 40));
  1408. Add(TFunction.CreateOper('*', 'IL', etLargeInt, FuncMul_F_IL, 40));
  1409. Add(TFunction.CreateOper('*', 'LF', etFloat, FuncMul_F_LF, 40));
  1410. Add(TFunction.CreateOper('*', 'LL', etLargeInt, FuncMul_F_LI, 40));
  1411. Add(TFunction.CreateOper('*', 'LI', etLargeInt, FuncMul_F_LL, 40));
  1412. {$endif}
  1413. Add(TFunction.CreateOper('/', 'FF', etFloat, FuncDiv_F_FF, 40));
  1414. Add(TFunction.CreateOper('/', 'FI', etFloat, FuncDiv_F_FI, 40));
  1415. Add(TFunction.CreateOper('/', 'IF', etFloat, FuncDiv_F_IF, 40));
  1416. Add(TFunction.CreateOper('/', 'II', etInteger, FuncDiv_F_II, 40));
  1417. {$ifdef SUPPORT_INT64}
  1418. Add(TFunction.CreateOper('/', 'FL', etFloat, FuncDiv_F_FL, 40));
  1419. Add(TFunction.CreateOper('/', 'IL', etLargeInt, FuncDiv_F_IL, 40));
  1420. Add(TFunction.CreateOper('/', 'LF', etFloat, FuncDiv_F_LF, 40));
  1421. Add(TFunction.CreateOper('/', 'LL', etLargeInt, FuncDiv_F_LI, 40));
  1422. Add(TFunction.CreateOper('/', 'LI', etLargeInt, FuncDiv_F_LL, 40));
  1423. {$endif}
  1424. Add(TFunction.CreateOper('=', 'FF', etBoolean, Func_FF_EQ , 80));
  1425. Add(TFunction.CreateOper('<', 'FF', etBoolean, Func_FF_LT , 80));
  1426. Add(TFunction.CreateOper('>', 'FF', etBoolean, Func_FF_GT , 80));
  1427. Add(TFunction.CreateOper('<=','FF', etBoolean, Func_FF_LTE, 80));
  1428. Add(TFunction.CreateOper('>=','FF', etBoolean, Func_FF_GTE, 80));
  1429. Add(TFunction.CreateOper('<>','FF', etBoolean, Func_FF_NEQ, 80));
  1430. Add(TFunction.CreateOper('=', 'FI', etBoolean, Func_FI_EQ , 80));
  1431. Add(TFunction.CreateOper('<', 'FI', etBoolean, Func_FI_LT , 80));
  1432. Add(TFunction.CreateOper('>', 'FI', etBoolean, Func_FI_GT , 80));
  1433. Add(TFunction.CreateOper('<=','FI', etBoolean, Func_FI_LTE, 80));
  1434. Add(TFunction.CreateOper('>=','FI', etBoolean, Func_FI_GTE, 80));
  1435. Add(TFunction.CreateOper('<>','FI', etBoolean, Func_FI_NEQ, 80));
  1436. Add(TFunction.CreateOper('=', 'II', etBoolean, Func_II_EQ , 80));
  1437. Add(TFunction.CreateOper('<', 'II', etBoolean, Func_II_LT , 80));
  1438. Add(TFunction.CreateOper('>', 'II', etBoolean, Func_II_GT , 80));
  1439. Add(TFunction.CreateOper('<=','II', etBoolean, Func_II_LTE, 80));
  1440. Add(TFunction.CreateOper('>=','II', etBoolean, Func_II_GTE, 80));
  1441. Add(TFunction.CreateOper('<>','II', etBoolean, Func_II_NEQ, 80));
  1442. Add(TFunction.CreateOper('=', 'IF', etBoolean, Func_IF_EQ , 80));
  1443. Add(TFunction.CreateOper('<', 'IF', etBoolean, Func_IF_LT , 80));
  1444. Add(TFunction.CreateOper('>', 'IF', etBoolean, Func_IF_GT , 80));
  1445. Add(TFunction.CreateOper('<=','IF', etBoolean, Func_IF_LTE, 80));
  1446. Add(TFunction.CreateOper('>=','IF', etBoolean, Func_IF_GTE, 80));
  1447. Add(TFunction.CreateOper('<>','IF', etBoolean, Func_IF_NEQ, 80));
  1448. {$ifdef SUPPORT_INT64}
  1449. Add(TFunction.CreateOper('=', 'LL', etBoolean, Func_LL_EQ , 80));
  1450. Add(TFunction.CreateOper('<', 'LL', etBoolean, Func_LL_LT , 80));
  1451. Add(TFunction.CreateOper('>', 'LL', etBoolean, Func_LL_GT , 80));
  1452. Add(TFunction.CreateOper('<=','LL', etBoolean, Func_LL_LTE, 80));
  1453. Add(TFunction.CreateOper('>=','LL', etBoolean, Func_LL_GTE, 80));
  1454. Add(TFunction.CreateOper('<>','LL', etBoolean, Func_LL_NEQ, 80));
  1455. Add(TFunction.CreateOper('=', 'LF', etBoolean, Func_LF_EQ , 80));
  1456. Add(TFunction.CreateOper('<', 'LF', etBoolean, Func_LF_LT , 80));
  1457. Add(TFunction.CreateOper('>', 'LF', etBoolean, Func_LF_GT , 80));
  1458. Add(TFunction.CreateOper('<=','LF', etBoolean, Func_LF_LTE, 80));
  1459. Add(TFunction.CreateOper('>=','LF', etBoolean, Func_LF_GTE, 80));
  1460. Add(TFunction.CreateOper('<>','FI', etBoolean, Func_LF_NEQ, 80));
  1461. Add(TFunction.CreateOper('=', 'LI', etBoolean, Func_LI_EQ , 80));
  1462. Add(TFunction.CreateOper('<', 'LI', etBoolean, Func_LI_LT , 80));
  1463. Add(TFunction.CreateOper('>', 'LI', etBoolean, Func_LI_GT , 80));
  1464. Add(TFunction.CreateOper('<=','LI', etBoolean, Func_LI_LTE, 80));
  1465. Add(TFunction.CreateOper('>=','LI', etBoolean, Func_LI_GTE, 80));
  1466. Add(TFunction.CreateOper('<>','LI', etBoolean, Func_LI_NEQ, 80));
  1467. Add(TFunction.CreateOper('=', 'FL', etBoolean, Func_FL_EQ , 80));
  1468. Add(TFunction.CreateOper('<', 'FL', etBoolean, Func_FL_LT , 80));
  1469. Add(TFunction.CreateOper('>', 'FL', etBoolean, Func_FL_GT , 80));
  1470. Add(TFunction.CreateOper('<=','FL', etBoolean, Func_FL_LTE, 80));
  1471. Add(TFunction.CreateOper('>=','FL', etBoolean, Func_FL_GTE, 80));
  1472. Add(TFunction.CreateOper('<>','FL', etBoolean, Func_FL_NEQ, 80));
  1473. Add(TFunction.CreateOper('=', 'IL', etBoolean, Func_IL_EQ , 80));
  1474. Add(TFunction.CreateOper('<', 'IL', etBoolean, Func_IL_LT , 80));
  1475. Add(TFunction.CreateOper('>', 'IL', etBoolean, Func_IL_GT , 80));
  1476. Add(TFunction.CreateOper('<=','IL', etBoolean, Func_IL_LTE, 80));
  1477. Add(TFunction.CreateOper('>=','IL', etBoolean, Func_IL_GTE, 80));
  1478. Add(TFunction.CreateOper('<>','IL', etBoolean, Func_IL_NEQ, 80));
  1479. {$endif}
  1480. Add(TFunction.CreateOper('NOT', 'B', etBoolean, Func_NOT, 85));
  1481. Add(TFunction.CreateOper('AND', 'BB', etBoolean, Func_AND, 90));
  1482. Add(TFunction.CreateOper('OR', 'BB', etBoolean, Func_OR, 100));
  1483. // Functions - name, description, param types, min params, result type, Func addr
  1484. Add(TFunction.Create('STR', '', 'FII', 1, etString, FuncFloatToStr, ''));
  1485. Add(TFunction.Create('STR', '', 'III', 1, etString, FuncIntToStr, ''));
  1486. Add(TFunction.Create('DTOS', '', 'D', 1, etString, FuncDateToStr, ''));
  1487. Add(TFunction.Create('SUBSTR', 'SUBS', 'SII', 3, etString, FuncSubString, ''));
  1488. Add(TFunction.Create('UPPERCASE', 'UPPER', 'S', 1, etString, FuncUppercase, ''));
  1489. Add(TFunction.Create('LOWERCASE', 'LOWER', 'S', 1, etString, FuncLowercase, ''));
  1490. end;
  1491. with DbfWordsInsensGeneralList do
  1492. begin
  1493. Add(TFunction.CreateOper('<', 'SS', etBoolean, FuncStrI_LT , 80));
  1494. Add(TFunction.CreateOper('>', 'SS', etBoolean, FuncStrI_GT , 80));
  1495. Add(TFunction.CreateOper('<=','SS', etBoolean, FuncStrI_LTE, 80));
  1496. Add(TFunction.CreateOper('>=','SS', etBoolean, FuncStrI_GTE, 80));
  1497. Add(TFunction.CreateOper('<>','SS', etBoolean, FuncStrI_NEQ, 80));
  1498. end;
  1499. with DbfWordsInsensNoPartialList do
  1500. Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStrI_EQ , 80));
  1501. with DbfWordsInsensPartialList do
  1502. Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStrIP_EQ, 80));
  1503. with DbfWordsSensGeneralList do
  1504. begin
  1505. Add(TFunction.CreateOper('<', 'SS', etBoolean, FuncStr_LT , 80));
  1506. Add(TFunction.CreateOper('>', 'SS', etBoolean, FuncStr_GT , 80));
  1507. Add(TFunction.CreateOper('<=','SS', etBoolean, FuncStr_LTE, 80));
  1508. Add(TFunction.CreateOper('>=','SS', etBoolean, FuncStr_GTE, 80));
  1509. Add(TFunction.CreateOper('<>','SS', etBoolean, FuncStr_NEQ, 80));
  1510. end;
  1511. with DbfWordsSensNoPartialList do
  1512. Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStr_EQ , 80));
  1513. with DbfWordsSensPartialList do
  1514. Add(TFunction.CreateOper('=', 'SS', etBoolean, FuncStrP_EQ , 80));
  1515. finalization
  1516. DbfWordsGeneralList.Free;
  1517. DbfWordsInsensGeneralList.Free;
  1518. DbfWordsInsensNoPartialList.Free;
  1519. DbfWordsInsensPartialList.Free;
  1520. DbfWordsSensGeneralList.Free;
  1521. DbfWordsSensNoPartialList.Free;
  1522. DbfWordsSensPartialList.Free;
  1523. end.