🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages Started by Michael.Ruehling Fri, 02 May 2008 11:20
GetPrivateProfilString()
#336
Author: Michael.Ruehling
Date: Fri, 02 May 2008 11:20
42 lines
2258 bytes
Hi,
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:

e.g.

[code]
 LPTSTR lpTemp;
 CHAR szBuffer[64];
 LPTSTR lpBuf =
(LPTSTR)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,0x7FFF);
 GetPrivateProfileSectionNames(lpBuf, 0x7FFF, "CDPLAYER.UNI");
 lpTemp = lpBuf;
 TTreeNode *cur;
 TreeView1->Items->Clear();
 TreeView1->Items->Add(NULL,"CDS");
 cur = TreeView1->Items->Item[0];
 while (*lpTemp)
       {
       GetPrivateProfileString(lpTemp,"Artist","Nicht
gefunden",szBuffer,sizeof(szBuffer),"CDPLAYER.UNI");
       TreeView1->Items->Add(cur,szBuffer);
       cur = TreeView1->Items->Item[1];
       GetPrivateProfileString(lpTemp,"Title","Nicht
gefunden",szBuffer,sizeof(szBuffer),"CDPLAYER.UNI");
       TreeView1->Items->AddChild(cur,szBuffer);
       cur = TreeView1->Items->Item[0];
//       TreeView1->Items->Add(cur,"Hallo");
       lpTemp += lstrlen(lpTemp)+1;
       }
 HeapFree(GetProcessHeap(),0,lpBuf);
 TreeView1->AlphaSort();
}

Level 1 nodes are created perfectly and level 2 Nodes 

are createdt perfectly but are stored under the wrong 
head-Nodes. Why? can anyone help?


M.
Re: GetPrivateProfilString()
#338
Author: Bob Gonder
Date: Fri, 02 May 2008 15:33
22 lines
1622 bytes
Michael.Ruehling@t-online.de wrote:

> while (*lpTemp)
>       {
>	 cur = TreeView1->Items->Item[0];
>       TreeView1->Items->Add(cur,szBuffer);
>       cur = TreeView1->Items->Item[1];
>       TreeView1->Items->AddChild(cur,szBuffer);
>       }
> TreeView1->AlphaSort();
>}
>
>Level 1 nodes are created perfectly and level 2 Nodes 
>are createdt perfectly but are stored under the wrong 
>head-Nodes. Why? can anyone help?

You are adding to node cur. Cur is always 0 or 1.
You want to AddChild to the last Add node:

	cur = TreeView1->Items->Item[0];
	cur = TreeView1->Items->Add(cur,szBuffer);
	TreeView1->Items->AddChild(cur,szBuffer);
Re: GetPrivateProfilString()
#339
Author: Remy Lebeau (TeamB)
Date: Fri, 02 May 2008 16:37
93 lines
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 
Re: GetPrivateProfilString()
#341
Author: Michael.Ruehling
Date: Fri, 02 May 2008 21:25
31 lines
1844 bytes
Hi,
I will try this at once.


M.
On Fri, 02 May 2008 08:33:21 -0700, Bob Gonder
<notbg@notmindspring.invalid> wrote:

>Michael.Ruehling@t-online.de wrote:
>
>> while (*lpTemp)
>>       {
>>	 cur = TreeView1->Items->Item[0];
>>       TreeView1->Items->Add(cur,szBuffer);
>>       cur = TreeView1->Items->Item[1];
>>       TreeView1->Items->AddChild(cur,szBuffer);
>>       }
>> TreeView1->AlphaSort();
>>}
>>
>>Level 1 nodes are created perfectly and level 2 Nodes 
>>are createdt perfectly but are stored under the wrong 
>>head-Nodes. Why? can anyone help?
>
>You are adding to node cur. Cur is always 0 or 1.
>You want to AddChild to the last Add node:
>
>	cur = TreeView1->Items->Item[0];
>	cur = TreeView1->Items->Add(cur,szBuffer);
>	TreeView1->Items->AddChild(cur,szBuffer);
>
Re: GetPrivateProfilString()
#343
Author: Michael.Ruehling
Date: Mon, 05 May 2008 03:08
42 lines
2235 bytes
Hi,
tried this and it works fine for me. 
So this ist stage 1. 
Next stage will be the sorted output.

Thanks
M.

On Fri, 02 May 2008 23:25:45 +0200, Michael.Ruehling@t-online.de
wrote:

>Hi,
>I will try this at once.
>
>
>M.
>On Fri, 02 May 2008 08:33:21 -0700, Bob Gonder
><notbg@notmindspring.invalid> wrote:
>
>>Michael.Ruehling@t-online.de wrote:
>>
>>> while (*lpTemp)
>>>       {
>>>	 cur = TreeView1->Items->Item[0];
>>>       TreeView1->Items->Add(cur,szBuffer);
>>>       cur = TreeView1->Items->Item[1];
>>>       TreeView1->Items->AddChild(cur,szBuffer);
>>>       }
>>> TreeView1->AlphaSort();
>>>}
>>>
>>>Level 1 nodes are created perfectly and level 2 Nodes 
>>>are createdt perfectly but are stored under the wrong 
>>>head-Nodes. Why? can anyone help?
>>
>>You are adding to node cur. Cur is always 0 or 1.
>>You want to AddChild to the last Add node:
>>
>>	cur = TreeView1->Items->Item[0];
>>	cur = TreeView1->Items->Add(cur,szBuffer);
>>	TreeView1->Items->AddChild(cur,szBuffer);
>>
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads