Collection property editor at runtime lazarus / 31-LCL ---------------------------------------------------------------------- serge_t · 2015-05-24 20:42 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. ---------------------------------------------------------------------- howardpc · 2015-05-25 07:29 Presumably you have not looked at ....\lazarus\components\rtticontrols\examples\exampleprojectgrid1.lpi ? ---------------------------------------------------------------------- serge_t · 2015-05-25 08:25 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. · 2015-05-25 08:46 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 · 2015-05-25 08:53 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. ---------------------------------------------------------------------- Basile B. · 2015-05-25 10:38 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. ---------------------------------------------------------------------- serge_t · 2015-05-25 10:56 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. ---------------------------------------------------------------------- Basile B. · 2015-05-25 11:06 Then stay on Delphi 7 if it's so great... ---------------------------------------------------------------------- serge_t · 2015-05-25 11:44 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 · 2015-05-25 12:05 Quote from: serge_t on May 25, 2015, 01:44:18 pmWhy use D7 in 2015 when XE8 is released? One reason is that many people/companies who could afford D7 cannot afford XE8. Quote from: serge_t on May 25, 2015, 01:44:18 pmI 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... ---------------------------------------------------------------------- taazz · 2015-05-25 12:08 Quote from: serge_t on May 25, 2015, 12:56:40 pmFor 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. ---------------------------------------------------------------------- serge_t · 2015-05-25 12:41 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 · 2015-05-25 12:50 Quote from: serge_t on May 25, 2015, 02:41:01 pmFolks, 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. ---------------------------------------------------------------------- Basile B. · 2015-05-25 13:00 Quote from: serge_t on May 25, 2015, 02:41:01 pmFolks, 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/9cbadf9d4473528ff4973fd3971074 aebabda39c/components/IdeInspector/maininspector.pas#L101 https://github.com/graemeg/lazarus/blob/9cbadf9d4473528ff4973fd3971074 aebabda39c/components/IdeInspector/maininspector.pas#L596 https://github.com/graemeg/lazarus/blob/9cbadf9d4473528ff4973fd3971074 aebabda39c/components/IdeInspector/maininspector.pas#L605 https://github.com/graemeg/lazarus/blob/9cbadf9d4473528ff4973fd3971074 aebabda39c/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. · 2015-05-25 13:33 Quote from: serge_t on May 25, 2015, 12:56:40 pmBBasile, 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