SRL Archive - Help and Support

saving information


Camaro'

2008-05-24 15:22:24

Well, im making a form that has a menu and a sub menu , All is working fine. On the click i have it close the form then reload the form.

But everytime you do that, it erases any information that you could of inputted. My question is how do i save that information?

itSchRis917

2008-05-24 16:32:11

Write that information to an ini file and then load that information from the ini file into the text box upon re-opening.

Negaal

2008-05-24 16:32:53

Link in my signature, about INI's

Edit: … chris was faster

itSchRis917

2008-05-24 16:36:10

:p Negaal. Or you could just do writing to files in general, that would be more secure.. You write it to a .dat file and it is that much harder to read…

Negaal

2008-05-24 16:45:22

Choose program to open with –> notepad?

Yay. Data should be encrypted by you not file extension..no offence.

mixster

2008-05-24 16:47:49

If in doubt, you can always just parse passwords through with a MD5hash but I doubt anyone would look in it anyway. Not to mention I would recommend an ini over writing files as it's much easier to access and write to etc.

itSchRis917

2008-05-24 16:50:36

Lol, i had no idea you could do that Negaal…

R0b0t1

2008-05-24 17:24:04

I use bitmaps in one of my private scripts. It seems to be faster for integers.

Camaro'

2008-05-25 09:59:35

From: Negaal
Choose program to open with –> notepad?

Yay. Data should be encrypted by you not file extension..no offence.


it works like a charm , but everytime i try to load it its say scars trying to connect to the file, im saving it to the script path..

and how would i go about saving if a check box is checked..

R0b0t1

2008-05-25 12:52:05

Any file you access is caught, no matter where.



if (CheckBox1.checked) then //I can't remember true thingy

R0b0t1

2008-05-25 12:53:37

Any file you access is caught, no matter where.



if (CheckBox1.checked) then //I can't remember true thingy

itSchRis917

2008-05-25 15:33:46

I think something like this would work…


Players[CurrentPlayer].Active := Active.Checked;
for f:= 0 to HowManyPlayers - 1 do
WriteFileString(charsfile, 'active' + IntToStr(f) + '=' + BoolToStr(players[f].active) + Chr(13))

R0b0t1

2008-05-25 17:18:06

But he wants to be able to programmatically read it too.

itSchRis917

2008-05-25 18:10:15

ReadFileString R0b0t1…. or he can just do WriteIni and do the same thing..

Camaro'

2008-05-25 19:05:50

From: itschris917
ReadFileString R0b0t1…. or he can just do WriteIni and do the same thing..


Thanks guys..

R0b0t1

2008-05-25 19:57:52

itschris917, you kinda don't get it.

I meant he should use an INI, if he did it your way he'd have to create a text parser.



And writing INI's is different. It formats it for you, you tell it like 'ReadVar(Header, Sub, Name)' or something.

itSchRis917

2008-05-25 20:04:27

Not an intense string parser though.. Barely even one..

ReadFileString(CharsFile, CharsFileString, FileSize(CharsFile));
CloseFIle(CharsFile);
Temp := CountPlayers(CharsFileString);
If (Temp <= 0) then Temp:= 1;
SetArrayLength(players, Temp);
HowManyPlayers := GetArrayLength(players)
for f := 0 to HowManyPlayers - 1 do
begin
players[f].Name := Between('name' + IntToStr(f) + '=', chr(13), CharsFileString);
//do the same thing for the other options like password etc...
end;

R0b0t1

2008-05-25 20:12:38

But it is still more code than if he uses INI files, and it could be more if he wants to store integers or floats.

itSchRis917

2008-05-25 21:00:10

True true. I just used FileString because i used that in one of my scripts so i just copied and pasted.

Widget

2008-05-25 23:17:23

procedure SaveTheSettings(Sender:TObject);
var path:string;
i:integer;
begin
Path := AppPath+'WidgetSettings.ini';
WriteINI('Settings','StatsID',OtherEdits[1].Text,Path);
WriteINI('Settings','StatsPass',Encrypt(OtherEdits[2].Text),Path);
WriteINI('Settings','MouseSpeed',OtherEdits[3].Text,Path);
WriteINI('Settings','Loads',OtherEdits[4].Text,Path);
WriteINI('Settings','UsePouches',BoolToStr(Checks[1].Checked),Path);
WriteINI('Settings','AutoRespond',BoolToStr(Checks[2].Checked),Path);
WriteINI('Settings','Players',IntToStr(GetArrayLength(PlayerFormEdits[1])),Path);
for i := 0 to (GetArrayLength(PlayerFormEdits[1])-1) do
begin
WriteINI('Player'+inttostr(i),'User',PlayerFormEdits[1][i].Text,Path);
WriteINI('Player'+inttostr(i),'Pass',Encrypt(PlayerFormEdits[2][i].Text),Path);
WriteINI('Player'+inttostr(i),'Nick',PlayerFormEdits[3][i].Text,Path);
WriteINI('Player'+inttostr(i),'PIN',PlayerFormEdits[4][i].Text,Path);
end;
end;
procedure LoadTheSettings(Sender:TObject);
var path:string;
i:integer;
begin
Path := AppPath+'WidgetSettings.ini';
if not FileExists(path) then Exit;
OtherEdits[1].Text := ReadINI('Settings','StatsID',path);
OtherEdits[2].Text := Decrypt(ReadINI('Settings','StatsPass',path));
OtherEdits[3].Text := ReadINI('Settings','MouseSpeed',path);
OtherEdits[4].Text := ReadINI('Settings','Loads',path);
for i := 2 to GetArrayLength(PlayerFormEdits[1]) do
SafeDeletePlayer(Form);
for i := 0 to (StrToIntDef(ReadINI('Settings','Players',path),0)-1) do
begin
if (i>0) then
SafeAddPlayer(Form);
PlayerFormEdits[1][i].Text := ReadINI('Player'+inttostr(i),'User',path);
PlayerFormEdits[2][i].Text := Decrypt(ReadINI('Player'+inttostr(i),'Pass',path));
PlayerFormEdits[3][i].Text := ReadINI('Player'+inttostr(i),'Nick',path);
PlayerFormEdits[4][i].Text := ReadINI('Player'+inttostr(i),'PIN',path);
end;
Checks[1].Checked := StrToBoolDef(ReadINI('Settings','UsePouches',path),False);
Checks[2].Checked := StrToBoolDef(ReadINI('Settings','AutoRespond',path),False);
end;
That's what I do :)

Bam Bam

2008-05-26 06:44:16

SaveSetting and LoadSetting?

Widget

2008-05-26 12:19:31

No I mean like
  Path := AppPath+'WidgetSettings.ini';
WriteINI('Settings','StatsID',OtherEdits[1].Text,Path);
WriteINI('Settings','StatsPass',Encrypt(OtherEdits[2].Text),Path); // Encrypt is a seperate function I made
WriteINI('Settings','MouseSpeed',OtherEdits[3].Text,Path);
BoolToStr and StrToBool will let you use Checkbox.Checked in there too