Jump to content


Photo

TNxPropertyItems.AddChild / AddItem


  • Please log in to reply
4 replies to this topic

#1 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 23 May 2014 - 12:23 AM

unit NxPropertyItems;
...
procedure TNxPropertyItems.AddItem(Parent, Item: TNxPropertyItem; Position: TAddPosition);
...
(1867) Item.Font.Assign(TNxCustomInspector(FOwner).Font);
(1868) Item.ValueFont.Assign(Item.Font);

The existence of these lines seem like a bug to me. The issue here for me, is that TNxProperyItems.AddChild internally calls TNxPropertyItems.AddItem, which then resets any changes made to the object's item.font or item.font.style prior to adding the object to the control. This isn't such a big deal when you're calling AddChild since it returns the object and you can easily modify it after adding it, but in the case of calling AddItem directly it's super annoying since you're forced to use it to assign the parent/child relationship of the item in the treeview but then can't directly manipulate the object after its added and it overwrites any font changes made prior to adding. Well not without doing something similar to below...

Here's code I used to test how adding items to the control worked.

procedure AddItem(ni: TNextInspector; strName: string);
var
pi, ci: TNxPropertyItem;
begin
// Add parent item
pi := ni.Items.AddChild(nil, TNxTextItem, strName);
pi.Caption := strName;
pi.Expanded := False;

// Add child item
ci := TNxMemoItem.Create(ni);
ci.ReadOnly := True;
ci.Value := strName;
ni.Items.AddItem(pi, ci);

ci.Free;
ci := pi.GetFirstChild;
ci.ValueFont.Style := [];
end;

Am I missing something here? Is there a better way?
Thanks.

#2 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 23 May 2014 - 05:07 PM

I ended up doing this, since it was really only the style I needed to modify.

procedure TNxPropertyItems.AddItem(Parent, Item: TNxPropertyItem; Position: TAddPosition);
var
  Pos: Integer;
  fsSaved: TFontStyles;
begin
...
  fsSaved := Item.ValueFont.Style;
  Item.Font.Assign(TNxCustomInspector(FOwner).Font);
  Item.ValueFont.Assign(Item.Font);
  Item.ValueFont.Style := fsSaved;
  if not Item.Hidden then Item.Change(ckAdded);
end;


#3 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 25 May 2014 - 06:36 AM

Hi,

I will need to see how to solve this better. Maybe having ParentFont checking, or maybe adding optional parameter to this method. I will decide in next days.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#4 FourWhey

FourWhey
  • Members
  • 165 posts

Posted 28 May 2014 - 07:02 PM

Hi,

I will need to see how to solve this better. Maybe having ParentFont checking, or maybe adding optional parameter to this method. I will decide in next days.

Any changes would be welcome.

If AddChild accepted an argument to assign parent, it would solve the problem. It would allow us to modify the object after it was added and make it easy to recursively add Parent/Child items.

Parent items would have a nil parent. Child would have a parent assigned.
This would function similar to other Treenodes, in that you create the Parent, Child, Grandchild nodes and modify them accordingly.

#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 01 June 2014 - 06:47 PM

Hello,

I have added (optional, default True) parameter to AddItem procedure:

This is added at the end of this procedure:

  if UpdateFont then
  begin
    Item.Font.Assign(TNxCustomInspector(FOwner).Font);
    Item.ValueFont.Assign(Item.Font);
  end;    

In v6 I have already solved this much better. I have 2 properties named ParentCaptionFont and ParentValueFont. I have tried to add them in v5, but I will need to think how to not broke users existing code.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users