delphi xe8 - firemonkey add item to HorzScrollBox on the fly -
i have horizontal scroll box item on form.after run program json string include list of items must in horizontal scroll box .and must add them dynamically.
for example have :
after run program in ? area must a new image.
i found function : horzscrollbox1.addobject(); argument required this
i have 2 question:
1)how can add new object this?
2)can clone existing image , add @ end of list?
add object: there 2 ways - set parent property of children or execute addobject method of parent. parent property setter has checks, , call addobject. depending on control class, child object can added controls collection of control or content private field. not classes provide access field (in cases can use workaround, in question). horzscrollbox has field in public section.
so, if want clone existing image, must:
get existing image
contentofhorzscrollboxcreate new image , set properties
put new image horzscrollbox.
for example:
procedure tform2.btnaddimgclick(sender: tobject); function findlastimg: timage; var i: integer; tmpimage: timage; begin result:=nil; // search scroll box content "most right" image := 0 horzscrollbox1.content.controlscount-1 if horzscrollbox1.content.controls[i] timage begin tmpimage:=timage(horzscrollbox1.content.controls[i]); if not assigned(result) or (result.boundsrect.right < tmpimage.boundsrect.right) result:=tmpimage; end; end; function cloneimage(sourceimage: timage): timage; var newrect: trectf; begin result:=timage.create(sourceimage.owner); result.parent:=sourceimage.parent; // copy needed properties. assign not work timage... result.align:=sourceimage.align; result.opacity:=sourceimage.opacity; result.multiresbitmap.assign(sourceimage.multiresbitmap); // move new image newrect:= sourceimage.boundsrect; newrect.offset(newrect.width, 0); // move rect right. result.boundsrect:=newrect; end; begin cloneimage(findlastimg); end;
Comments
Post a Comment