whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews ¦  misc ¦  forum
 kylix ¦  tutorials ¦  online shop ¦  photos ¦  Add&Win Game

Tips (1565)

Database (91)
Files (139)
Forms (113)
Graphic (116)
IDE (21)
Indy (5)
Internet / LAN (133)
IntraWeb (0)
Kylix (10)
Math (77)
Misc (128)
Multimedia (46)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (246)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

25 Visitors Online


SwissDelphiCenter is a Borland Technology Partner
 
...add data manually to a tree view, from a Texteditor?
Autor: Carlos Borrero
[ Print tip ]  

Tip Rating (1):  
     


unit Unit1;

// Suppose you want to add data to a TTreeView object but
// you prefer to prepare your data from a word processor,
// for example MS WORD.
//
// The first thing you have to know is that the text related
// to each node is saved on standard text format on the file
// corresponding to the tree view. The text of each node is
// preceded by tab (#9) characters deppending on the level of
// the node. Nodes at root level don't have tab (#9) characters,
// nodes whose parent is at root level have one tab character
// preceding it's text, and so on.
// You have to add one tab (#9) for each level different than root.
// Nodes are each on one line.

// So, you create your file from MS WORD following the rules
// mentioned. A tipical document could be the following -long
// spaces correspond to tab (#9) characters-:
//
// Node 1
//      Node 1, 1
//      Node 1, 2
//      Node 1, 3
// Node 2
//      Node 2, 1
//      Node 2, 2
//              Node 2, 2, 1
//              Node 2, 2, 2
//      Node 2, 3
//
// Once you create your document you "save as" it with
// format "Only Text". This option generates a document
// with extension ".txt". In the example below the file is named
// "test.txt"
//
// Then you simply read your data with procedure "LoadFromFile".
//
// If you want to read the data again form MS WORD, you
// read the corresponding ".txt" file.
//
// YOU HAVE TO BE CAREFUL NOT TO ADD SPACES BETWEEN
// THE TAB CHARACTERS AND TEXT RELATED TO NODES.
// IF YOU DO, YOU WON'T BE ABLE READ YOUR DATA.


interface

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

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

var
  
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  
// The following procedure read the data created woth MS WORD
  
TreeView1.LoadFromFile('c:\test.txt');
end;

end.


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners