Saturday 15 June 2013

class - How to create properties of classes within classes? -



class - How to create properties of classes within classes? -

for delphi xe6, creating class called taccountsearch. has little number of properties, , class of tobjectlist. issue cannot seem create tobjectlist class exposed property.

code snippet... create class utilize tobjectlist

type tsearchhits = class id: integer; name : string; ... end;

now create class contains instance of tobjectlist...

type taccountsearch = class private zsearchphrase: string; zlist: tobjectlist<tsearchhits>; ... property searchphrase: string read zsearchphrase; property mylist:tobjectlist<tsearchhits> read tobjectlist<tsearchhits>; end;

taccountsearch.searchphrase valid property. taccountsearch.mylist not.... accountsearch class, how give calling programme access searchhits property? second, if don't include write definition on property line, property considered read only. accurate? proper way create read properties?

you access instance variable zlist in order gain access internal storage:

property mylist: tobjectlist<tsearchhits> read zlist write zlist;

use write setmylist if need setter procedure.

you can utilize getter function gain access:

private function getmylist: tobjectlist<tsearchhits>; published property mylist: tobjectlist<tsearchhits> read getmylist write setmylist;

where getter function written like

function taccountsearch.getmylist: tobjectlist<tsearchhits>; begin result := zlist; end;

the way implement read-only properties omit write portion.

property mylist: tobjectlist<tsearchhits> read zlist;

class delphi properties tobjectlist

No comments:

Post a Comment