Solved

IdIMAP41.mailboxlist to TTreeNode

Posted on 2003-12-10
4
725 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now