delphi - How to override loading a TImage from the object inspector (at run-time)? -
aplogies top posting. has buggged me years , need know answer. put 150 points bounty attract interest, increase right answer.
here need:
i use tms obejct inpsctor tms scripter pro allow users design form @ run-time. can assume derives standard delphi object inspector , adds little functionality 90% of calls inherited methods.
when click ellipsis next picture property of timage calls inherited method - don't know - allow me load picture. when have done so, not know file image loaded , want save same name in different directory.
- i prompt user file name, looks confusing him , plain sloppy.
- i find timage / tpicture descendant stores file name , allows me query it. can point out such foss component gets bounty.
- i derive tpicture , or timage , code myself, not change. can tell me how code gets the bounty. exactly, mean naming classes , methods.
thanks in advance help. 1 annoys me.
further my previous question, did not useful answer despite bounty, try rephrasing question.
basically, when user clicks ellipsis in object inspector, delphi opens file/open dialog. want replace handling own, can save image's path.
i have expected need derive class timage , override assign() function, in following code. however, when assign function never called. so, looks need override else, what?
unit my_image; interface uses classes, extctrls, jpeg, graphics; type tmy_image = class(timage) private fpicture : tpicture; protected procedure onchange(sender: tobject); public { public declarations } constructor create(aowner: tcomponent); override; procedure setpicture(picture : tpicture); procedure assign(source: tpersistent); override; published { published declarations - available in object inspector @ design-time } property picture : tpicture read fpicture write setpicture; end; // of class tmy_image() procedure register; implementation uses controls, dialogs; procedure register; begin registercomponents('standard', [tmy_image]); end; constructor tmy_image.create(aowner: tcomponent); begin inherited; // call parent create method hint := 'add image file|add image file'; // tooltip | status bar text autosize := true; // control resizes when contents change (new image loaded) height := 104; width := 104; fpicture := tpicture.create(); self.picture.bitmap.loadfromresourcename(hinstance, 'picture_poperty_bmp'); end; procedure tmy_image.onchange(sender: tobject); begin constraints.maxheight := picture.height; constraints.maxwidth := picture.width; self.height := picture.height; self.width := picture.width; end; procedure tmy_image.setpicture(picture : tpicture); begin messagedlg('tmy_image.setpicture', mtwarning, [mbok], 0); // never called end; procedure tmy_image.assign(source: tpersistent); begin messagedlg('tmy_image.assign', mtwarning, [mbok], 0); // never called end; end.
see if works:
[...] procedure tmy_image.picturechange(sender: tobject); begin showmessage('should work'); end; [...] constructor tmy_image.create(aowner: tcomponent); begin inherited; // call parent create method hint := 'add image file|add image file'; // tooltip | status bar text autosize := true; // control resizes when contents change (new image loaded) height := 104; width := 104; fpicture := tpicture.create(); fpicture.onchange := picturechange; /// <<<< self.picture.bitmap.loadfromresourcename(hinstance, 'picture_poperty_bmp'); end; [...]
god bless you!
Comments
Post a Comment