Recent

Author Topic: [Reopend] Assistance with TIPropertyGrid and things like TBITMAP fields.  (Read 694 times)

jamie

  • Hero Member
  • *****
  • Posts: 7306
I decided to give a TIPropertyGrid a try for a specific operation which may work nicely for my needs.

First off, I can get all the basic type fields to work just fine however, I would like to do things like the TBITMAP property.

I can get the Image load dialog to appear but when I decide to use the LOAD button, it crashes. Obviously I need to initiate some IDE classes to use this.
Here is the short test I have started.
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, RTTIGrids;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.   TTest = class(TComponent)
  14.   private
  15.     fLeft: integer;
  16.     fBitmap: TBitmap;
  17.   public
  18.     constructor Create(aowner: TComponent); override;
  19.     destructor Destroy; override;
  20.   published
  21.     property left: integer read FLeft write Fleft;
  22.     property Bitmap: TBitMap read fBitmap write fBitmap;
  23.   end;
  24.  
  25.   TForm1 = class(TForm)
  26.     Button1: TButton;
  27.     TIPropertyGrid1: TTIPropertyGrid;
  28.     procedure FormCreate(Sender: TObject);
  29.   private
  30.  
  31.   public
  32.     TestObject: Ttest;
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.lfm}
  41.  
  42. destructor TTest.Destroy;
  43. begin
  44.   fBitMap.Free;
  45.   inherited;
  46. end;
  47.  
  48. constructor TTest.Create(aowner: TComponent);
  49. begin
  50.   inherited;
  51.   fBitmap := nil;
  52. end;
  53.  
  54. { TForm1 }
  55.  
  56. procedure TForm1.FormCreate(Sender: TObject);
  57. begin
  58.   TestObject := TTest.Create(Self);
  59.   TiPropertyGrid1.TIObject := TestObject;
  60. end;
  61.  
  62. end.
  63.  
Once I figure this out I am sure I can do the rest.
Thanks.

« Last Edit: October 26, 2025, 07:14:12 pm by jamie »
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7306
Re: Assistance with TIPropertyGrid and things like TBITMAP fields.
« Reply #1 on: October 19, 2025, 04:07:11 pm »
After closer examination and getting a basic understanding of the controls at hand along with the massive amount of resources it takes to use these controls, I can't afford the space and CPU cycles.

 I'll make my own property editor using a TTreeView and some basic Classes with a base edit class for each one.

 Also, there is the chance of program breakage if the IDE makes changes.


Jamie
The only true wisdom is knowing you know nothing

BildatBoffin

  • New Member
  • *
  • Posts: 40
I think you need a setter for the `write` at then in that setter use assign() so that data are copied. otherwise you just assign a pointer and things get lost.

BildatBoffin

  • New Member
  • *
  • Posts: 40
Concretly I meant try something like this instead

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, RTTIGrids;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.   TTest = class(TComponent)
  14.   private
  15.     fLeft: integer;
  16.     fBitmap: TBitmap;
  17.     procedure SetBitmap(other: TPersistent);
  18.   public
  19.     constructor Create(aowner: TComponent); override;
  20.     destructor Destroy; override;
  21.   published
  22.     property left: integer read FLeft write Fleft;
  23.     property Bitmap: TBitMap read fBitmap write setBitmap;
  24.   end;
  25.  
  26.   TForm1 = class(TForm)
  27.     Button1: TButton;
  28.     TIPropertyGrid1: TTIPropertyGrid;
  29.     procedure FormCreate(Sender: TObject);
  30.   private
  31.  
  32.   public
  33.     TestObject: Ttest;
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43. destructor TTest.Destroy;
  44. begin
  45.   fBitMap.Free;
  46.   inherited;
  47. end;
  48.  
  49. constructor TTest.Create(aowner: TComponent);
  50. begin
  51.   inherited;
  52.   fBitmap := TBitmape.Create();
  53. end;
  54.  
  55. procedure TTest.SetBitmap(other: TPersistent);
  56. begin
  57.   fBitmap.assign(other);
  58. end;
  59.  
  60. { TForm1 }
  61.  
  62. procedure TForm1.FormCreate(Sender: TObject);
  63. begin
  64.   TestObject := TTest.Create(Self);
  65.   TiPropertyGrid1.TIObject := TestObject;
  66. end;
  67.  
  68. end.

The point is the ownership.

jamie

  • Hero Member
  • *****
  • Posts: 7306
Re: [Reopend] Assistance with TIPropertyGrid and things like TBITMAP fields.
« Reply #4 on: October 26, 2025, 07:18:53 pm »
I managed to get around the problem of the Dialogs, you need to set a vector back to your code so it gives you a chance to set paths in the dialog. That is working and I can read/write image data to a stream however, I am having problems streaming child classes to a stream for property info.

 I have a test app attached showing what I have so far, would be nice if I could also stream child classes to the same output component stream etc.

This uses the TIPropertyGrid so as so far I have much of what I need working, I just need some help getting the child classes to also stream.

  I did call the RegisterClass(TChildClass) but that does not seem to help.

The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 7306
Re: [Reopend] Assistance with TIPropertyGrid and things like TBITMAP fields.
« Reply #5 on: November 01, 2025, 03:23:16 pm »
I've gotten over the hurtle of streaming child classes, apparently, They can only descend from TPersistent.

Next question:
  How do I insert at runtime a published class much like the IDE OI does when dropping controls on the form.

  I want to insert a class at runtime into the main class so the Property Grid can see it and stream it?

Jamie

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018