Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

LMDSimplePropInspector to display records

I would like to be able to use the Property Inspector component to display properties of records rather than those of components. I have a feeling from some passing comments here that it should be possible, perhaps by redefining records as classes? However I don't have the Delphi skills to work out how this could/should be done. 

Is what I want to do possible? if so, can anyone show me a simple example of the necessary code?

David.  

Comments

  • 2 Comments sorted by Votes Date Added
  • edited May 13 Posts: 0 Accepted Answer Vote Up0Vote Down
    You can create object wrapper around your record and use it in property inspector. The idea is shown below:

    type
      TMyRec = record
        A: Integer;
        B: string;
      end;

      TMyWrapper = class(TPersistent)
      private
        FRec: TMyRec;
      private
        function  GetA: Integer;
        procedure SetA(const Value: Integer);
        function  GetB: string;
        procedure SetB(const Value: string);
      public
        property Rec: TMyRec read FRec;
      published
        property A: Integer read GetA write SetA;
        property B: string read GetB write SetB;
      end;

    ...

    { TMyWrapper }

    function TMyWrapper.GetA: Integer;
    begin
      Result := FRec.A;
    end;

    function TMyWrapper.GetB: string;
    begin
      Result := FRec.B;
    end;

    procedure TMyWrapper.SetA(const Value: Integer);
    begin
      FRec.A := Value;
    end;

    procedure TMyWrapper.SetB(const Value: string);
    begin
      FRec.B := Value;
    end;
  • Thanks, I will give that a go :-)
Sign In or Register to comment.