mixster
02-23-2008, 10:21 PM
After starting my script a while back, I dived into the uses of creating INI files to store data, thus the ExportUsers and ImportUsers was forged. It's very simple and should be easy to see how it works. You may need to tweak a couple of things depending on how your form works, but otherwise it *should* work straight oput the box. Also, you can change the filename it saves it as (I would recommend making it a const, but I just had it in like this because I was too lazy to scroll up when scripting it). To use it, just plop it in then make an export and import button, then direct them to the appropriate procedure.
Procedure ExportUsers(Sender: TObject);
Var
i: Integer;
Begin
For i:= 0 To GetArrayLength(Players) - 1 Do
Begin
WriteINI('Player' + IntToStr(i), 'Username', Players[i].Name, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Password', Players[i].Pass, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Nickname', Players[i].Nick, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Active', BoolToStr(Players[i].Active), ScriptPath + 'sUsers.ini');
End;
End;
Procedure ImportUsers(Sender: TObject);
Var
i,ii: Integer;
Begin
While(Not(ReadINI('Player' + IntToStr(i), 'Username', ScriptPath + 'sUsers.ini') = '') and (i < 50)) Do
Inc(i);
Dec(i);
SetArrayLength(Players,i+1);
For ii:= 0 to i do
Begin
Players[ii].Name:= ReadINI('Player' + IntToStr(ii), 'Username', ScriptPath + 'sUsers.ini');
Players[ii].Pass:= ReadINI('Player' + IntToStr(ii), 'Password', ScriptPath + 'sUsers.ini');
Players[ii].Nick:= ReadINI('Player' + IntToStr(ii), 'Nickname' ,ScriptPath + 'sUsers.ini');
Players[ii].Active:= StrToBool(ReadINI('Player' + IntToStr(ii), 'Active', ScriptPath + 'sUsers.ini'));
End;
FCurPla:= 0;
edName.Text:= Players[FCurPla].Name;
edPass.Text:= Players[FCurPla].Pass;
edNick.Text:= Players[FCurPla].Nick;
cbActive.Text:= BoolToStr(Players[FCurPla].Active);
End;
Note: This was before the end of my over-capitalizing phase, so lots of capitals, yay!
Procedure ExportUsers(Sender: TObject);
Var
i: Integer;
Begin
For i:= 0 To GetArrayLength(Players) - 1 Do
Begin
WriteINI('Player' + IntToStr(i), 'Username', Players[i].Name, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Password', Players[i].Pass, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Nickname', Players[i].Nick, ScriptPath + 'sUsers.ini');
WriteINI('Player' + IntToStr(i), 'Active', BoolToStr(Players[i].Active), ScriptPath + 'sUsers.ini');
End;
End;
Procedure ImportUsers(Sender: TObject);
Var
i,ii: Integer;
Begin
While(Not(ReadINI('Player' + IntToStr(i), 'Username', ScriptPath + 'sUsers.ini') = '') and (i < 50)) Do
Inc(i);
Dec(i);
SetArrayLength(Players,i+1);
For ii:= 0 to i do
Begin
Players[ii].Name:= ReadINI('Player' + IntToStr(ii), 'Username', ScriptPath + 'sUsers.ini');
Players[ii].Pass:= ReadINI('Player' + IntToStr(ii), 'Password', ScriptPath + 'sUsers.ini');
Players[ii].Nick:= ReadINI('Player' + IntToStr(ii), 'Nickname' ,ScriptPath + 'sUsers.ini');
Players[ii].Active:= StrToBool(ReadINI('Player' + IntToStr(ii), 'Active', ScriptPath + 'sUsers.ini'));
End;
FCurPla:= 0;
edName.Text:= Players[FCurPla].Name;
edPass.Text:= Players[FCurPla].Pass;
edNick.Text:= Players[FCurPla].Nick;
cbActive.Text:= BoolToStr(Players[FCurPla].Active);
End;
Note: This was before the end of my over-capitalizing phase, so lots of capitals, yay!