Solved

IdIMAP41.mailboxlist to TTreeNode

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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