PDA

View Full Version : need help with ini file "write and read error"


jackdaniels
04-22-2008, 09:32 AM
i have a tree object and i am trying to save the nodes in it to an ini file and load it on start...

Thanks in Advance

jackdaniels
04-22-2008, 03:35 PM
any help or idea :rolleyes

RizlaUK
04-22-2008, 06:12 PM
ok, there was many mistakes in that code, but i sorted it for you

Replace the below functions in your project

function AddFavorite()
Url = Web.GetURL("Web1");
UrlDialog = Dialog.Input("Add Favorite - Specify the adress", "Please enter the url of the website", Url, MB_ICONQUESTION);
NameDialog = Dialog.Input("Add Favorite - Enter a name", "Please enter the name of the favorite", "", MB_ICONQUESTION);
FavCount = Tree.GetChildCount("Favorites_Panel", "1");
FavNodeData = {};
FavNodeData.Text = NameDialog;
FavNodeData.Data = UrlDialog;
FavNodeData.Expanded = true;
FavNodeData.NodeIndex = 3.1;
FavNodeData.ImageIndex = 1;
FavNodeData.SelectedImageIndex = 1;
Tree.InsertNode("Favorites_Panel", (FavCount), FavNodeData);
end

function SaveFavorites()
FavCount = Tree.GetChildCount("Favorites_Panel", "0");
for node=1, FavCount do
FavDataTable = Tree.GetNode("Favorites_Panel", node);
Url = FavDataTable.Data
Name = FavDataTable.Text
if Url ~= "0" then -- dont save the root node or it will keep adding it
INIFile.SetValue("AutoPlay\\Docs\\favorites.ini", Name, "Url", Url);
end
end
end

function ReadAndInsertFavorites()
Favorites = INIFile.GetSectionNames("AutoPlay\\Docs\\favorites.ini");
if Favorites then
for index, sections in Favorites do
Url = INIFile.GetValue("AutoPlay\\Docs\\favorites.ini", sections, "Url");
FavCount = Tree.GetChildCount("Favorites_Panel", "1");
FavNodeData = {};
FavNodeData.Text = sections;
FavNodeData.Data = Url;
FavNodeData.Expanded = true;
FavNodeData.NodeIndex = FavCount+1;
FavNodeData.ImageIndex = 1;
FavNodeData.SelectedImageIndex = 1;
Tree.InsertNode("Favorites_Panel", (FavCount), FavNodeData);
end
end
end

-- test function
function OpenFavorite(sNodeIndex)
-- make sure nothing happens when the root node is clicked
if Tree.GetNode("Favorites_Panel", sNodeIndex).Data ~= "0" then
result = Dialog.Message("Notice", Tree.GetNode("Favorites_Panel", sNodeIndex).Data, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
end

move the call to "ReadAndInsertFavorites()" from page preload to page on show and set the tree root node data to 0

heres the apz showing it working

jackdaniels
04-23-2008, 01:51 AM
thanks alot RizlaUK :yes ... i have another problem with tree

i want to edit node in the tree... what am i doing wrong ???

function Edit()
SelFav = Tree.GetSelectedNode("Favorites_Panel");
FavDataTable = Tree.GetNode("Favorites_Panel", SelFav);
Url = FavDataTable.Data
Name = FavDataTable.Text
UrlDialog = Dialog.Input("Add Favorite - Specify the adress", "Please enter a new url for : " .. Url, Url, MB_ICONQUESTION);
NameDialog = Dialog.Input("Add Favorite - Enter a name", "Please enter the name for the favorite : " .. Name, "", MB_ICONQUESTION);
FavNodeData = {};
FavNodeData.Text = NameDialog;
FavNodeData.Data = UrlDialog;
FavNodeData.Expanded = true;
FavNodeData.NodeIndex = SelFav;
FavNodeData.ImageIndex = 8;
FavNodeData.SelectedImageIndex = 8;
Tree.SetNode("Favorites_Panel", SelFav, FavNodeData);
end