I've extended a TRichViewEdit-component, and overridden the constructor in order to set up some hard-coded styles in my custom component. However, attempting to access the TRichViewEdit.Style property throws an access violation exception, which in turn is a signal that the associated field has not yet been initialized.
When does the initialization of the Style-object take place? At what point may I access the TRichViewEdit.Style property?
At what point is TRichViewEdit.Style assigned?
-
- Posts: 25
- Joined: Thu Sep 17, 2009 7:50 am
-
- Posts: 25
- Joined: Thu Sep 17, 2009 7:50 am
further specification
To define my situation more precisely:
The access violation is thrown whenever I try to access TRichViewEdit.Style from within the constructor of TRichViewEdit.
The access violation is thrown whenever I try to access TRichViewEdit.Style from within the constructor of TRichViewEdit.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
By default, it is nil. You need to assign this property yourself.
If you place TRichViewEdit on the form and assign Style property, when the application starts, it:
1) creates a TRichViewEdit control (constructor is called)
2) loads properties (including Style)
3) calls TRichViewEdit.Loaded.
So, if you need to do something with RVStyle, override Loaded method.
Note that this method is not called when you create the component in code (you can call it directly, if you make it public).
In any case, check if Style<>nil before doing something with Style, because the user can forget to assign Style.
PS: alternatively, you can create a component inherited from TRVStyle and override its constructor.
If you place TRichViewEdit on the form and assign Style property, when the application starts, it:
1) creates a TRichViewEdit control (constructor is called)
2) loads properties (including Style)
3) calls TRichViewEdit.Loaded.
So, if you need to do something with RVStyle, override Loaded method.
Note that this method is not called when you create the component in code (you can call it directly, if you make it public).
In any case, check if Style<>nil before doing something with Style, because the user can forget to assign Style.
PS: alternatively, you can create a component inherited from TRVStyle and override its constructor.