Re: GetPrivateProfilString()
  Home FAQ Contact Sign in
borland.public.cppbuilder.nativeapi only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: GetPrivateProfilString()         

Group: borland.public.cppbuilder.nativeapi · Group Profile
Author: Remy Lebeau (TeamB)
Date: May 2, 2008 09:37

wrote in message
news:41ul1411o0gb2tnl2dhigfmq95a1bgs165@4ax.com...
> I'm trying to read an Ini-file for an small helperApp. As fas as
> creating designing and stuff all works well, but when I#m trying to
> read the second level items, all are read in in a single Headnode:

Try this code instead:

TreeView1->Items->BeginUpdate();
try
{
TreeView1->Items->Clear();

LPTSTR lpBuf = (LPTSTR) LocalAlloc(LPTR, 0x7FFF);
if( lpBuf )
{
TTreeNode *RootNode = TreeView1->Items->Add(NULL, "CDS");
GetPrivateProfileSectionNames(lpBuf, 0x7FFF,
TEXT("CDPLAYER.UNI"));

LPTSTR lpTemp = lpBuf;
TCHAR szBuffer[64];

while( *lpTemp )
{
if( GetPrivateProfileString(lpTemp, TEXT("Artist"),
TEXT("Nicht gefunden"), szBuffer, sizeof(szBuffer), TEXT("CDPLAYER.UNI")) )
{
TTreeNode *ArtistNode =
TreeView1->Items->AddChild(RootNode, szBuffer);
if( GetPrivateProfileString(lpTemp, TEXT("Title"),
TEXT("Nicht gefunden"), szBuffer, sizeof(szBuffer), TEXT("CDPLAYER.UNI")) )
TreeView1->Items->AddChild(ArtistNode, szBuffer);
}

lpTemp += lstrlen(lpTemp)+1;
}

LocalFree(lpBuf);
TreeView1->AlphaSort();
}
}
__finally
{
TreeView1->Items->EndUpdate();
}

Alternatively, since you are using the VCL anyway:

#include
#include

std::auto_ptr Ini(new TIniFile("CDPLAYER.UNI"));

TreeView1->Items->BeginUpdate();
try
{
TreeView1->Items->Clear();

std::auto_ptr Sections(new TStringList);
Ini->ReadSections(Sections.get());

TTreeNode *RootNode = TreeView1->Items->Add(NULL, "CDS");
for(int i = 0; i < Sections->Count; ++i)
{
AnsiString tmp = Ini->ReadString(Sections->Strings[i], "Artist",
"Nicht gefunden");
TTreeNode *ArtistNode = TreeView1->Items->AddChild(RootNode,
tmp);

tmp = Ini->ReadString(Sections->Strings[i], "Title", "Nicht
gefunden");
TreeView1->Items->AddChild(ArtistNode, tmp);
}

TreeView1->AlphaSort();
}
__finally
{
TreeView1->Items->EndUpdate();
}
> are createdt perfectly but are stored under the wrong
> head-Nodes. Why?

Because you are calling Add() instead of AddChild() when adding each artist
node.

Gambit
no comments
diggit! del.icio.us! reddit!