Recent

Author Topic: Question about TreeView and ImageList  (Read 6282 times)

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Question about TreeView and ImageList
« on: January 08, 2015, 09:15:07 am »
When we create a form with a TreeView and edit content of TreeView in desing time, asigning images to TreeView from ImageList where this link betwen images and tree is stored? and if we savetofile the tree and newly loadfromfile images don´t restore association of images with tree items (same content and structure in this case). There is a way to save also index images in savetofile not only names with tab? or where this association is stored when form is saved?

Thanks.
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

ausdigi

  • Jr. Member
  • **
  • Posts: 52
  • Programmer
    • RNR
Re: Question about TreeView and ImageList
« Reply #1 on: January 29, 2015, 02:11:41 am »
The settings you change in the designer should be saved in the .lfm (Lazarus ForM) file. If they aren't there may be a bug.

However I'm not 100% sure I understand what you are doing so it would help if you attached a simple project and then the steps to reproduce the problem from there. I don't have Lazarus on this computer so I can't right now test what I think you are doing.
Win10/64: CT 5.7 32&64

LA.Center

  • Full Member
  • ***
  • Posts: 244
    • LA.Center
Re: Question about TreeView and ImageList
« Reply #2 on: April 21, 2015, 03:57:36 pm »
TreeView.SaveToFile simple saves the text to a file, when you use LoadFromFile it will only restore the text since imageIndex and SelectedIndex are not stored.

If you don't need your Tree content to be human readable I suggest that you save it in binary format like this:

Code: [Select]
procedure saveTreeToFile(filename: string);
var
  f: TFileStream;
begin
  f := TFileStream.Create('somefile', fmCreate);
  f.WriteComponent(treeview.Items);
  f.Free;
end;


procedure loadTreeFromFile(filename: string);
var
  f: TFileStream;
begin
  f := TFileStream.Create('somefile', fmOpenRead);
  f.ReadComponent(treeview.Items);
  f.Free;
end;

I have not tested above sample, you may have to adjust a bit, but this is the way to go if you want to save all information to a binary file.

make sure that you clear all items in the treeview before you load something.

Hope this helps

jma_sp

  • Full Member
  • ***
  • Posts: 150
  • El conocimiento si ocupa lugar.
Re: Question about TreeView and ImageList
« Reply #3 on: June 19, 2015, 03:01:07 pm »
OK plusplus, thanks, it helps to hide the information in simple text format, an enhancement to the program.

ausdigi, you are right, the images are stored in files when in design. I have looking the files contents.

What i have been tried is to assign images to the nodes in the treeview an runtime and use a source of information for select dinamicaly the image from previously stored imagelit1.

For this i was in the right direction but forget to associate treeview1 to imagelist1  :-X. Without it nothing happens.

I have assigned the images and used treeview1.beginupdate   treeview.endupdate treeview1.refresh  and treeview.repaint after assigning the images with
    nodo.ImageIndex  nodo.SelectedIndex  nodo.StateIndex

I´m creating a simple phone index in treewiew.

Regards.
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

 

TinyPortal © 2005-2018