delphi - Tvirtuaildrawtree how to place nodes in one row? -


this follow other question here.

as have been suggested in comment ask new question subject

i have been suggested draw different images in row . goal beginning insert nodes side side have been told cannot done vdt not made purpose . makes me sure there way because see online project doing using same vdt

here screen shot project

enter image description here

with using resource viewer pe explorer found data of form

    object vdt: tvirtualdrawtree       alignwithmargins = true       left = 5       top = 5       width = 457       height = 227       margins.left = 5       margins.top = 5       margins.right = 5       margins.bottom = 5       align = alclient       bevelinner = bvnone       bevelouter = bvnone       defaultnodeheight = 55       header.autosizeindex = 0       header.font.charset = default_charset       header.font.color = clwindowtext       header.font.height = -11       header.font.name = 'tahoma'       header.font.style = []       hotcursor = crhandpoint       taborder = 0       treeoptions.paintoptions = [tohidefocusrect, tohideselection, tohottrack, toshowbuttons, toshowdropmark, tothemeaware, touseblendedimages, toalwayshideselection, touseblendedselection]       treeoptions.selectionoptions = [toextendedfocus, tomiddleclickselect, torightclickselect]       onbeforecellpaint = vdtbeforecellpaint       ongetnodewidth = vdtgetnodewidth       onmouseup = vdtmouseup       explicitleft = 3       explicittop = 3       columns = <         item           position = 0           width = 54           widetext = '55'         end         item           position = 1           width = 54           widetext = '55'         end         item           position = 2           width = 54           widetext = '55'         end         item           position = 3           width = 54           widetext = '55'         end         item           position = 4           width = 54           widetext = '55'         end         item           position = 5           width = 54           widetext = '55'         end         item           position = 6           width = 54           widetext = '55'         end         item           position = 7           width = 54           widetext = '55'         end>     end   end 

so told self have use tviruaildrawtree same goal start create data

type   tanmiclass = class   private     fanmigraphic : tgifimage;    public     property anmigraphic: tgifimage read fanmigraphic write fanmigraphic;    public     constructor create;     destructor destroy; override;   end;  type   panimedata = ^tanimedata;    tanimedata = record     fobject: tanmiclass;   end; 

as thinking have create image object node because downloading image list url add them node following , following code downloading images stringlist desk load node tgifimage

for := 0 animationimages.count-1 begin animaturl := animationimages.strings[i];  uri := tiduri.create(animaturl); try imagename := uri.document; freeandnil(uri); end;  if (extractfileext(imagename) = '.gif') begin addanimation(animaturl); end; end;  procedure tform2.addanimation(aanimationurl: string); var anmiclass: tanmiclass; path: string; begin  vdtani.beginupdate; try anmiclass := tanmiclass.create;  path := aanimationurl;  if fileexists(path) begin anmiclass.anmigraphic.loadfromfile(path); anmiclass.anmigraphic.animate := true; anmiclass.anmigraphic.transparent := true; end;  addanmitovd(vdtani, nil, anmiclass);  vdtani.endupdate; end; 

and here how draw nodes inside vdt

procedure tform2.vdtanibeforecellpaint(sender: tbasevirtualtree;   targetcanvas: tcanvas; node: pvirtualnode; column: tcolumnindex;   cellpaintmode: tvtcellpaintmode; cellrect: trect; var contentrect: trect); var data: panimedata; newrect: trect; r: trect; begin // if not assigned(node) begin exit; end;  data := vdtani.getnodedata(node);  case column of  0 : begin newrect := contentrect; newrect.left := newrect.left +2; newrect.width := 55; newrect.height := 55; newrect.top := newrect.top + 2; newrect.bottom := newrect.bottom; targetcanvas.stretchdraw( newrect, data.fobject.anmigraphic); end;  end; end; 

but cannot arrange nodes same image show above

and seems not thing can made in onbeforecellpanit .

in other question tom brunberg suggested divide images 10 nodes if image added 80 , need 8 per row example, each having 8 images , each image displayed in own column. don't know how in coding or start .

issue of current code

unit unit1;  interface  uses   winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics,   vcl.controls, vcl.forms, vcl.dialogs, virtualtrees, gifimg, vcl.stdctrls,   vcl.grids, vcl.extctrls;   type   timageobjarr = array of tgifimage;   type   tanidataclass = class   imageobjarr: timageobjarr;   private     fanirefrence: string;     faniimage: tgifimage;   public     property anirefrence: string read fanirefrence write fanirefrence;     property aniimage: tgifimage read faniimage write faniimage;    public     constructor create;     destructor destroy; override;   end;  type panidata = ^tanidata;  tanidata = record fobject: tanidataclass; end;       type   tform1 = class(tform)     vdtani: tvirtualstringtree;     button1: tbutton;     button2: tbutton;     procedure button1click(sender: tobject);     procedure formshow(sender: tobject);     procedure formdestroy(sender: tobject);     procedure vdtanibeforecellpaint(sender: tbasevirtualtree;       targetcanvas: tcanvas; node: pvirtualnode; column: tcolumnindex;       cellpaintmode: tvtcellpaintmode; cellrect: trect; var contentrect: trect);     procedure formcreate(sender: tobject);     procedure vdtanifreenode(sender: tbasevirtualtree; node: pvirtualnode);     procedure vdtanigetnodedatasize(sender: tbasevirtualtree;       var nodedatasize: integer);   private     { private declarations }    imageobjarr: timageobjarr;  // main storage of images   public     { public declarations }       dimagelist : tstringlist;   end;  var   form1: tform1;  implementation  {$r *.dfm}  { tanidataclass }  constructor tanidataclass.create; begin faniimage := tgifimage.create; end;  destructor tanidataclass.destroy; begin faniimage.free;   inherited; end;  procedure tform1.button1click(sender: tobject); var   node: pvirtualnode;   data: panidata;   i, row, col: integer;   fn: string; begin    // load images main store imgarr setlength(imageobjarr, dimagelist.count);  := 0 dimagelist.count -1 begin fn := dimagelist[i]; imageobjarr[i] := tgifimage.create; imageobjarr[i].loadfromfile(fn); end;    // setup vdt nodes , assign images 8 in row   // hardcoded now. may want add dynamics   // varying window , image sizes   row := 0;   while row <= (dimagelist.count div 8)   begin     node := vdtani.addchild(nil);     data := vdtani.getnodedata(node);     setlength(data.fobject.imageobjarr, 8);     col := 0 7       data.fobject.imageobjarr[col] := imageobjarr[row * 8 + col];     inc(row);   end;  end;   procedure tform1.formcreate(sender: tobject); begin dimagelist :=  tstringlist.create; vdtani.nodedatasize := sizeof(tanidata); end;  procedure tform1.formdestroy(sender: tobject); begin if assigned(dimagelist) begin   freeandnil(dimagelist); end; end;  procedure tform1.formshow(sender: tobject); begin  dimagelist.add('1mm.gif'); dimagelist.add('2mm.gif'); dimagelist.add('3mm.gif'); dimagelist.add('4mm.gif'); dimagelist.add('5mm.gif'); dimagelist.add('6mm.gif');   end;  procedure tform1.vdtanibeforecellpaint(sender: tbasevirtualtree;   targetcanvas: tcanvas; node: pvirtualnode; column: tcolumnindex;   cellpaintmode: tvtcellpaintmode; cellrect: trect; var contentrect: trect); var   data: panidata; begin if not assigned(node) begin exit; end;    data := vdtani.getnodedata(node);   sender.nodeheight[node] := 54;   cellrect.height := 54;    targetcanvas.stretchdraw( cellrect, data.fobject.imageobjarr[column]); end;  procedure tform1.vdtanifreenode(sender: tbasevirtualtree; node: pvirtualnode); var data: panidata; begin data := vdtani.getnodedata(node); if assigned(data) data.fobject.free; end; procedure tform1.vdtanigetnodedatasize(sender: tbasevirtualtree;   var nodedatasize: integer); begin nodedatasize := sizeof(tanidata); end;  end. 

i got exception here @ following code added 6 images path string list try draw on each columns

row := 0;   while row <= (dimagelist.count div 2)   begin     node := vdtani.addchild(nil);     data := vdtani.getnodedata(node);     setlength(data.fobject.imageobjarr, 2);     col := 0 7       data.fobject.imageobjarr[col] := imageobjarr[row * 2 + col];     inc(row);   end; 

here's implementation of suggested.

type   timgarr = array of tbitmap;    tvdtdata = record     fobject: timgarr;   end;   pvdtdata = ^tvdtdata;    tform2 = class(tform)     vdt: tvirtualdrawtree;     ...   private     { private declarations }     imgarr: timgarr;  // main storage of images  implementation  procedure tform2.button1click(sender: tobject); var   node: pvirtualnode;   data: pvdtdata;   p: pointer;   i, row, col: integer;   fn: tfilename; begin   // load images main store imgarr   setlength(imgarr, 100);   := 0 99   begin     fn := format('c:\tmp\nums\%.2d.bmp',[i]);     imgarr[i] := tbitmap.create;     imgarr[i].loadfromfile(fn);   end;    // setup vdt nodes , assign images 8 in row   // hardcoded now. may want add dynamics   // varying window , image sizes   row := 0;   while row <= (100 div 8)   begin     node := vdt.addchild(nil);     p := node.getdata;     data := vdt.getnodedata(node);     // setlength(data.fobject, 8);     setlength(data.fobject, vdt.header.columns.count);     col := 0 7       data.fobject[col] := imgarr[row * 8 + col];     inc(row);   end; end;  procedure tform2.vdtbeforecellpaint(sender: tbasevirtualtree;   targetcanvas: tcanvas; node: pvirtualnode; column: tcolumnindex;   cellpaintmode: tvtcellpaintmode; cellrect: trect; var contentrect: trect); var   data: pvdtdata; begin   if not assigned(node) exit;    data := vdt.getnodedata(node);   sender.nodeheight[node] := 64;   cellrect.height := 64;    if assigned(data.fobject[column])     targetcanvas.stretchdraw( cellrect, data.fobject[column]); end; 

no warranty of not carrying errors.

and result

enter image description here

but seriously, others have pointed out, easier use tdrawgrid or tstringgrid. of course it's call.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -