Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-11

How to hide class names in a property grid?

10 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Gabor Boros

Hi All,

I use a property grid in my application and don't want to advertise my class names to the users. For example (TSizeConstraints) displayed next to Contraints. Any idea how to hide class names or override at object(TPersistent) level?

Gabor

Reply by email

Mattias Gaertner
to Gabor Boros
Show quoted text 6 lines
Hi All, I use a property grid in my application and don't want to advertise my class names to the users. For example (TSizeConstraints) displayed next to Contraints. Any idea how to hide class names or override at object(TPersistent) level?

You cannot decrease visibility in Free Pascal.
You can hide properties in the Object inspector. For example

  RegisterPropertyEditor(TypeInfo(TAnchorSide), TControl, 'AnchorSideLeft', THiddenPropertyEditor);

Mattias

Reply by email

Gabor Boros
to Mattias Gaertner

2015.11.11. 21:22 keltez?ssel, Mattias Gaertner ?rta:

You cannot decrease visibility in Free Pascal. You can hide properties in the Object inspector. For example RegisterPropertyEditor(TypeInfo(TAnchorSide), TControl, 'AnchorSideLeft', THiddenPropertyEditor);

I don't want to hide the property just the class name. Now I see MyProperty (TMySubClass) in the property grid. I want to show property name MyProperty only to the user without class name.

Gabor

Reply by email

Mattias Gaertner
to Gabor Boros: I use a property grid in my application and don't want to advertise my class names to the…
Show quoted text 6 lines
Hi All, I use a property grid in my application and don't want to advertise my class names to the users. For example (TSizeConstraints) displayed next to Contraints. Any idea how to hide class names or override at object(TPersistent) level?

There is no option yet.

It is done by TClassPropertyEditor.GetValue in unit propedits.pp.

Feel free to implement an option.

Mattias

Reply by email

Gabor Boros
to Mattias Gaertner

2015.11.12. 11:33 keltez?ssel, Mattias Gaertner ?rta:

Show quoted text 5 lines
There is no option yet. It is done by TClassPropertyEditor.GetValue in unit propedits.pp. Feel free to implement an option.

I created a property and attached the patch. Please review.

Gabor
-------------- next part --------------
Index: components/ideintf/objectinspector.pp
=================================================================== --- components/ideintf/objectinspector.pp (revision 50318) +++ components/ideintf/objectinspector.pp (working copy) @@ -295,6 +295,7 @@

     FActiveRowBmp: TCustomBitmap;
     FFirstClickTime: DWORD;
     FKeySearchText: string;

+ FHideClassNames: Boolean;

     // hint stuff
     FHintTimer: TTimer;
@@ -507,6 +508,7 @@
     property TopY: integer read FTopY write SetTopY default 0;
     property Favorites: TOIFavoriteProperties read FFavorites write SetFavorites;
     property Filter : TTypeKinds read FFilter write SetFilter;
+    property HideClassNames: Boolean read FHideClassNames write FHideClassNames;
   end;
@@ -1744,7 +1746,7 @@
       ValueEdit.ReadOnly:=NewRow.IsReadOnly;
       ValueEdit.Enabled:=true;
       ValueEdit.MaxLength:=NewRow.Editor.GetEditLimit;
-      ValueEdit.Text:=NewValue;
+      if (FHideClassNames and (Rows[FItemIndex].Editor is TClassPropertyEditor)) then ValueEdit.Text:='' else ValueEdit.Text:=NewValue;
     end;
     AlignEditComponents;
     if FCurrentEditnil then
@@ -2797,7 +2799,7 @@
     Font:=OldFont;
     // draw value
-    if ARowItemIndex
+    if (ARowItemIndex) and not (FHideClassNames and (CurRow.Editor is TClassProperty))
     then begin
       OldFont:=Font;
       if CurRow.Editor.IsNotDefaultValue then

Reply by email

Mattias Gaertner
to Gabor Boros
Show quoted text 8 lines
2015.11.12. 11:33 keltez?ssel, Mattias Gaertner ?rta: > There is no option yet. > > It is done by TClassPropertyEditor.GetValue in unit propedits.pp. > > Feel free to implement an option. I created a property and attached the patch. Please review.

Only TClassPropertyEditor shows the classname. Descends like TPersistentPropertyEditor shows the name for Components.

Maybe better make the option a class option of TClassPropertyEditor.

Mattias

Reply by email

Gabor Boros
to Mattias Gaertner

2015.11.14. 16:57 keltez?ssel, Mattias Gaertner ?rta:

Show quoted text 6 lines
> I created a property and attached the patch. Please review. Only TClassPropertyEditor shows the classname. Descends like TPersistentPropertyEditor shows the name for Components. Maybe better make the option a class option of TClassPropertyEditor.

New patch attached. I hope better than the previous.

Gabor
-------------- next part --------------
Index: components/ideintf/objectinspector.pp
=================================================================== --- components/ideintf/objectinspector.pp (revision 50331) +++ components/ideintf/objectinspector.pp (working copy) @@ -295,6 +295,7 @@

     FActiveRowBmp: TCustomBitmap;
     FFirstClickTime: DWORD;
     FKeySearchText: string;

+ FHideClassNames: Boolean;

     // hint stuff
     FHintTimer: TTimer;
@@ -507,6 +508,7 @@
     property TopY: integer read FTopY write SetTopY default 0;
     property Favorites: TOIFavoriteProperties read FFavorites write SetFavorites;
     property Filter : TTypeKinds read FFilter write SetFilter;
+    property HideClassNames: Boolean read FHideClassNames write FHideClassNames;
   end;
@@ -1859,6 +1861,8 @@
   end;
   if PropEditor is TClassPropertyEditor then
     (PropEditor as TClassPropertyEditor).SubPropsTypeFilter := FFilter;
+  if PropEditor is TClassPropertyEditor then
+    (PropEditor as TClassPropertyEditor).HideClassName:=FHideClassNames;
   NewRow := TOIPropertyGridRow.Create(Self, PropEditor, nil, WidgetSets);
   FRows.Add(NewRow);
   if FRows.Count>1 then begin
@@ -1983,6 +1987,8 @@
 begin
   if PropEditor is TClassPropertyEditor then
     (PropEditor as TClassPropertyEditor).SubPropsTypeFilter := FFilter;
+  if PropEditor is TClassPropertyEditor then
+    (PropEditor as TClassPropertyEditor).HideClassName:=FHideClassNames;
   NewRow:=TOIPropertyGridRow.Create(Self,PropEditor,FExpandingRow, []);
   NewIndex:=FExpandingRow.Index+1+FExpandingRow.ChildCount;
   NewRow.FIndex:=NewIndex;
Index: components/ideintf/propedits.pp
===================================================================
--- components/ideintf/propedits.pp	(revision 50331)
+++ components/ideintf/propedits.pp	(working copy)
@@ -571,6 +571,7 @@
   TClassPropertyEditor = class(TPropertyEditor)
   private
     FSubPropsTypeFilter: TTypeKinds;
+    FHideClassName: Boolean;
     procedure SetSubPropsTypeFilter(const AValue: TTypeKinds);
     function EditorFilter(const AEditor: TPropertyEditor): Boolean;
   protected
@@ -584,6 +585,7 @@
     property SubPropsTypeFilter: TTypeKinds
       read FSubPropsTypeFilter write SetSubPropsTypeFilter default tkAny;
+    property HideClassName: Boolean read FHideClassName write FHideClassName;
   end;

{ TMethodPropertyEditor
@@ -4222,7 +4224,7 @@

 function TClassPropertyEditor.GetValue: ansistring;
 begin
-  Result:='(' + GetPropType^.Name + ')';
+  if not FHideClassName then Result:='(' + GetPropType^.Name + ')';
 end;
 procedure TClassPropertyEditor.SetSubPropsTypeFilter(const AValue: TTypeKinds);

Reply by email

Gabor Boros
to Gabor Boros

2015.11.14. 18:53 keltez?ssel, Gabor Boros ?rta:

Show quoted text 10 lines
2015.11.14. 16:57 keltez?ssel, Mattias Gaertner ?rta: >> I created a property and attached the patch. Please review. > > Only TClassPropertyEditor shows the classname. Descends like > TPersistentPropertyEditor shows the name for Components. > > Maybe better make the option a class option of TClassPropertyEditor. New patch attached. I hope better than the previous.

Mattias?

Gabor

Reply by email

Mattias Gaertner
to Gabor Boros: 2015.11.14. 16:57 keltez?ssel, Mattias Gaertner ?rta: New patch attached. I hope better…
Show quoted text 9 lines
2015.11.14. 16:57 keltez?ssel, Mattias Gaertner ?rta: >> I created a property and attached the patch. Please review. > > Only TClassPropertyEditor shows the classname. Descends like > TPersistentPropertyEditor shows the name for Components. > > Maybe better make the option a class option of TClassPropertyEditor. New patch attached. I hope better than the previous.

Yes. Applied.

Mattias

Reply by email