uPublic.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. unit uPublic;
  2. interface
  3. uses
  4. LIBC, IniFiles, QForms, SysUtils, Classes, QGraphics,
  5. QMenus, QStdCtrls, QExtCtrls, QGrids, Variants,
  6. QDialogs, QPrinters;
  7. const
  8. key = 18900;
  9. text_size = 511;
  10. type
  11. msgbuff = record
  12. mtype: integer;
  13. mtext: array[0..511] of char;
  14. end;
  15. type
  16. //linux
  17. RTTCdata = record
  18. NozNO: INTEGER; //油枪号
  19. TTC: Integer; //流水号
  20. TTCtime: string; //上传时间
  21. MON: Double; //加油金额
  22. VOL: Double; //加油量
  23. rationV: Double; //预付金额
  24. code: string;
  25. FuelNO: string; //油品编号
  26. FuelName: string; //
  27. state: integer; //状态 0=空闲 1=申请 2= 通过 3=无此验证码 4=允许加油 5=加油未找零 6=验证码油品错误 7=验证码过期
  28. end;
  29. type
  30. Tzfz_posstat = record
  31. posid: integer;
  32. pos_stat: byte;
  33. cash_stat: byte;
  34. prt_stat: byte;
  35. money: integer;
  36. door_stat: byte;
  37. end;
  38. TzfzPosArr = array of Tzfz_posstat;
  39. EAdvListViewError = class(Exception); //输出错误提示
  40. TResultByteArray = array of byte;
  41. TFuellingPointDB = record
  42. FP_Name: string; //加油点的名称
  43. Nb_Tran_Buffer_Not_Paid: integer; //脱机记录编号 1-15
  44. Nb_Of_Historic_Trans: integer; //已经清除的交易记录编号 1-15
  45. Nb_Logical_Nozzle: integer; //逻辑枪号 1-8
  46. Loudspeaker_Switch: integer; //加油点喇叭的开关 0=off 1=on
  47. Default_Fuelling_Mode: integer; //默认的加油模式 FM,1-8
  48. Leak_Log_Noz_Mask: integer; //理解为测试用油 泄露测试
  49. Drive_Off_Light_Switch: integer; //设备灯 开关
  50. OPT_Light_Switch: integer; //OPT灯 开关
  51. FP_State: integer; //加油点状态
  52. Log_Noz_State: integer; //枪状态
  53. Assign_Contr_Id: string; //FP 当前登陆的 CD SUBNET+NODE 两字节
  54. Release_Mode: integer; // 开放模式 1=允许脱机加油 0=不允许
  55. ZeroTR_Mode: integer; // 0交易记录是否保存 ,0=不保存 1=保存
  56. Log_Noz_Mask: integer; //授权某一条枪或者多条抢 BIN8 每位代表一条枪 0=未授权 1=已授权
  57. Config_Lock: string; // 设置FP只与这个CD通讯 SUBNET+NODE 两字节
  58. Remote_Amount_Prepay: string; //定量金额
  59. Remote_Volume_Preset: string; //定量值
  60. Release_Token: INTEGER; //
  61. Fuelling_Mode: integer; //
  62. Transaction_Sequence_Nb: string; //交易流水号 1-9999 BCD
  63. Current_TR_Seq_Nb: string; //为当前正在加油的记录指定一个交易流水号。1-9999 BCD
  64. Release_Contr_Id: string; //大概是当前正在交易的记录是由哪个CD控制的
  65. Suspend_Contr_Id: string; //和上面的有关系,这两个都不知道什么意思
  66. Current_Amount: string; //加油金额
  67. Current_Volume: string; //加油量
  68. Current_Unit_Price: string; //单价
  69. Current_Log_Noz: integer; //正在加油的枪
  70. Current_Prod_Nb: integer; //商品号(油品)
  71. Current_TR_Error_Code: integer; //当前记录的错误状态,0=没错误
  72. Current_Average_Temp: string; //
  73. Current_Price_Set_Nb: string; //
  74. Multi_Nozzle_Type: integer; //
  75. Multi_Nozzle_State: integer; //
  76. Multi_Nozzle_Status_Message: integer; //
  77. Local_Vol_Preset: string; //
  78. Local_Amount_Prepay: string; //
  79. Running_Transaction_Message_Frequency: string; //
  80. Open_FP: integer; //启动加油点
  81. Close_FP: integer; //关闭加油点
  82. Release_FP: integer; //授权加油点
  83. Terminate_FP: integer; //停止加油
  84. Suspend_FP: integer; //暂停加油
  85. Resume_FP: integer; //恢复加油
  86. Clear_Display: integer; //清空显示版
  87. Leak_Command: integer;
  88. FP_Alarm: string; //警报
  89. FP_Status_Message: string;
  90. FP_Multi_Nozzle_Status_Message: integer;
  91. FP_Running_Transaction_Message: string;
  92. end;
  93. TPaymentState = record
  94. cardno: string;
  95. logicCardNO: string;
  96. LastlogicCardNO: string;
  97. PerSet: Double;
  98. PayState: integer;
  99. LastPayState: integer;
  100. ispaid: integer;
  101. Lastispaid: integer;
  102. paytype: integer;
  103. Fueled: integer;
  104. AcctID: string;
  105. end;
  106. procedure SplitColumns(const AData: string; AStrings: TStrings; const ADelim: string = ' ');
  107. procedure PRINTSTRINGGRID(StringGrid: TStringGrid; _titel: string; PAGETYPE: INTEGER = 0);
  108. function _IsInt(sStr: string): boolean;
  109. function _IsFloat(sStr: string): boolean;
  110. function _IsDate(sStr: string): boolean;
  111. function _IsTime(sStr: string): boolean;
  112. function _IsDateTime(sStr: string): boolean;
  113. function GetdateTimestrD1(dtstr: string; _INC: INTEGER): string;
  114. //function _GetDCB(DCBSTR:STRING):TDCB;
  115. // procedure _OpenFile(sFileName: string);
  116. function _SelectedFile(var sFileName: string; sExt: string = ''; sPath: string = ''): boolean;
  117. function _SaveTo(var sFileName: string; sExt: string; sPath: string = ''): boolean;
  118. procedure _Msg(sPrompt: string; sTitle: string = '');
  119. procedure _MsgError(sPrompt: string; sTitle: string = '');
  120. function _MsgYesNo(sPrompt: string; sTitle: string = ''): TMessageButton;
  121. // function _MsgOKCancel(sPrompt: string; sTitle: string = ''): integer;
  122. function _ErrorDate(sDate: string): string;
  123. function _ErrorTime(sTime: string): string;
  124. function _ErrorInt(sStr: string): string;
  125. function _ErrorFloat(sStr: string): string;
  126. procedure _test;
  127. function _GetAppPath: string;
  128. function _GetExcelPath: string;
  129. function _GetTrsDBPath: string;
  130. function _GetLogDBPath: string;
  131. function _GetRFCardPath: string;
  132. function _GetDBPath: string;
  133. procedure _LoadIPconfig; //取IP配置
  134. // procedure _ToExcel(sFileName: string;strGrid:TStringGrid);
  135. function _GetMK: string;
  136. // procedure _ToExcelDX(aDBGridEh: TdxDBGrid);
  137. function _LAddChar(sStr, sChar: string; iLength: integer): string;
  138. function _RAddChar(sStr, sChar: string; iLength: integer): string;
  139. function _NextNo(sNo: string): string;
  140. function _GetAccountNo(aDate: TDateTime): string;
  141. //系统 ID h:=GetHWndByPID(GetPID('hscd.exe'));
  142. // function GetPID(ExeFileName: string): integer;
  143. // function GetHWndByPID(const hPID: THandle): THandle;
  144. //控制LV到某一列并取值
  145. // function ListView_GetItemText_Ex(hwndLV: Integer; i, iSubItem: Integer;
  146. // pszText: PChar; cchTextMax: Integer): Integer;
  147. //不控制一列只取值
  148. // function ListView_GetItemText_NOT_SELECT(hwndLV:integer; i, iSubItem: Integer;
  149. // pszText: PChar; cchTextMax: Integer): Integer;
  150. //菜单操作和查找
  151. // FUNCTION ClickMenu(h:integer; MainIndex,SubIndex:integer) :integer;
  152. // function Find_SubMenuByCaption(h:integer;str:string;var MainIndex,SubIndex:integer):TStringList;
  153. //获取本地串口列表
  154. procedure _GetLocalCommList(var stList: TStringList);
  155. var
  156. _AppPath: string;
  157. _XlsPath: string;
  158. _TrsDBPath: string;
  159. _LogDBPath: string;
  160. _RFCardPath: string;
  161. _DBPath: string;
  162. _PsamIP: string;
  163. _PsamPort: integer;
  164. _ShiftID: string;
  165. _DayID: string;
  166. _MK: string;
  167. _User: string;
  168. _UserID: string;
  169. _E_isSup: integer;
  170. StateList: array of RTTCdata;
  171. StatePanelParentList: array of TPanel;
  172. posPlist: array of TPanel;
  173. _istest: integer;
  174. _isLOG: integer;
  175. _prtOrt: integer;
  176. _paymode: integer;
  177. _bPrint: integer;
  178. RTLDB: TRTLCriticalSection; //显示线程临界区
  179. CSMNT: TRTLCriticalSection; //显示线程临界区
  180. //InterlockedCritDisplay : TRTLCriticalSection; //显示线程临界区
  181. /// InterlockedRFCARD : TRTLCriticalSection; //RF卡支付线程临界区
  182. // InterlockedLocalFuel : TRTLCriticalSection; //RF卡支付线程临界区
  183. msgID: INTEGER; //PUBLIC
  184. ThreadMsgID1, ThreadMsgID2: INTEGER;
  185. implementation
  186. uses DESCrypt;
  187. const
  188. NumberArr: array[0..9] of Char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
  189. LetterArr: array[0..25] of Char = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  190. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
  191. 'u', 'v', 'w', 'x', 'y', 'z');
  192. {
  193. function _GetDCB(DCBSTR:STRING):TDCB;
  194. BEGIN
  195. Result.BaudRate:=STRTOINT(COPY(DCBSTR,1,POS(',',DCBSTR)-1));
  196. DCBSTR:=COPY(DCBSTR,POS(',',DCBSTR)+1,LENGTH(DCBSTR));
  197. Result.ByteSize:=STRTOINT(COPY(DCBSTR,1,POS(',',DCBSTR)-1));
  198. DCBSTR:=COPY(DCBSTR,POS(',',DCBSTR)+1,LENGTH(DCBSTR));
  199. Result.Parity:=STRTOINT(COPY(DCBSTR,1,POS(',',DCBSTR)-1));
  200. DCBSTR:=COPY(DCBSTR,POS(',',DCBSTR)+1,LENGTH(DCBSTR));
  201. Result.StopBits:=STRTOINT(DCBSTR);
  202. END;
  203. }
  204. procedure PRINTSTRINGGRID(StringGrid: TStringGrid; _titel: string; PAGETYPE: INTEGER = 0);
  205. var
  206. i, ii, r: Integer;
  207. xdpi, ydpi, x, y: Integer;
  208. ye: integer;
  209. begin
  210. xdpi := 120;
  211. ydpi := 120;
  212. x := 0;
  213. Y := 150;
  214. Printer.Title := 'HS Printer';
  215. Printer.canvas.Font.Size := 12;
  216. if PAGETYPE = 0 then
  217. printer.Orientation := poPortrait
  218. else
  219. printer.Orientation := poLandscape;
  220. Printer.BeginDoc;
  221. with Printer.Canvas do
  222. begin
  223. ye := 1;
  224. i := 0;
  225. r := 1;
  226. while r < StringGrid.RowCount do
  227. // for i := 0 to StringGrid.RowCount do
  228. begin
  229. x := 0;
  230. if I = 0 then
  231. begin
  232. TextOut(x * 2, y - 100, _titel + ' ' + formatdatetime('yyyy-MM-dd HH:mm:SS', now) + ' 第 ' + inttostr(ye) + ' 页');
  233. for ii := 0 to StringGrid.colCount do
  234. begin
  235. MoveTo(x, ydpi + Y);
  236. LineTo(x, ydpi * i + Y);
  237. MoveTo(x, ydpi * i + Y);
  238. x := x + StringGrid.ColWidths[ii] * 5 + 100;
  239. LineTo(x, ydpi * i + Y);
  240. TextOut(x - (StringGrid.ColWidths[ii] * 5 + 90), ydpi * i + 2 + Y, StringGrid.Cells[ii, 0]);
  241. end;
  242. MoveTo(x, ydpi + Y);
  243. LineTo(x, ydpi * i + Y);
  244. end
  245. else
  246. begin
  247. for ii := 0 to StringGrid.colCount do
  248. begin
  249. MoveTo(x, ydpi + Y);
  250. LineTo(x, ydpi * i + Y);
  251. MoveTo(x, ydpi * i + Y);
  252. x := x + StringGrid.ColWidths[ii] * 5 + 100;
  253. LineTo(x, ydpi * i + Y);
  254. TextOut(x - (StringGrid.ColWidths[ii] * 5 + 90), ydpi * i + 2 + Y, StringGrid.Cells[ii, r]);
  255. end;
  256. MoveTo(x, ydpi + Y);
  257. LineTo(x, ydpi * i + Y);
  258. r := r + 1;
  259. end;
  260. if (i * ydpi) >= (printer.PageHeight - ydpi * 2 - 150) then
  261. begin
  262. i := i + 1;
  263. x := 0;
  264. for ii := 0 to StringGrid.colCount do
  265. begin
  266. MoveTo(x, ydpi + Y);
  267. LineTo(x, ydpi * i + Y);
  268. MoveTo(x, ydpi * i + Y);
  269. x := x + StringGrid.ColWidths[ii] * 5 + 100;
  270. LineTo(x, ydpi * i + Y);
  271. end;
  272. MoveTo(x, ydpi + Y);
  273. LineTo(x, ydpi * i + Y);
  274. ye := ye + 1;
  275. i := 0;
  276. printer.newpage;
  277. end
  278. else
  279. i := i + 1;
  280. end;
  281. end;
  282. Printer.EndDoc;
  283. end;
  284. function _GetMK: string;
  285. begin
  286. Result := EnCrypt_String('004150');
  287. end;
  288. function _GetAppPath: string;
  289. begin
  290. _AppPath := ExtractFilePath(Application.ExeName);
  291. Result := _AppPath;
  292. end;
  293. function _GetExcelPath: string;
  294. begin
  295. _XlsPath := ExtractFilePath(Application.ExeName) + 'xls/';
  296. Result := _XlsPath;
  297. end;
  298. function _GetTrsDBPath: string;
  299. begin
  300. _TrsDBPath := ExtractFilePath(Application.ExeName) + 'DB/TRSDB.T';
  301. Result := _TrsDBPath;
  302. end;
  303. function _GetLogDBPath: string;
  304. begin
  305. _LogDBPath := ExtractFilePath(Application.ExeName) + 'DB/LOGDB.L';
  306. Result := _LogDBPath;
  307. end;
  308. function _GetRFcardPath: string;
  309. begin
  310. _RFCardPath := ExtractFilePath(Application.ExeName) + 'RFcard/';
  311. Result := _RFCardPath;
  312. end;
  313. function _GetDBPath: string;
  314. begin
  315. _DBPath := ExtractFilePath(Application.ExeName) + 'db/';
  316. Result := _DBPath;
  317. end;
  318. //iStyle = 1, 下一个大写字母
  319. function NextChar(sChar: Char; iStyle: integer): Char;
  320. var
  321. i: integer;
  322. s: string;
  323. begin
  324. Result := sChar;
  325. s := LowerCase(sChar);
  326. for i := 0 to 25 do
  327. if s = LetterArr[i] then
  328. begin
  329. Result := LetterArr[(i + 1) mod 26];
  330. Break;
  331. end;
  332. if iStyle = 1 then
  333. Result := UpCase(Result);
  334. end;
  335. //下一个数字
  336. function NextNumber(sChar: Char): Char;
  337. var
  338. i: integer;
  339. begin
  340. Result := sChar;
  341. for i := 0 to 9 do
  342. if sChar = NumberArr[i] then
  343. begin
  344. Result := NumberArr[(i + 1) mod 10];
  345. Break;
  346. end;
  347. end;
  348. //左边增加字符串
  349. function _LAddChar(sStr, sChar: string; iLength: integer): string;
  350. var
  351. i: integer;
  352. begin
  353. Result := sStr;
  354. for i := Length(sStr) + 1 to iLength do
  355. Result := sChar + Result;
  356. end;
  357. //右边增加字符串
  358. function _RAddChar(sStr, sChar: string; iLength: integer): string;
  359. var
  360. i: integer;
  361. begin
  362. Result := sStr;
  363. for i := Length(sStr) + 1 to iLength do
  364. Result := Result + sChar;
  365. end;
  366. //是有效整型数
  367. function _IsInt(sStr: string): boolean;
  368. begin
  369. try
  370. StrToInt(sStr);
  371. Result := true;
  372. except
  373. Result := false;
  374. end;
  375. end;
  376. function GetdateTimestrD1(dtstr: string; _INC: INTEGER): string;
  377. var dt: Tdatetime;
  378. timestr, datestr: string;
  379. begin
  380. datestr := copy(dtstr, 1, pos(' ', dtstr) - 1);
  381. timestr := copy(dtstr, pos(' ', dtstr) + 1, 10);
  382. try
  383. dt := strtodate(datestr) - _INC + strtotime(timestr);
  384. except
  385. _msgerror('datetime error!');
  386. exit;
  387. end;
  388. result := formatdatetime('YYYY-MM-DD HH:mm:SS', DT);
  389. end;
  390. //是有效浮点数
  391. function _IsFloat(sStr: string): boolean;
  392. begin
  393. try
  394. StrToFloat(sStr);
  395. Result := true;
  396. except
  397. Result := false;
  398. end;
  399. end;
  400. //是有效日期
  401. function _IsDate(sStr: string): boolean;
  402. begin
  403. try
  404. StrToDate(sStr);
  405. Result := true;
  406. except
  407. Result := false;
  408. end;
  409. end;
  410. function _IsDateTime(sStr: string): boolean;
  411. begin
  412. try
  413. StrToDatetime(sStr);
  414. Result := true;
  415. except
  416. Result := false;
  417. end;
  418. end;
  419. //是有效时间
  420. function _IsTime(sStr: string): boolean;
  421. begin
  422. try
  423. StrToTime(sStr);
  424. Result := true;
  425. except
  426. Result := false;
  427. end;
  428. end;
  429. //获得下一编号
  430. function _NextNo(sNo: string): string;
  431. var
  432. iLen: integer;
  433. bStr: string;
  434. sChar: Char;
  435. begin
  436. Result := sNo;
  437. if Trim(sNo) = '' then Exit;
  438. iLen := Length(sNo);
  439. sChar := sNo[iLen];
  440. bStr := Copy(sNo, 1, iLen - 1);
  441. if sChar in ['0'..'9'] then
  442. begin
  443. sChar := NextNumber(sChar);
  444. if sChar = '0' then
  445. bStr := _NextNo(bStr);
  446. Result := bStr + sChar;
  447. end
  448. else if sChar in ['a'..'z'] then
  449. begin
  450. sChar := NextChar(sChar, 0);
  451. if sChar = 'a' then
  452. bStr := _NextNo(bStr);
  453. Result := bStr + sChar;
  454. end
  455. else if sChar in ['A'..'Z'] then
  456. begin
  457. sChar := NextChar(sChar, 1);
  458. if sChar = 'A' then
  459. bStr := _NextNo(bStr);
  460. Result := bStr + sChar;
  461. end
  462. else
  463. Result := _NextNo(bStr) + sChar;
  464. end;
  465. function _SelectedFile(var sFileName: string;
  466. sExt: string = '';
  467. sPath: string = ''): boolean;
  468. begin
  469. Result := False;
  470. with TOpenDialog.Create(nil) do
  471. try
  472. Options := Options + [ofFileMustExist];
  473. if Trim(sExt) = '' then
  474. sExt := '*';
  475. Filter := Format('文件类型 (*.%s)|*.%s', [sExt, sExt]);
  476. if Trim(sPath) = '' then
  477. InitialDir := _AppPath
  478. else
  479. InitialDir := sPath;
  480. if Execute then
  481. begin
  482. sFileName := FileName;
  483. Result := True;
  484. end;
  485. finally
  486. Free;
  487. end;
  488. end;
  489. function _SaveTo(var sFileName: string;
  490. sExt: string;
  491. sPath: string = ''): boolean;
  492. begin
  493. Result := False;
  494. with TSaveDialog.Create(nil) do
  495. try
  496. Options := Options + [ofOverwritePrompt];
  497. if Trim(sExt) <> '' then
  498. DefaultExt := sExt
  499. else
  500. sExt := '*';
  501. Filter := Format('文件类型 (*.%s)|*.%s', [sExt, sExt]);
  502. if sPath = '' then
  503. InitialDir := _AppPath
  504. else
  505. InitialDir := sPath;
  506. if Execute then
  507. begin
  508. sFileName := FileName;
  509. Result := True;
  510. end;
  511. finally
  512. Free;
  513. end;
  514. end;
  515. procedure _Msg(sPrompt: string; sTitle: string);
  516. begin
  517. //if sTitle <> '' then
  518. Application.MessageBox(Pchar(sPrompt),
  519. Pchar(sTitle))
  520. end;
  521. // MB_ICONINFORMATION
  522. procedure _MsgError(sPrompt: string; sTitle: string);
  523. begin
  524. //if sTitle <> '' then
  525. Application.MessageBox(Pchar(sPrompt),
  526. Pchar(sTitle),
  527. [smbOK], smsWarning)
  528. end;
  529. function _MsgYesNo(sPrompt: string; sTitle: string): TMessageButton;
  530. var bts: TMessageButtons;
  531. begin
  532. bts := [smbYes, smbNo, smbCancel];
  533. // if sTitle <> '' then
  534. result := Application.MessageBox(Pchar(sPrompt), Pchar(sTitle), bts); //,smsWarning,smsWarning,smbOK);
  535. end;
  536. function PosIdx(const ASubStr, AStr: AnsiString; AStartPos: Cardinal): Cardinal;
  537. var
  538. lpSubStr, lpS: PChar;
  539. LenSubStr, LenS: Integer;
  540. LChar: Char;
  541. begin
  542. LenSubStr := Length(ASubStr);
  543. LenS := Length(AStr);
  544. if (LenSubStr = 0) or (LenSubStr > LenS) then begin
  545. Result := 0; //not found
  546. EXIT;
  547. end; //if
  548. lpSubStr := Pointer(ASubStr);
  549. lpS := Pointer(AStr);
  550. if AStartPos > 0 then begin
  551. lpS := lpS + AStartPos - 1;
  552. LenS := LenS + 1 - Integer(AStartPos);
  553. end; //if
  554. LChar := lpSubStr[0]; //first char
  555. lpSubStr := lpSubStr + 1; //next char
  556. LenSubStr := LenSubStr - 1; //len w/o first char
  557. LenS := LenS - LenSubStr; //Length(S)-Length(SubStr) +1(!) MUST BE >0
  558. if LenS <= 0 then begin
  559. Result := 0;
  560. EXIT;
  561. end; //if
  562. while LenS > 0 do begin
  563. if lpS^ = LChar then begin
  564. inc(lpS);
  565. if CompareMem(lpS, lpSubStr, LenSubStr) then begin
  566. Result := lpS - Pointer(AStr); //+1 already here
  567. EXIT;
  568. end;
  569. end
  570. else begin
  571. inc(lpS);
  572. end;
  573. dec(LenS);
  574. end; //while
  575. Result := 0;
  576. end; //PosIdx
  577. procedure SplitColumns(const AData: string; AStrings: TStrings; const ADelim: string = ' '); {Do not Localize}
  578. var
  579. i: Integer;
  580. LData: string;
  581. LDelim: Integer; //delim len
  582. LLeft: string;
  583. LLastPos: Integer;
  584. LLeadingSpaceCnt: Integer;
  585. begin
  586. Assert(Assigned(AStrings));
  587. AStrings.Clear;
  588. LDelim := Length(ADelim);
  589. LLastPos := 1;
  590. LData := Trim(AData);
  591. LLeadingSpaceCnt := 0;
  592. if Length(LData) > 0 then begin //if Not WhiteStr
  593. while AData[LLeadingSpaceCnt + 1] <= ' ' do inc(LLeadingSpaceCnt);
  594. end
  595. else begin
  596. EXIT;
  597. end;
  598. i := Pos(ADelim, LData);
  599. while I > 0 do begin
  600. LLeft := Copy(LData, LLastPos, I - LLastPos); //'abc d' len:=i(=4)-1 {Do not Localize}
  601. if LLeft > '' then begin {Do not Localize}
  602. AStrings.AddObject(Trim(LLeft), Pointer(LLastPos + LLeadingSpaceCnt));
  603. end;
  604. LLastPos := I + LDelim; //first char after Delim
  605. i := PosIdx(ADelim, LData, LLastPos);
  606. end; //while found
  607. if LLastPos <= Length(LData) then begin
  608. AStrings.AddObject(Trim(Copy(LData, LLastPos, MaxInt)), Pointer(LLastPos + LLeadingSpaceCnt));
  609. end;
  610. end; //TIdFTPListItems.ParseColumns
  611. {
  612. function _MsgOKCancel(sPrompt: string; sTitle: string): integer;
  613. begin
  614. if sTitle <> '' then
  615. Result := Application.MessageBox(Pchar(sPrompt),Pchar(sTitle),
  616. MB_OKCANCEL + MB_ICONQUESTION + MB_DEFBUTTON2)
  617. else
  618. Result := Application.MessageBox(Pchar(sPrompt),Pchar(Application.Title),
  619. MB_OKCANCEL + MB_ICONQUESTION + MB_DEFBUTTON2);
  620. end; }
  621. {procedure _ToExcelDX(aDBGridEh: TdxDBGrid);
  622. var
  623. sFileName: string;
  624. begin
  625. if (not aDBGridEh.DataSource.DataSet.Active) or
  626. (aDBGridEh.DataSource.DataSet.IsEmpty) then
  627. begin
  628. _MsgError('对不起!没有数据可输出!');
  629. Exit;
  630. end;
  631. if _SaveTo(sFileName,'xls',_XlsPath) then
  632. begin
  633. aDBGridEh.SaveToXLS(sFileName,TRUE);
  634. { if _MsgBox('现在打开【' + sFileName + '】吗?') = IDOK then
  635. _OpenFile(sFileName);
  636. end;
  637. end; }
  638. function _GetAccountNo(aDate: TDateTime): string;
  639. var
  640. iY, iM, iD: Word;
  641. begin
  642. DecodeDate(aDate, iY, iM, iD);
  643. Result := IntToStr(iY) + '年' +
  644. _LAddChar(IntToStr(iM), '0', 2) + '月';
  645. end;
  646. function _ErrorDate(sDate: string): string;
  647. begin
  648. Result := Format('【%s】 - 无效的日期!', [sDate]);
  649. end;
  650. function _ErrorTime(sTime: string): string;
  651. begin
  652. Result := Format('【%s】 - 无效的时间!', [sTime]);
  653. end;
  654. function _ErrorInt(sStr: string): string;
  655. begin
  656. Result := Format('【%s】 - 无效的整数!', [sStr]);
  657. end;
  658. function _ErrorFloat(sStr: string): string;
  659. begin
  660. Result := Format('【%s】 - 无效的浮点数!', [sStr]);
  661. end;
  662. procedure _test;
  663. begin
  664. _Msg('test ok');
  665. end;
  666. procedure _loadIPconfig;
  667. var configini: TIniFile;
  668. begin
  669. _GetAppPath;
  670. configini := TIniFile.Create(_AppPath + 'config.ini');
  671. _PsamIP := configini.ReadString('PSAM CONFIG', 'ip', '');
  672. _PsamPort := configini.ReadInteger('PSAM CONFIG', 'port', 18900);
  673. configini.Free;
  674. end;
  675. procedure _GetLocalCommList(var stList: TStringList);
  676. begin
  677. ; ;
  678. end;
  679. end.