Sunday, 15 July 2012

Need help converting Graphics32 Delphi sample to C++ -



Need help converting Graphics32 Delphi sample to C++ -

using bds2006: i'm trying convert graphics32 resampler_ex illustration in c++, can't understand happens in codes, or how rewrite code in c++.

in sample there's combobox take resampler use: deplhi code in onchange event:

procedure tfmresamplersexample.kernelclassnameslistclick(sender: tobject); var index: integer; begin index := kernelclassnameslist.itemindex; if src.resampler tkernelresampler tkernelresampler(src.resampler) begin kernel := tcustomkernelclass(kernellist[index]).create; lbparameter.visible := (kernel talbrechtkernel) or {$ifdef ex} (kernel tgaussiankernel) or (kernel tkaiserbesselkernel) or (kernel tnutallkernel) or (kernel tburgesskernel) or (kernel tblackmanharriskernel) or (kernel tlawreykernel) or {$endif} (kernel tsinshkernel); gbparameter.visible := lbparameter.visible; setkernelparameter(kernel); curveimage.repaint; end; end;

where:

{ tclasslist } { class maintains list of classes. } tclasslist = class(tlist) protected function getitems(index: integer): tclass; procedure setitems(index: integer; aclass: tclass); public function add(aclass: tclass): integer; function extract(item: tclass): tclass; function remove(aclass: tclass): integer; function indexof(aclass: tclass): integer; function first: tclass; function last: tclass; function find(aclassname: string): tclass; procedure getclassnames(strings: tstrings); procedure insert(index: integer; aclass: tclass); property items[index: integer]: tclass read getitems write setitems; default; end; resamplerlist: tclasslist;

my problems on line

kernel := tcustomkernelclass(kernellist[index]).create;

how can convert line in c++?

edit after comments , anwers:

ok, seems beyond undertanding. purposes, suffice able replicate code without much hassle.

could possible instantiate right class using switch based on itemindex?

these 4 classes should instantiate:

class delphiclass tnearestresampler; class pascalimplementation tnearestresampler : public gr32::tcustomresampler { typedef gr32::tcustomresampler inherited; [...] } class delphiclass tlinearresampler; class pascalimplementation tlinearresampler : public gr32::tcustomresampler { typedef gr32::tcustomresampler inherited; [...] }; class delphiclass tdraftresampler; class pascalimplementation tdraftresampler : public tlinearresampler { typedef tlinearresampler inherited; [...] }; class delphiclass tkernelresampler; class pascalimplementation tkernelresampler : public gr32::tcustomresampler { typedef gr32::tcustomresampler inherited; [...] };

i don't ever how assign 1 of them "kernel"....

the delphi code relies on delphi virtual constructors. functionality not exist in c++.

if wanted translate code literally you'd need find way instantiate class calling virtual delphi constructor. cannot in c++ you'd need delphi code glue together. remy's reply here shows how utilize __classid() obtain delphi metaclass. you'd need pass metaclass delphi function perform instantiation.

frankly view beingness rather convoluted solution problem. instead think i'd replace class list function list. functions in list have task of instantiating new instance of kernel. instead of adding class list, add together function creates new instance of class. in fact might want map between name , function, depends on needs.

c++ delphi metaclass graphics32

No comments:

Post a Comment