Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

IdIMAP41.mailboxlist to TTreeNode

Posted on 2003-12-10
4
735 Views
Last Modified: 2010-04-16
Hello, I would convert IdIMAP41 Mailboxlist with all mailboxes and sub mailboxes to a TTreenode, is there any way to do it?
example:  
mailbox1/sub1/sub2/test
mailbox1/sub1/test1
mailbox1
mailbox1/sub1/sub2/test3

to

- mailbox1
  - sub1
       - sub2
             test
             test3
        test1


0
Comment
Question by:k4hvd66
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9911818
a sample

i have simplfied your content as memo-content

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    TreeView1: TTreeView;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function splitstr(var astring : String; Delimiter : String) : String;
var
  p : Integer;
begin
  result := '';
  if AString <> '' then
  begin
    p := pos(Delimiter,AString);
    if p > 0 then
    begin
      result := copy(AString,1,p-1);
      AString := copy(AString,p+length(Delimiter),maxLongInt);
    end
    else
    begin
      result := AString;
      AString := '';
    end;
  end;
end;

Function SearchOrCreateNode(ATree : TTreeView; AParentNode : TTreeNode; ACaption : String) : TTreeNode;
var ANode : TTreeNode;
begin
  result := nil;
  if not assigned(AParentNode) then  //onRoot
  begin
    ANode := ATree.TopItem;
    while (assigned(ANode)) and (ACaption <> ANode.Text) do
      ANode := ANode.getNextSibling;
    if not assigned(ANode) then
      result := ATree.Items.Add(NIL,ACaption)
    else
      result := ANode;
  end
  else
  begin  //OnParent
    ANode := AParentNode.getFirstChild;
    while (assigned(ANode)) and (ACaption <> ANode.Text) do
      ANode := ANode.getNextSibling;
    if not assigned(ANode) then
      result := ATree.Items.AddChild(AParentNode,ACaption)
    else
      result := ANode;
  end;
end;




Procedure FillTree(ATree : TTreeView; AList : TStrings; ADelimiter : String);
var
  I : Integer;
  s, ssplit : string;
  CurrentNode : TTreeNode;
begin
  for i := 0 to AList.Count-1 do
  begin
    s := AList[i];
    CurrentNode := Nil;
    while s <> '' do
    begin
      ssplit := splitstr(s,ADelimiter);
      CurrentNode := SearchOrCreateNode(ATree,CurrentNode,ssplit);
    end;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  FillTree(TreeView1, memo1.Lines, '/');

end;

end.

meikl ;-)
0
 

Author Comment

by:k4hvd66
ID: 9912353
the problem is, I need to add all of this as a child from a TNode so I cannot fill the tree directly, is that possible to get all this in a Node?
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 190 total points
ID: 9912386
?

TTreeNode must have as Owner TTreeNodes
TTreeNodes must have as Owner TCustomTreeView

all you need is a TTreeview

meikl ;-)
0
 

Author Comment

by:k4hvd66
ID: 9914346
it works!!
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question