Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Saving a TTreeView to a bitmap or text file

202 views
Skip to first unread message

TG

unread,
Aug 4, 2009, 1:13:57 AM8/4/09
to
I need to save a (potentially large sized) treeview to a bitmap
(prefered) or text file.

Default methods are not good enough.

treeview.paintto method only saves the visible area. I want to save
the entire view (including areas outside the visible area if the
treeview has scrollbars). This would be ideal as the graphical
version is much more compact than the text version.

treeview.savetofile saves the entire tree to a text file with nice
indenting, but it does not include lines between nodes. for example

A
B
D
C

and i would like ideally something like

A
+-----B
+-----D
|
C

Any ideas? Had a good hunt around and cannot find any solutions.

Thanks,
TG.

Maarten Wiltink

unread,
Aug 4, 2009, 1:30:12 AM8/4/09
to
"TG" <blah66...@gmail.com> wrote in message
news:679b85fd-07db-4580...@q40g2000prh.googlegroups.com...

> I need to save a (potentially large sized) treeview to a bitmap
> (prefered) or text file.
>
> Default methods are not good enough.
>
> treeview.paintto method only saves the visible area. I want to save
> the entire view (including areas outside the visible area if the
> treeview has scrollbars). This would be ideal as the graphical
> version is much more compact than the text version.

In what way? (This is a _very_ odd-sounding statement.)


> treeview.savetofile saves the entire tree to a text file with nice
> indenting, but it does not include lines between nodes. for example
>
> A
> B
> D
> C
>
> and i would like ideally something like
>
> A
> +-----B
> +-----D
> |
> C
>
> Any ideas? Had a good hunt around and cannot find any solutions.

Write your own function. Recursive, and one of the parameters is
a string containing the vertical lines as they should be printed
before the current nesting depth.

Groetjes,
Maarten Wiltink


Maarten Wiltink

unread,
Aug 4, 2009, 1:33:14 AM8/4/09
to
"TG" <blah66...@gmail.com> wrote in message
news:679b85fd-07db-4580...@q40g2000prh.googlegroups.com...

> I need to save a (potentially large sized) treeview to a bitmap
> (prefered) or text file.
[...]


> Any ideas? Had a good hunt around and cannot find any solutions.

An alternative method would be to dump the treenodes to an XML file
and run them through a script I found once named ascii-treeview.xslt.
Of course, that's a very long way around for something that should
be relatively simple.

Groetjes,
Maarten Wiltink


TG

unread,
Aug 4, 2009, 1:37:50 AM8/4/09
to
On Aug 4, 3:30 pm, "Maarten Wiltink" <maar...@kittensandcats.net>
wrote:
> "TG" <blah666123...@gmail.com> wrote in message

>
> news:679b85fd-07db-4580...@q40g2000prh.googlegroups.com...
>
> > I need to save a (potentially large sized) treeview to a bitmap
> > (prefered) or text file.
>
> > Default methods are not good enough.
>
> > treeview.paintto method only saves the visible area.  I want to save
> > the entire view (including areas outside the visible area if the
> > treeview has scrollbars).  This would be ideal as the graphical
> > version is much more compact than the text version.
>
> In what way? (This is a _very_ odd-sounding statement.)
>

As in if you look at a treeview graphically on screen the screen real-
estate it takes up is much smaller that the same thing exported to a
text file and viewed in notepad.

>
>
> > treeview.savetofile saves the entire tree to a text file with nice
> > indenting, but it does not include lines between nodes.  for example
>
> > A
> >       B
> >             D
> >       C
>
> > and i would like ideally something like
>
> > A
> > +-----B
> >        +-----D
> >        |
> >        C
>
> > Any ideas?  Had a good hunt around and cannot find any solutions.
>
> Write your own function. Recursive, and one of the parameters is
> a string containing the vertical lines as they should be printed
> before the current nesting depth.
>

Looks like this may be the way to go. I was hoping someone had
already done it before I had to go revisit recursive tree handling
code.

Thanks,
TG

> Groetjes,
> Maarten Wiltink

Maarten Wiltink

unread,
Aug 4, 2009, 4:56:32 AM8/4/09
to
"TG" <blah66...@gmail.com> wrote in message
news:442923b0-5e52-4f34...@v37g2000prg.googlegroups.com...

> On Aug 4, 3:30 pm, "Maarten Wiltink" <maar...@kittensandcats.net>
> wrote:
>> "TG" <blah666123...@gmail.com> wrote in message
>> news:679b85fd-07db-4580...@q40g2000prh.googlegroups.com...

>>> I need to save a (potentially large sized) treeview to a bitmap

>>> (prefered) or text file. [...] the graphical


>>> version is much more compact than the text version.
>>
>> In what way? (This is a _very_ odd-sounding statement.)
>
> As in if you look at a treeview graphically on screen the screen real-
> estate it takes up is much smaller that the same thing exported to a
> text file and viewed in notepad.

You do realise that you can change the font Notepad uses?

Groetjes,
Maarten Wiltink


BRoberts

unread,
Aug 4, 2009, 8:17:44 PM8/4/09
to
"TG" <blah66...@gmail.com> wrote in message
news:679b85fd-07db-4580...@q40g2000prh.googlegroups.com...

>I need to save a (potentially large sized) treeview to a bitmap
> (prefered) or text file.
>
> Default methods are not good enough.
>
> treeview.paintto method only saves the visible area. I want to save
> the entire view (including areas outside the visible area if the
> treeview has scrollbars). This would be ideal as the graphical
> version is much more compact than the text version.


I don't see how a graphical representation, especially a bitmap, would be
more compact.

You might be able to use the export tree routines. But it's probably simpler
to simply write your own traversal & write logic.


alang...@aol.com

unread,
Aug 5, 2009, 5:24:26 AM8/5/09
to
On 4 Aug, 06:37, TG <blah666123...@gmail.com> wrote:
<snip>

> Looks like this may be the way to go. �I was hoping someone had
> already done it before I had to go revisit recursive tree handling
> code.

Outline code from some development stuff . . .

procedure TForm1.SaveBtnClick(Sender: TObject);
var
FS : TFileStream;
TN : TTreeNode;
begin
FS := TFileStream.Create('C:\TreeView.dat', fmOpenWrite);
with TreeView1 do begin
TN := Items.GetFirstNode;
while TN <> nil do begin
SaveNode(TN, FS);
TN.GetNextSibling;
end;
end;
FS.Free;
end;

function TForm1.SaveNode(TN : TTreeNode; Stream : TStream);
var
TNNext : TTreeNode;
begin
with Stream do begin
WriteStreamInt(TN.Count);
WriteStreamStr(TN.Text);
if TN.HasChildren then begin
TNNext := TN.GetFirstChild;
SaveNode(TNNext, Stream);
end
else begin
TNNext := TN.GetNextSibling;
repeat
SaveNode(TNNext, Stream);
TNNext := TN.GetNextSibling;
until TNNext = nil;
end;
end;
end;

Alan Lloyd

TG

unread,
Aug 27, 2009, 7:33:22 AM8/27/09
to
On Aug 5, 10:17 am, "BRoberts" <berdontem...@caneris.ca> wrote:
> "TG" <blah666123...@gmail.com> wrote in message

OK, to clarify.

Imagine a treeview that with scrollbars takes up 400x400 pixels. With
scroll bars the actual total size of the entire treeview may be
1000x1000 pixels in size (as an image).

The default font size for a treeview is much more compact that
exporting the treeview as text. Yes, you can save the treeview as a
text file and shrink the font in notepad, but my ideal solution would
be to save the full graphical treeview to a bitmap even if the
treeview with scrolling is 10000x5000 pixels in size. Then I do not
have to parse the treeview as text and add my own versions of the
branches, like

A
|
B-C
| |
| +-D
| |
E F

etc...

I am not talking about disk space that a txt version of treeview saves
more bytes than a bitmap view saved. I mean the visual screen space
each option takes up.

There must be a clever way to get this working?

TG

Maarten Wiltink

unread,
Aug 27, 2009, 8:10:24 AM8/27/09
to
"TG" <blah66...@gmail.com> wrote in message
news:308f3e1c-d639-49ee...@y10g2000prf.googlegroups.com...
[...]

> I am not talking about disk space that a txt version of treeview saves
> more bytes than a bitmap view saved. I mean the visual screen space
> each option takes up.

Have you tried saving to any format at all and loading the data back
into a treeview as a viewer? That would seem to be easy and take up
the minimum visual space.

Groetjes,
Maarten Wiltink


0 new messages