C ++ Builder self-contained common function library (1)

xiaoxiao2021-03-06  15

#ifndef dujunlitoolscpp #define dujunlitoolscpp // Library 2002-11-15 19:26 #include #include #include #include #include #include #include #include /// md5 Ansistring __fastcall strip (Ansistring s) {Return S.delete (1, 2);}

Ansistring MD5TOString (ANSISTRING S) {ANSISTRING AHEX;

For (int i = 1; i <= s.Length (); i ) {AHEX = INTTOHEX (UNSIGNED Char) S [i], 2); // ""

return AHex;} String Md5Str (String src) {TIdCoderMD5 * md5 = new TIdCoderMD5 (NULL); md5-> Reset (); md5-> AutoCompleteInput = true; String tmp = md5ToString (Strip (md5-> CodeString (src)) ); delete md5; md5 = null; return tmp;} // md5 end bool OpenForm (TForm * wform) {

// IF (OpenForm (fRMMEM) == false) // {// fmmem = new tfrmmmem (application); // OpenForm (fmmem); //} // use example INT i; BOOL formexist;

IF (wform == null) Return False; formexist = false; for (i = 0; i formcount; i ) IF (screen-> forms [i] -> classtype () == wform-> classType )) {Formexist = true; break;} if (formexist == false) Return formexist;

IF (wform-> windowstate == wsminimized) showwindow (wform-> handle, sw_shownormal); else showwindow (wform-> handle, sw_showna); if (! wform-> visible) wform-> visible = true;

IF (getWindowlong (wform-> handle, gwl_exstyle & ws_ex_appwindow)! = ws_ex_appwindow) setWindowlong (wform-> handle, gwl_exstyle, ws_ex_appwindow);

WFORM-> bringtofront (); wform-> setfocus (); return true;} // -------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------- String REPL (String SSTR, STRING FSTR, STRING REPSTR) {// Replace String function string tmpstr = ""; int x = sstr.ansipos (fstr); if (x == 0) {tmpstr = SSTR; //application ,>MessageBoxa(SSTR.c_STR () ,"", Mb_ok); // Did not find the lookup string, return return tmpswstr;} while (x! = 0) {TmpStr = sstr.substring (1, x-1) REPSTR; SSTR = SSTR.SUBSTRING (X FSTR.LENGTH ), sstr.length ()); x = sstr.ansipos (fstr);} Tmpstr = SSTR; //application ,>MessageBoxa (TMPSTR.C_STR () ,""" ,mb_ok); Return Tmpstr;} // ------------------------------------------ String SQLSTR (String Sqlstr) { // if (SQLSTR! = "") {SQLSTR = REPL (SQLSTR, "'", "'");} Return SQLSTR;} // ---------------- --------------------- TDATETIME PMON (TDATETIME DT) {// Take a month Date Unsigned Short Year, Mon, Day, Hour, Min, Sec, Msec; DT.Decodedate (& Year, & Mon, & Day); DT.Decodetime (& Hour, & min, & sec, & msec); if (Mon <= 1) {Year- = 1; M ON = 12;} else {mon- = 1;} DT = :: Encodedate (Year, MON, day); Return DT;} TDATETIME NMON (TDATETIME DT) {// Remove the date Unsigned Short Year, Mon Day, Hour, Min, Sec, Msec; DT.Decodedate (& Year, & Mon, & Day); DT.Decodetime (& Hour, & min, & sec, & msec); if (Mon> = 12) {YEAR = 1; MON = 1 } Else {MON = 1;} DT = :: Encodedate (Year, MON, day); returnit DT;} // Export data to Excel; // Void DatasettoExcel (TDataSet * DataSet, Bool H ); // h: Table Press the line (

Normal) // Variant EX, WBS, WB, SH1; / / / --------------------------------- ----------------------------------------- / * // is not perfect, wrong To: If the data contains filtration properties, use Recount as uncomfortable void DataSetToExcel (TDataSet * Dataset, Bool H) {Variant EX, WBS, WB, SH1; INT Currrow, currcol; currcol = 0; currrow = 0; screen-> Cursor = CRHOURGLASS; if (ex.isempty ()) Try {hwnd hprevapp = :: FindWindow (Null, "Microsoft Excel"); if (! Hprevapp) {EX = variant :: createObject ("excel.application");} Else {EX = Variant :: getActiveObject ("excel.application");}} catch (...) {screen-> Cursor = crdefault; showMessage ("Open Excel error, please confirm that you have installed MS Office!" );}} Try {if ("ActiveWorkbook"). ISempty ()) EX.OLEPROPERTYGET ("Workbooks"). OLEPROCEDURE ("add"); if (wb.isempty ()) WB = EX. OLEPROPERTYGET ("ActiveWorkbook"); sh1 = wb.olePropertyget ("Sheets"). OLEFUNCTIO n ("add"); ex. op.} catch (...) {ex= ex.empty (); wb = wb.empty (); DataSetToExcel (Dataset, H);} IF (h) {

For (int J = 0; j fields-> count; j ) {if (dataset-> fields-> fields [j] -> visible) {currcol ; sh1.olepropertyget ("cells", 1, currcol ) .OlePropertySet ("Value", DataSet-> fields-> fields [j] -> fieldname);}} Dataset-> first (); for (int i = 0; i recordcount; i ) {CURRCOL = 0; for (int J = 0; j fields-> count; j ) {if (dataset-> fields-> fields [j] -> visible) {currcol ; sh1.olepropertyget ("cells", i 2, currcol) .olePropertySet ("Value", DataSet-> Fields-> Fields [J] -> asstring);}} Application-> ProcessMESSAGES (); Dataset-> Next ();}} else {for INT j = 0; j fields-> count; j ) {if (dataset-> fields-> fields [j] -> visible) {currrow ; sh1.olepropertyget ("Cell) s ", currrow, 1) .olePropertyset (" Value ", DataSet-> fields-> fields [j] -> fieldname); DataSet-> first (); for (int i = 0; i recordcount; i ) {Sh1.olePropertyget ("cells", currrow, i 2) .olePropertySet ("Value", DataSet-> Fields-> Fields [J] -> asstring); DataSet-> next ();}}}} Screen-> Cursor = crdefault;

} * / void DataSetToExcel (TDataSet * Dataset, Bool H) {Variant EX, WBS, WB, Sh1; Int Currrow, currcol; currcol = 0; Currrow = 0; Screen-> Cursor = CRHOURGLASS; if (EX.Isempty () "Try {hwnd hprevapp = :: FindWindow (Null," Microsoft Excel "); if (! Hprevapp) {EX = variant :: createObject (" excel.application ");} else {EX = variant :: getActiveObject (" Excel .Application ");}} catch (...) {Screen-> Cursor = crdefault; showMessage (" Open Excel error, please confirm that you have installed MS Office! "); Return;} try {if (EX. OLEPROPERTYGET ("ActiveWorkbook"). ISempty ()) EX.OLEPROPERTYGET ("Workbooks"). OLEPROCEDURE ("add"); if (wb.isempty ()) WB = ex. oportyget ("ActiveWorkbook"; sh1 = WB. OLEPROPERTYGET ("Sheets"). OLEFUNCTION ("add");} catch (...) {EX = ex.empty (); wb = wb.empty (); DataSetToExcel (Dataset, H);} if (h) {

For (int J = 0; j fields-> count; j ) {if (dataset-> fields-> fields [j] -> visible) {currcol ; sh1.olepropertyget ("cells", 1, currcol ) .Olepropertyset ("value", dataset-> fields-> fields [j] -> fieldname);}} Dataset-> first (); / * for (int i = 0; i recordcount; i ) {Currcol = 0; for (int J = 0; j fields-> count; j ) {if (dataset-> fields-> fields [j] -> visible) {currcol ; sh1.olepropertyget ("cells ", i 2, currcol) .olePropertySet (" Value ", DataSet-> Fields-> Fields [J] -> asstring);}} Application-> processMessages (); DataSet-> next ();} * / int i = 0; while (! DataSet-> EOF) {currcol = 0; for (int J = 0; j fields-> count; j ) {if (dataset-> fields-> Fiel DS [J] -> Visible) {currcol ; sh1.olepropertyget ("cells", i 2, currcol) .olePropertySet ("Value", DataSet-> Fields-> Fields [J] -> asstring);}} Application -> ProcessMess (); Dataset-> Next (); i ;}} else {for (int J = 0; j fields-> count; j ) {if (dataset-> fields-> fields [J ] ->

Visible) {currrow ; sh1.olepropertyget ("cells", currrow, 1) .olePropertySet ("Value", DataSet-> Fields-> Fields [J] -> FieldName); dataset-> first (); int i = 0 While (! Dataset-> eof) {Sh1.olePropertyget ("cells", currrow, i 2) .olepropertyset ("Value", DataSet-> Fields-> Fields [J] -> asstring); Application-> ProcessMessages (); Dataset-> next (); i ;}}}}} ex. ieproperty; screen-> cursor = crdefault;} // ------------- -------------------------------------------------- . IF (Slen

} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------- // ======================= ============================================================================================================================================================================================================= ==== // Function Instructions: When enter the table name, get the maximum value of all records, convert to n-bit 00001 form // Enter a table of a table in the CTABLENAME database // nnumkeep Format the characters String total length / / ============================================ ==================================================================================================================================================

AdoQuery1-> SQL-> CLEAR (); adoQuery1-> sql-> add ("select count (*) as curn from" ctable1-> prepared; adoquery1-> activ = true; adoquery1-> open () ; // showMessage (adoQuery1-> fields-> fields [0] -> asstring); int ngetn = adoquery1-> fieldbyname ("curn") -> asinteger; adoQuery1-> Active = false; adoquery1-> close (); Return Get00Str (ngetn 1, nnumkeep);

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------- Function: get00STR function: Generate 0000000x string input: ORAGN is converted with the total length of the string after formatting the string -------------------------------------------------- ---------------------- * / Ansistring __fastcall tMainform :: get00str (int oragn, int nnumkeep) {

Ansistring cc = INTOSTR (ORAGN); CC = cc.trim (); ANSISTRING TMP0 = ""; INT flen = cc.Length (); for (int J = 0; j

/ / =========================================================================================================================================================================================== ===============================

转载请注明原文地址:https://www.9cbs.com/read-46301.html

New Post(0)