delphi - How to access to a private variable used as by a property ( designTime package) from another unit (runtimepackage) -


in order create component, created designtime , runtime packages, runtime package (lets call rp140) contains code of component , requires rtl.dcp, designtime package (lets call dclrp140) contains register procedure , requires designide, runtime package , rtl.dcp. need access private variables declared in unit belongs "dclrp140" package, unit belongs "rp140", created simple code contains relevant part, make easier understand:

unit mycomponentregister;  interface  uses classes, mycomponent;  type   tevent = procedure(sender: tobject) of object;    tmycomponent = class(tcomponent)   private     fmyproperty: string;     fmyevent: tevent;   public     constructor create(aowner: tcomponent); override;   published     property myproperty: string read fmyproperty write fmyproperty       default initial_value;     property myevent: tevent read fmyevent write fmyevent;   end;  procedure register;  implementation  procedure register; begin   registercomponents('samples', [tmycomponent]); end;  constructor tmycomponent.create(aowner: tcomponent); begin   inherited;   fmyproperty := initial_value; end;  end. 

the other unit contains main code of component:

unit mycomponent;  interface  uses   sysutils, classes;  type   tmycomponent = class(tcomponent)   public     procedure myprocedure(avalue: string);   end;  implementation  procedure tmycomponent.myprocedure(avalue: string); begin   fmyproperty := avalue; // want access fmyproperty   if assigned(fmyevent) // want access fmyevent     // work end;  end. 

so first, have tell i'm new creating packages , components, doing right way? or there wrong?

second,as said before, want access private variables declared in 'mycomponentregister' 'mycomponent', tried many tricks none of them worked, sure there way that, cant find limited experience.so, how can solve one??

your problem trying define component in multiple places. that's not possible. code declares 2 distinct classes. that's 1 more need.

do so:

unit mycomponent;  interface  uses   classes;  type   tevent = procedure(sender: tobject) of object;    tmycomponent = class(tcomponent)   private     fmyproperty: string;     fmyevent: tevent;   public     constructor create(aowner: tcomponent); override;     procedure myprocedure(avalue: string);   published     property myproperty: string read fmyproperty write fmyproperty;     property myevent: tevent read fmyevent write fmyevent;   end;  implementation  constructor tmycomponent.create(aowner: tcomponent); begin   inherited; end;  procedure tmycomponent.myprocedure(avalue: string); begin   fmyproperty := avalue;   if assigned(fmyevent)     ; // work end;  end. 

this unit included in both design time , run time packages.

unit mycomponentregister;  interface  uses   classes, mycomponent;  procedure register;  implementation  procedure register; begin   registercomponents('samples', [tmycomponent]); end;  end. 

this second unit included in design time package. note not defined component because defined in mycomponent uses.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -