TFont property on descesndant of TfrxMemoView
We have created a descendant of the TfrxMemoView class.
In this descendant, we added a TPersistent property
TMgrGroupStyle = class(TPersistent)
private
FFrame: TFrxFrame;
FUseFrame: Boolean;
FFont: TFont;
FUseFont: Boolean;
public
procedure Assign(Source: TPersistent); override;
constructor Create; overload;
destructor Destroy; override;
published
property UseFont: Boolean read FUseFont write FUseFont;
property UseFrame: Boolean read FUseFrame write FUseFrame;
property Font: TFont read FFont write FFont;
property Frame: TFrxFrame read FFrame write FFrame;
end;
TMgrIndentMemoView = class(TfrxMemoView)
private
...
FGroupStyle: TMgrGroupStyle;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
class function GetDescription: String; override;
procedure Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX, OffsetY: Extended); override;
function Diff(AComponent: TfrxComponent): string; override;
published
...
property GroupStyle: TMgrGroupStyle read FGroupStyle write FGroupStyle;
procedure GetData; override;
end;
My new GroupStyle property is displayed in the object inspector and I can use it to trigger some special code in my overriden Draw event, so far so good. It works if I change one of the GroupStyle.Font property directly in the object inspector, but creates an AV when I try to use the font dialog via the button (besides font property).
What am I missing so to get rid of the AV.
AV seems to be triggered here:
procedure TfrxXMLSerializer.WriteRootComponent(Root: TfrxComponent;
SaveChildren: Boolean = True; XMLItem: TfrxXMLItem = nil; Streaming: Boolean = False);
var
XMLDoc: TfrxXMLDocument;
procedure DoWrite(Item: TfrxXMLItem; ARoot: TfrxComponent);
var
i: Integer;
begin
if ARoot.IsAncestor and not Streaming then
Item.Name := 'inherited'
else
Item.Name := ARoot.ClassName;
if ARoot = Root then
Item.Text := ObjToXML(ARoot)
else
Item.Text := 'Name="' + ARoot.Name + '"' + ObjToXML(ARoot); //<-- On this line
if FHandleNestedProperties and (csHandlesNestedProperties in ARoot.frComponentStyle) then
ARoot.WriteNestedProperties(Item);
if SaveChildren then
for i := 0 to ARoot.Objects.Count - 1 do
DoWrite(Item.Add, ARoot.Objects);
end;
Do I need to declare my property differently so ObjToXML can digest it better?
I tried adding the following line in the initialization, but that didn't fix it:
Initialization
frxPropertyEditors.Register(TypeInfo(TFont), TMgrIndentMemoView, 'HeaderGroupStyle.Font', TfrxFontProperty);
QUESTION #2
Also, my descendant has an extended property that I would like to treat like all the other properties that get affected by a units type change (when the user double clicks on the status bar of the object inspector to toggle between inches, centimeters, pixels, etc..) Can't find where that gets done. Can you point me in the right direction?
Please and thank you,
Richard
In this descendant, we added a TPersistent property
TMgrGroupStyle = class(TPersistent)
private
FFrame: TFrxFrame;
FUseFrame: Boolean;
FFont: TFont;
FUseFont: Boolean;
public
procedure Assign(Source: TPersistent); override;
constructor Create; overload;
destructor Destroy; override;
published
property UseFont: Boolean read FUseFont write FUseFont;
property UseFrame: Boolean read FUseFrame write FUseFrame;
property Font: TFont read FFont write FFont;
property Frame: TFrxFrame read FFrame write FFrame;
end;
TMgrIndentMemoView = class(TfrxMemoView)
private
...
FGroupStyle: TMgrGroupStyle;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
class function GetDescription: String; override;
procedure Draw(Canvas: TCanvas; ScaleX, ScaleY, OffsetX, OffsetY: Extended); override;
function Diff(AComponent: TfrxComponent): string; override;
published
...
property GroupStyle: TMgrGroupStyle read FGroupStyle write FGroupStyle;
procedure GetData; override;
end;
My new GroupStyle property is displayed in the object inspector and I can use it to trigger some special code in my overriden Draw event, so far so good. It works if I change one of the GroupStyle.Font property directly in the object inspector, but creates an AV when I try to use the font dialog via the button (besides font property).
What am I missing so to get rid of the AV.
AV seems to be triggered here:
procedure TfrxXMLSerializer.WriteRootComponent(Root: TfrxComponent;
SaveChildren: Boolean = True; XMLItem: TfrxXMLItem = nil; Streaming: Boolean = False);
var
XMLDoc: TfrxXMLDocument;
procedure DoWrite(Item: TfrxXMLItem; ARoot: TfrxComponent);
var
i: Integer;
begin
if ARoot.IsAncestor and not Streaming then
Item.Name := 'inherited'
else
Item.Name := ARoot.ClassName;
if ARoot = Root then
Item.Text := ObjToXML(ARoot)
else
Item.Text := 'Name="' + ARoot.Name + '"' + ObjToXML(ARoot); //<-- On this line
if FHandleNestedProperties and (csHandlesNestedProperties in ARoot.frComponentStyle) then
ARoot.WriteNestedProperties(Item);
if SaveChildren then
for i := 0 to ARoot.Objects.Count - 1 do
DoWrite(Item.Add, ARoot.Objects);
end;
Do I need to declare my property differently so ObjToXML can digest it better?
I tried adding the following line in the initialization, but that didn't fix it:
Initialization
frxPropertyEditors.Register(TypeInfo(TFont), TMgrIndentMemoView, 'HeaderGroupStyle.Font', TfrxFontProperty);
QUESTION #2
Also, my descendant has an extended property that I would like to treat like all the other properties that get affected by a units type change (when the user double clicks on the status bar of the object inspector to toggle between inches, centimeters, pixels, etc..) Can't find where that gets done. Can you point me in the right direction?
Please and thank you,
Richard
Comments
Solved by registering my extended property as such (in initialization section)
frxPropertyEditors.Register(TypeInfo(Extended), TfrxComponent, 'MyExtendedPropName', TfrxLocSizeXProperty);
Anyone can help with my QUESTION #1?
Richard
I needed to include an Assign method.
procedure TMyPersistent.Assign(Source: TPersistent);
var
P: TMyPersistent;
begin
if Source is TMyPersistent then
begin
P := (Source as TMyPersistent);
//assign copy stuff here
end
else
inherited;
end;
Richard
Somehow I feel like nobody is monitoring this forum [img]style_emoticons/<#EMO_DIR#>/dry.gif" style="vertical-align:middle" emoid="<_<" border="0" alt="dry.gif" /> Richard[/img]