// // INI-DEMO.VDM Ch.Ziemski 21.11.2002 // 24.11.2002 // // // Simple demo for using inifiles in your VEDIT macros. // // // Requires: The Windows version of VEDIT // INIFILE.VDM in a proper place (vedit\user-mac for example) // An example INI file as described below (and delivered together with this demo) // //-------- // // Remembers the date/time of last start. // // Reads the serial# from the VEDIT.INI and displays it in the dialog. // // And then uses the default INI-file INI-DEMO.INI in the current directory for some playing with. // // Example contents of this demo file: // // [Friends] // name1=Tim // name3=Willi // name2=Otto // [hobbies] // name1=Swimming // name3=Hiking // name2=Walking // [Age] // name1=51 // name3=12 // name2=21 // //---------------------------------------------------------------------------------- // // If you wish you can add a Call("ERROR-CHECK") after each Call_File(101, "INIFILE.VDM") // like shown in the first demo below. // Then there will be an error dialog upon parameter errors. // //---------------------------------------------------------------------------------- Reg_Empty(16) Reg_Empty(17) Reg_Empty(24) Reg_Empty(25) Reg_Empty(26) Reg_Empty(27) #27=-1 //----------- 1st demo: read/save the date and time of the last run in a central inifile ------------ Reg_Set(17, HOME) // prepare a register to hold the path to the central VED-MAC.INI Reg_Set(17, "\VED-MAC.INI", APPEND) Reg_Set(103, ^(READ_STR, "INIT-DEMO", "LastRun", 16, "initial", @17)^) // read the date of last run into T-Reg(16) Call_File(101, "INIFILE.VDM") Call("ERROR-CHECK") Out_Reg(106) // get the current date and time Date(NOMSG+NOCR) Message(" ") Time(NOMSG+NOCR) Out_Reg(CLEAR) Reg_Set(103, ^(WRITE_STR, "INIT-DEMO", "LastRun", @106, @17)^) // write the date of this run from T-Reg(106) Call_File(101, "INIFILE.VDM") // into the inifile Call("ERROR-CHECK") //--------------------------------------------------------------------------------------------------- //----------- 2nd demo: read VEDIT's serial number for displaying in the dialog ------------------- Reg_Set(18, HOME) // prepare a register to hold the path to the original VEDIT.INI Reg_Set(18, "\VEDIT.INI", APPEND) Reg_Set(103, ^(READ_STR, "AUTHENTICATION", "SerialNumber", 19, "xxx", @18)^) // read VEDIT's serial# into T-Reg(19) Call_File(101, "INIFILE.VDM") //----------- 3rd demo: dialog for modifying an example inifile ----------------------------------- // Reg_Set(15, "INI-DEMO.INI") // the filename for the demo ini-file // (searched in the current directory first, then USER_MACRO, MACRO, HOME) while(1==1){ Reg_Set(103, ^(READ_STR, "FRIENDS", "", 20, "", @15)^) // read all keys in section "Friends" Call_File(101, "INIFILE.VDM") if(Return_Value < 0){ Reg_Set(20, ">>> INI-FILE OR SECTION/KEY NOT FOUND <<< \n>>> it will be created upon [Write] <<<") } #80=Dialog_Input_1(24,"`VEDIT PLUS Serial#: |@(19)`, `This is a little demo application how to use INI-files.`, `It has been run the last time at: |@(16)`, `.c------------------`, ` Available keys in the section 'Friends':`, `.c|@(20)`, `??Choose a key:`, `[&Read]`,`[&Write]`,`[&Delete]`,`[Cancel]`, `.c------------------`, `??Name: `, `??Hobby:`, `??Age: `", SET+APP+CENTER,0,0) if(#80 == 0 || #80 == 4){ break // quit the macro via or [Cancel] } if(Reg_Size(24) == 0){ // if no section choosen Reg_Empty(25) // empty the display (from previous run) Reg_Empty(26) Reg_Empty(27) continue // and do noting in this loop } if(#80 == 1){ // READ Reg_Set(103, ^(READ_STR, "FRIENDS", @24, 25, "-unknown-", @15)^) Call_File(101, "INIFILE.VDM") Reg_Set(103, ^(READ_STR, "hobbies", @24, 26, "-none-", @15)^) Call_File(101, "INIFILE.VDM") Reg_Set(103, ^(READ_NUM, "Age", @24, 27, 0, @15)^) Call_File(101, "INIFILE.VDM") Num_Str(#27, 27, LEFT) // prepare for displaying } if(#80 == 2){ // WRITE Reg_Set(103, ^(WRITE_STR, "friends", @24, @25, @15)^) Call_File(101, "INIFILE.VDM") Reg_Set(103, ^(WRITE_STR, "hobbies", @24, @26, @15)^) Call_File(101, "INIFILE.VDM") #27=Num_Eval_Reg(27, SUPPRESS) // prepare for writing (in DI_1() it's a string) Reg_Set(103, ^(WRITE_NUM, "Age", @24, #27, @15)^) Call_File(101, "INIFILE.VDM") Reg_Set(103, ^(READ_NUM, "Age", @24, 27, 0, @15)^) // but read number again Call_File(101, "INIFILE.VDM") // it may have been written modified due // invalid characters (...) Num_Str(#27, 27, LEFT) // prepare for displaying } if(#80 == 3){ // DELETE Reg_Set(103, ^(DELETE, "friends", @24, @15)^) Call_File(101, "INIFILE.VDM") Reg_Set(103, ^(DELETE, "hobbies", @24, @15)^) Call_File(101, "INIFILE.VDM") Reg_Set(103, ^(DELETE, "Age", @24, @15)^) Call_File(101, "INIFILE.VDM") Reg_Empty(24) Reg_Empty(25) Reg_Empty(26) Reg_Empty(27) } } return //====================================================================================== :ERROR-CHECK: #104=Return_Value Num_Str(#104, 104, LEFT) if(#103 > 0){ Dialog_Input_1(1,"`Error`, `Parameter error at or after:`, `|@(103)`, `Return Code = |@(104)`", APP+CENTER,0,0) } return //======================================================================================