delphi - Load database field of all records into ListView Item Detail Object -


using delphi xe8 i'm testing functionality firemonkey tlistviews.

one thing i'm trying load field of records tfdmemtable component listview item, detailobject of listview item.

for example, have 3 records in table (db field called 'name'):

record 1 = name 1   record 2 = name 2   record 3 = name 3   

there 1 detailobject property per listview item question is, able add of fields (name 1, name 2, name 3) 1 detailobject?

below i've attempted far no luck. not 100% sure need do.

procedure mainform.buildlist; var litem : tlistviewitem; begin   listview1.beginupdate;   try     listview1.clearitems;     litem := listview1.items.add;     litem.objects.detailobject.visible := true;     memtable     begin       while not eof       begin         litem.detail := fieldbyname('name').asstring;       end;     end;       listview1.endupdate;   end; end; 

i'm sorry if isn't clear enough, please let me know.

any great.

i think should warn before seeing q, i'd never done fmx listviews , master/detail datasets. following little rough around edges, , layout isn't ideal, shows 1 way populate listview master + detail datasets. have no idea whether there better ways. personally, see if use live bindings job.

procedure tmasterdetailform.buildlist; var   litem : tlistviewitem;   detailitem : tlistviewitem;   listitemtext : tlistitemtext;   detailindex : integer; begin   listview1.beginupdate;   listview1.itemappearanceobjects.itemeditobjects.text.textvertalign := ttextalign.leading;  // default    //  seems `center`, whereas want master field name @ top of item    try     listview1.items.clear; //items;     master.first;     while not master.eof begin       litem := listview1.items.add;       litem.text := master.fieldbyname('name').asstring;       litem.height := 25;        detail.first;       detailindex := 0;       while not detail.eof begin         inc(detailindex);         listitemtext := tlistitemtext.create(litem);         listitemtext.placeoffset.x := 100;         listitemtext.placeoffset.y := 25 * (detailindex - 1);         listitemtext.textalign := ttextalign.leading;         listitemtext.name := 'name' + inttostr(detailindex); //detail.fieldbyname('name').asstring;         litem.data['name' + inttostr(detailindex)] := detail.fieldbyname('name').asstring;         detail.next;       end;       litem.height := litem.height * (1 + detailindex);        master.next;     end;       listview1.endupdate;   end; end; 

tlistitemtext 1 of number of "drawable" fmx objects can added tlistviewitem. seem need unique names can accessed via names property.

fwiw, used 2 tclientdatasets master , detail in code.

also fwiw, fmx newbies me, populating fmx treeview lot more you'd in vcl project:

procedure tmasterdetailform.buildtree; var   pnode,   childnode : ttreeviewitem; begin   treeview1.beginupdate;   try     treeview1.clear;     master.first;     while not master.eof begin       pnode := ttreeviewitem.create(treeview1);       treeview1.addobject(pnode);       pnode.text := master.fieldbyname('name').asstring;        detail.first;       while not detail.eof begin         childnode := ttreeviewitem.create(treeview1);         childnode.text := detail.fieldbyname('name').asstring;         pnode.addobject(childnode);         detail.next;       end;       master.next;     end;       treeview1.endupdate;   end; end; 

btw, in code should have been calling

memtable.next; 

in while not eof loop, , memtable.first before loop.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -