Recent

Author Topic: Collection property editor at runtime  (Read 7266 times)

serge_t

  • New Member
  • *
  • Posts: 10
Collection property editor at runtime
« on: May 24, 2015, 10:42:00 pm »
Hello,

Does anyone get working TTIPropertyGrid / Editor with collections?

I have access violation at runtime even for standard components like TStringGrid when selecting columns.
I added issue on tracker with small example: http://bugs.freepascal.org/view.php?id=28175

Simple code working in Delphi 7 with TOwnedCollection doesn't work in Lazarus too.

Any suggestions / workarounds are welcome.
« Last Edit: May 24, 2015, 10:45:21 pm by serge_t »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Collection property editor at runtime
« Reply #1 on: May 25, 2015, 09:29:26 am »
Presumably you have not looked at
....\lazarus\components\rtticontrols\examples\exampleprojectgrid1.lpi ?

serge_t

  • New Member
  • *
  • Posts: 10
Re: Collection property editor at runtime
« Reply #2 on: May 25, 2015, 10:25:20 am »
howardpc,

Yes, I looked at examples in components/rtticontrols but they are not matched to my case.
Particularly, exampleprojectgrid1 contains TTIGrid that shows the collection of objects. But I need to get working standard collection editor for collection property of an object shown by TTIPropertyGrid (like columns of grid).

Basile B.

  • Guest
Re: Collection property editor at runtime
« Reply #3 on: May 25, 2015, 10:46:07 am »
TTIPropertyGrid is just a base class that works with simple properties (i believe that the Lazarus Object inspector is much more complex than that).

In a project, for the collections, i had to write a menu representing the collections elements and when a menu item is selected, the TIObject value is set to the collection item matching the menu item.

By menu i don't necessarily mean TMenu, it can be a tree view too, or a TMemo with each line object set to a collection item...

serge_t

  • New Member
  • *
  • Posts: 10
Re: Collection property editor at runtime
« Reply #4 on: May 25, 2015, 10:53:04 am »
BBasile,

TTIPropertyGrid shows collections properties and assign them a default collection editor as it expected.
The problem is that this editor seems not working or some additional code is required.

My workaround is to create own property editor but I'd prefer to use standard one to reduce codebase.

P.S. TTIPropertyGrid is the descendant of TOICustomPropertyGrid that is used in IDE's object inspector, they have the common codebase.
« Last Edit: May 25, 2015, 11:22:07 am by serge_t »

Basile B.

  • Guest
Re: Collection property editor at runtime
« Reply #5 on: May 25, 2015, 12:38:46 pm »
I just tell you that when you select a TCollection item from the default editor, the TTIPropertyGrid.TIObject property is not set accordingly to this particular item. So you have to write a kind of custom selector. It can be done in 15 lines of codes.

For my own thing, like said before, i've written a custom selector to overcome the same issue, but you can access the dialog a bit like this:

Code: [Select]
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, FileUtil, RTTIGrids, Forms, Controls, Graphics, Dialogs,
  Grids, ObjectInspector, PropEdits, CollectionPropEditForm;

type
  { TForm1 }
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    TIPropertyGrid1: TTIPropertyGrid;
  private
    procedure CollectionItemClick(Sender: TObject);
  public
    constructor Create(TheOwner: TComponent); override;
  end;

var
  Form1: TForm1;

implementation
{$R *.lfm}
constructor TForm1.Create(TheOwner: TComponent);
var
  rw: TOIPropertyGridRow;
  ed: TCollectionPropertyEditor;
  fm: TCollectionPropertyEditorForm;
  i: integer;
begin
  inherited;
  for i := 0 to TIPropertyGrid1.RowCount-1 do
  begin
    rw := TIPropertyGrid1.Rows[i];
    if not (rw.Editor is TCollectionPropertyEditor) then continue;
    ed := TCollectionPropertyEditor(rw.Editor);
    fm := TCollectionPropertyEditorForm(ed.ShowCollectionEditor(nil, nil, ''));
    fm.CollectionListBox.OnClick:=@CollectionItemClick;
    fm.Close;
  end;
end;

procedure TForm1.CollectionItemClick(Sender: TObject);
begin
  ShowMessage('Now you are notified and you can set TIPropertyGrid1.TIObject');
end;

end.

now you have the pattern, but it's not finished:
  • in TForm1.CollectionItemClick you have to find which item is selected so that TIPropertyGrid1.TIObject can be set.
  • you also have to set an event which restores previous TIPropertyGrid1.TIObject value when the collection editor closes.
« Last Edit: May 25, 2015, 12:46:30 pm by BBasile »

serge_t

  • New Member
  • *
  • Posts: 10
Re: Collection property editor at runtime
« Reply #6 on: May 25, 2015, 12:56:40 pm »
BBasile,

Thank for example. But I see that 15 lines do only very basic things. You should find selected collection item before set it to property grid and set back the main object at least. The code with handlers is specific to form used so you cannot use it with several forms.
Finally, this kind of generalization seems more complex that own property editor.

For info, in Delphi 7 these manipulations are not required at all.
« Last Edit: May 25, 2015, 12:58:46 pm by serge_t »

Basile B.

  • Guest
Re: Collection property editor at runtime
« Reply #7 on: May 25, 2015, 01:06:56 pm »
Then stay on Delphi 7 if it's so great...

serge_t

  • New Member
  • *
  • Posts: 10
Re: Collection property editor at runtime
« Reply #8 on: May 25, 2015, 01:44:18 pm »
Why use D7 in 2015 when XE8 is released?
I mean that in 2015 D7 stay more simple and efficient in many areas than L1.4, i.e. debugging and watch values. And it's really sad.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Collection property editor at runtime
« Reply #9 on: May 25, 2015, 02:05:51 pm »
Why use D7 in 2015 when XE8 is released?
One reason is that many people/companies who could afford D7 cannot afford XE8.

I mean that in 2015 D7 stay more simple and efficient in many areas than L1.4, i.e. debugging and watch values. And it's really sad.
It's not so much sad as a reflection of the fact that L1.4 is truly cross-platform, and written entirely by volunteers in their spare time. A RAD tool that supports so many platforms/processors/OSs is never going to be as simple and efficient as one that is optimised for a single OS, which inherited a debugger that was in continuous development for that single platform for at least the previous 10 years, and was written by a sizeable team of full-time professional developers, most of whom were so good that M$ made them offers they could not refuse.

Nevertheless, you can contribute to improve the places where you see Lazarus is currently lacking. Of course there are many...
« Last Edit: May 25, 2015, 02:07:56 pm by howardpc »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Collection property editor at runtime
« Reply #10 on: May 25, 2015, 02:08:17 pm »
For info, in Delphi 7 these manipulations are not required at all.
True. Delphi 7 does not come with any property grids. You need 3rd party code for that.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

serge_t

  • New Member
  • *
  • Posts: 10
Re: Collection property editor at runtime
« Reply #11 on: May 25, 2015, 02:41:01 pm »
Folks, do not start holywar please.
Personally, I use D7 in 2015 because of millions lines of legacy code but there are no more reasons for me.
I consider FreePascal a good alternative of C++ for cross-platform development but only the in RTL/FCL level.
Unfortunately, when I use LCL, I always need to workaround many problems and swim deeply in source code that add hours and days.
So there is no discuss for me, LCL to be improved and I hope to see it before my retirement.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Collection property editor at runtime
« Reply #12 on: May 25, 2015, 02:50:43 pm »
Folks, do not start holywar please.
Which war? Just tells us what is the framework you use in delphi 7 so we can take part on your discussion. Other than that its a waste of time.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Basile B.

  • Guest
Re: Collection property editor at runtime
« Reply #13 on: May 25, 2015, 03:00:48 pm »
Folks, do not start holywar please.
Personally, I use D7 in 2015 because of millions lines of legacy code but there are no more reasons for me.
I consider FreePascal a good alternative of C++ for cross-platform development but only the in RTL/FCL level.
Unfortunately, when I use LCL, I always need to workaround many problems and swim deeply in source code that add hours and days.
So there is no discuss for me, LCL to be improved and I hope to see it before my retirement.

Your POV on this particular issue is irritating because there's no that much code to add...even the Lazarus object inspector uses some events (it tracks which control is active and which form is active to update the grid TIObject):

https://github.com/graemeg/lazarus/blob/9cbadf9d4473528ff4973fd3971074aebabda39c/components/IdeInspector/maininspector.pas#L101
https://github.com/graemeg/lazarus/blob/9cbadf9d4473528ff4973fd3971074aebabda39c/components/IdeInspector/maininspector.pas#L596
https://github.com/graemeg/lazarus/blob/9cbadf9d4473528ff4973fd3971074aebabda39c/components/IdeInspector/maininspector.pas#L605
https://github.com/graemeg/lazarus/blob/9cbadf9d4473528ff4973fd3971074aebabda39c/components/IdeInspector/maininspector.pas#L699

You could find that by yourself with a minimal intellectual effort (a few Ctrl + Click or Ctrl + Shift + Up, goto definition, goto implementation...).

Basile B.

  • Guest
Re: Collection property editor at runtime
« Reply #14 on: May 25, 2015, 03:33:42 pm »
BBasile,

Thank for example. But I see that 15 lines do only very basic things. You should find selected collection item before set it to property grid and set back the main object at least. The code with handlers is specific to form used so you cannot use it with several forms.
Finally, this kind of generalization seems more complex that own property editor.

For info, in Delphi 7 these manipulations are not required at all.

http://imgur.com/ovIuu73

 

TinyPortal © 2005-2018