Article View: borland.public.cppbuilder.nativeapi
Article #339Re: GetPrivateProfilString()
From: Remy Lebeau (TeamB)
Date: Fri, 02 May 2008 16:37
Date: Fri, 02 May 2008 16:37
93 lines
3609 bytes
3609 bytes
<Michael.Ruehling@t-online.de> 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 <IniFiles.hpp>
#include <memory>
std::auto_ptr<TIniFile> Ini(new TIniFile("CDPLAYER.UNI"));
TreeView1->Items->BeginUpdate();
try
{
TreeView1->Items->Clear();
std::auto_ptr<TStringList> 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
Technical Details
Message-ID:
<481b435b$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news2.arglkargh.de!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41ul1411o0gb2tnl2dhigfmq95a1bgs165@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,7f46e08466844be8 X-Google-Attributes: gid10cc67,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <41ul1411o0gb2tnl2dhigfmq95a1bgs165@4ax.com> Subject: Re: GetPrivateProfilString() Date: Fri, 2 May 2008 09:37:23 -0700 Lines: 95 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <481b435b$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1209746267 207.178.157.90 (2 May 2008 09:37:47 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news2.arglkargh.de!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail