Solved

IdIMAP41.mailboxlist to TTreeNode

Posted on 2003-12-10
4
738 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Graphics32 under Delphi 10.1 Berlin 2 170
Microsoft Access 97 and Delphi XE2 9 83
delphi popmenu non latine charcters 3 44
TAction.OnAfterExecute? 2 30
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…

738 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