Jump to content
shadowrecon

TForms Storing Data and Loading Data

Recommended Posts

I have successfully made a few forms now, but they require you to enter the data data each time is there a way to write an ini fine and recall this data into the from? please be descriptive with reply, I understand how to get data and read it in the script but the question is how to read data in the from from a file and load it up or saving the data would be as simple as onclick := @SaveData; then have a save data function write all the data to the ini? something like that. the real question how do u load it!

Link to comment
Share on other sites

I gave you the tutorial this morning to read with that exact section in it, directly for that reason...

 

 

im looking for ideas =p the tut was nice but i just like to gather ideas before jumping into something as thats going to take a while to do.

 

---------- Post added at 05:21 AM ---------- Previous post was at 05:20 AM ----------

 

You could use [wiki=SaveSetting]SaveSetting[/wiki], it saves the setting to a special settings file for scripts on the PC.[/QUOT

Thanks ill look into that.

Link to comment
Share on other sites

well after messing around with the savesettings and delete settings i figured it out, basically like a ini file, or structured the same, this si what i came up with for my tform sfor saving and retrieving the data is there a more effective way to do it other than this?

procedure SaveButton(sender: TObject);
begin
// Global Settings
 SaveSetting('BreakConfig','BreakTime', IntToStr(BreakTimeMin.Position));
 SaveSetting('BreakConfig','BreakWhen', IntToStr(BreakAfterHrs.Position));
 SaveSetting('BreakConfig','UseBreaksYes', BoolToStr(UbYes.Checked));
 SaveSetting('BreakConfig','UseRBreaksNo', BoolToStr(RBreakNo.Checked));
 SaveSetting('BreakConfig','UseRBreaksYes', BoolToStr(RBreakYes.Checked));
 SaveSetting('BreakConfig','UseBreaksNo', BoolToStr(UbNo.Checked));
 SaveSetting('AntiBan','TalkYes', BoolToStr(aTalk.Checked));
 SaveSetting('AntiBan','TalkNo', BoolToStr(dTalk.Checked));
// user 1
 SaveSetting('UserConfig', 'up1', BoolToStr(up1.checked));
 SaveSetting('UserConfig', 'un1', un1.text);
 SaveSetting('UserConfig', 'pw1', pw1.text);
 SaveSetting('UserConfig', 'bp1', bp1.text);
 SaveSetting('UserConfig', 'fworld1', BoolToStr(fw1.checked));
 SaveSetting('UserConfig', 'mworld1', BoolToStr(mw1.checked));
// user 2
 SaveSetting('UserConfig', 'up2', BoolToStr(up2.checked));
 SaveSetting('UserConfig', 'un2', un2.text);
 SaveSetting('UserConfig', 'pw2', pw2.text);
 SaveSetting('UserConfig', 'bp2', bp2.text);
 SaveSetting('UserConfig', 'fworld2', BoolToStr(fw2.checked));
 SaveSetting('UserConfig', 'mworld2', BoolToStr(mw2.checked));
// user 3
 SaveSetting('UserConfig', 'up3', BoolToStr(up3.checked));
 SaveSetting('UserConfig', 'un3', un3.text);
 SaveSetting('UserConfig', 'pw3', pw3.text);
 SaveSetting('UserConfig', 'bp3', bp3.text);
 SaveSetting('UserConfig', 'fworld3', BoolToStr(fw3.checked));
 SaveSetting('UserConfig', 'mworld3', BoolToStr(mw3.checked));
// user 4
 SaveSetting('UserConfig', 'up4', BoolToStr(up4.checked));
 SaveSetting('UserConfig', 'un4', un4.text);
 SaveSetting('UserConfig', 'pw4', pw4.text);
 SaveSetting('UserConfig', 'bp4', bp4.text);
 SaveSetting('UserConfig', 'fworld4', BoolToStr(fw4.checked));
 SaveSetting('UserConfig', 'mworld4', BoolToStr(mw4.checked));
// user 5
 SaveSetting('UserConfig', 'up5', BoolToStr(up5.checked));
 SaveSetting('UserConfig', 'un5', un5.text);
 SaveSetting('UserConfig', 'pw5', pw5.text);
 SaveSetting('UserConfig', 'bp5', bp5.text);
 SaveSetting('UserConfig', 'fworld5', BoolToStr(fw5.checked));
 SaveSetting('UserConfig', 'mworld5', BoolToStr(mw5.checked));
end;

Procedure LoadButton(sender: TObject);
begin
// Global Settings
 BreakTimeMin.Position := StrToInt(LoadSetting('BreakConfig','BreakTime'));
 BreakAfterHrs.Position := StrToInt(LoadSetting('BreakConfig','BreakWhen'));
 ubYes.Checked := StrToBool(LoadSetting('BreakConfig','UseBreaksYes'));
 ubNo.Checked := StrToBool(LoadSetting('BreakConfig','UseBreaksNo'));
 aTalk.Checked := StrToBool(LoadSetting('AntiBan','TalkYes'));
 dTalk.Checked := StrToBool(LoadSetting('AntiBan','TalkNo'));

// user 1
 up1.checked := StrToBool(LoadSetting('UserConfig', 'up1'));
 un1.text := LoadSetting('UserConfig', 'un1');
 pw1.text := LoadSetting('UserConfig', 'pw1');
 bp1.text := LoadSetting('UserConfig', 'bp1');
 fw1.checked := StrToBool(LoadSetting('UserConfig', 'fworld1'));
 mw1.checked := StrToBool(LoadSetting('UserConfig', 'mworld1'));
// user 2
 up2.checked := StrToBool(LoadSetting('UserConfig', 'up2'));
 un2.text := LoadSetting('UserConfig', 'un2');
 pw2.text := LoadSetting('UserConfig', 'pw2');
 bp2.text := LoadSetting('UserConfig', 'bp2');
 fw2.checked := StrToBool(LoadSetting('UserConfig', 'fworld2'));
 mw2.checked := StrToBool(LoadSetting('UserConfig', 'mworld2'));
// user 3
 up3.checked := StrToBool(LoadSetting('UserConfig', 'up3'));
 un3.text := LoadSetting('UserConfig', 'un3');
 pw3.text := LoadSetting('UserConfig', 'pw3');
 bp3.text := LoadSetting('UserConfig', 'bp3');
 fw3.checked := StrToBool(LoadSetting('UserConfig', 'fworld3'));
 mw3.checked := StrToBool(LoadSetting('UserConfig', 'mworld3'));
// user 4
 up4.checked := StrToBool(LoadSetting('UserConfig', 'up4'));
 un4.text := LoadSetting('UserConfig', 'un4');
 pw4.text := LoadSetting('UserConfig', 'pw4');
 bp4.text := LoadSetting('UserConfig', 'bp4');
 fw4.checked := StrToBool(LoadSetting('UserConfig', 'fworld4'));
 mw4.checked := StrToBool(LoadSetting('UserConfig', 'mworld4'));
// user 5
 up5.checked := StrToBool(LoadSetting('UserConfig', 'up5'));
 un5.text := LoadSetting('UserConfig', 'un5');
 pw5.text := LoadSetting('UserConfig', 'pw5');
 bp5.text := LoadSetting('UserConfig', 'bp5');
 fw5.checked := StrToBool(LoadSetting('UserConfig', 'fworld5'));
 mw5.checked := StrToBool(LoadSetting('UserConfig', 'mworld5'));
end;

Procedure DeleteButton1(sender: TObject);
begin
// user 1
 DeleteSetting('UserConfig', 'up1');
 DeleteSetting('UserConfig', 'un1');
 DeleteSetting('UserConfig', 'pw1');
 DeleteSetting('UserConfig', 'bp1');
 DeleteSetting('UserConfig', 'fworld1');
 DeleteSetting('UserConfig', 'mworld1');
 up1.checked := True;
 un1.text := '';
 pw1.text := '';
 bp1.text := '';
 fw1.checked := True;
 SaveSetting('UserConfig', 'up1', BoolToStr(up1.checked)); // this corrects problem if they try to reload settings, else it give an error about the booleans
 SaveSetting('UserConfig', 'fworld1', BoolToStr(fw1.checked));
 SaveSetting('UserConfig', 'mworld1', BoolToStr(mw1.checked));
end;
Procedure DeleteButton2(sender: TObject);
// user 2
begin
 DeleteSetting('UserConfig', 'up2');
 DeleteSetting('UserConfig', 'un2');
 DeleteSetting('UserConfig', 'pw2');
 DeleteSetting('UserConfig', 'bp2');
 DeleteSetting('UserConfig', 'fworld2');
 DeleteSetting('UserConfig', 'mworld2');
 up2.checked := False;
 un2.text := '';
 pw2.text := '';
 bp2.text := '';
 fw2.checked := True;
 SaveSetting('UserConfig', 'up2', BoolToStr(up2.checked));
 SaveSetting('UserConfig', 'fworld2', BoolToStr(fw2.checked));
 SaveSetting('UserConfig', 'mworld2', BoolToStr(mw2.checked));
end;
Procedure DeleteButton3(sender: TObject);
// user 3
begin
 DeleteSetting('UserConfig', 'up3');
 DeleteSetting('UserConfig', 'un3');
 DeleteSetting('UserConfig', 'pw3');
 DeleteSetting('UserConfig', 'bp3');
 DeleteSetting('UserConfig', 'fworld3');
 DeleteSetting('UserConfig', 'mworld3');
 up3.checked := False;
 un3.text := '';
 pw3.text := '';
 bp3.text := '';
 fw3.checked := True;
 SaveSetting('UserConfig', 'up3', BoolToStr(up3.checked));
 SaveSetting('UserConfig', 'fworld3', BoolToStr(fw3.checked));
 SaveSetting('UserConfig', 'mworld3', BoolToStr(mw3.checked));
end;
Procedure DeleteButton4(sender: TObject);
// user 4
begin
 DeleteSetting('UserConfig', 'up4');
 DeleteSetting('UserConfig', 'un4');
 DeleteSetting('UserConfig', 'pw4');
 DeleteSetting('UserConfig', 'bp4');
 DeleteSetting('UserConfig', 'fworld4');
 DeleteSetting('UserConfig', 'mworld4');
 up4.checked := False;
 un4.text := '';
 pw4.text := '';
 bp4.text := '';
 fw4.checked := True;
 SaveSetting('UserConfig', 'up4', BoolToStr(up4.checked));
 SaveSetting('UserConfig', 'fworld4', BoolToStr(fw4.checked));
 SaveSetting('UserConfig', 'mworld4', BoolToStr(mw4.checked));
end;
Procedure DeleteButton5(sender: TObject);
// user 5
begin
 DeleteSetting('UserConfig', 'up5');
 DeleteSetting('UserConfig', 'un5');
 DeleteSetting('UserConfig', 'pw5');
 DeleteSetting('UserConfig', 'bp5');
 DeleteSetting('UserConfig', 'fworld5');
 DeleteSetting('UserConfig', 'mworld5');
 up5.checked := False;
 un5.text := '';
 pw5.text := '';
 bp5.text := '';
 fw5.checked := True;
 SaveSetting('UserConfig', 'up5', BoolToStr(up5.checked));
 SaveSetting('UserConfig', 'fworld5', BoolToStr(fw5.checked));
 SaveSetting('UserConfig', 'mworld5', BoolToStr(mw5.checked));
end; 

Link to comment
Share on other sites

It's not at all like an ini file actually... The functions originally wrote to the registry, the values just represented a subkey, keyname and value, but currently the data is stored in an xml structured file. The functions haven't changed to retain backwards compatibility. It looks about right though.

Link to comment
Share on other sites

It's not at all like an ini file actually... The functions originally wrote to the registry, the values just represented a subkey, keyname and value, but currently the data is stored in an xml structured file. The functions haven't changed to retain backwards compatibility. It looks about right though.

i didnt mean structured as in the saving function wise, i meant the section and subkey naming, but thanks it seems to be working the way i want it to, i had to add a save to my delete or when i deleted a particular setting i got a error with a '' as a Boolean from a read somewhere, so i just deleted then saved an default value for the booleans it was expecting, which works, i guess.

Link to comment
Share on other sites

Actually, now that you mention it, it's probably best to give the section a name that identifies your script as other scripts can obviously use this as well. And then rename the keys to for example BreakConfig-BreakTime

oh i gotcha, are all settings stored within the same file on the computer? i also optimized the way i saved the data by eliminating alot of of the regular radiobuttons and doing radiobutton groups which took away quite a few lines of code. because as u can see i was reading each radiobutton. the itemindex works alot better,

 

speaking of which, when the form editor complies your code for scar, if you have the radio buttons set to a default value like itemindex :=2; so the 3rd item is checked, within the form editor, and u compile it to scar and export it, it places the itemindex value about the add.items, so its setting the value before the index is ever created, so when u run the form they dont show up as checked, if you move the itemindex :=2; below the add.items it works just fine and sets it to you default value. I dont know if this is a bug, or maybe im just doing it ass backwards.. lol

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...