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

Comments

  • edited 5:19AM
    For those that may be interested, I am answering my QUESTION #2:

    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

    Richard17 wrote: »
    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
  • edited 5:19AM
    Also answering my QUESTION #1: (for those interested)

    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
  • edited 5:19AM
    Correction, that didn't fix it. I still need help with this.

    Richard17 wrote: »
    Also answering my QUESTION #1: (for those interested)

    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
  • edited 5:19AM
    Now fixed. What really fixed it is defining a setter for my Font property which would Assign the Font.

    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]
    Richard17 wrote: »
    Correction, that didn't fix it. I still need help with this.

    Richard17 wrote: »
    Also answering my QUESTION #1: (for those interested)

    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

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.