Recent

Author Topic: [SOLVED] Object properties  (Read 605 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
[SOLVED] Object properties
« on: September 02, 2020, 08:52:37 pm »
Hi All,

Today I saw a very interesting program called DFM Editor (http://www.mitec.cz/dfm.html) where you could open a DFM or LFM file and it would show, along with other things, a list of ALL properties and methods for a selected component on the form.

I was wondering is it possible (and how) to get a list of properties / methods in Lazarus?

Thanks in advance.
« Last Edit: September 02, 2020, 09:05:27 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

jamie

  • Hero Member
  • *****
  • Posts: 6091
Re: Object properties
« Reply #1 on: September 02, 2020, 08:59:13 pm »
Just open  your file manager in the IDE (OPEN) and propagate to your *.LFM file.. and open it.

it will show in the IDE editor.
The only true wisdom is knowing you know nothing

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Object properties
« Reply #2 on: September 02, 2020, 09:04:13 pm »
It's OK, I found the solution.

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, TypInfo;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     ListBox1: TListBox;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. {$R *.lfm}
  30.  
  31. { TForm1 }
  32.  
  33.  
  34. procedure ListComponentProperties(Component: TComponent; Strings: TStrings);
  35. var
  36.   Count, Size, I: Integer;
  37.   List: PPropList;
  38.   PropInfo: PPropInfo;
  39.   PropOrEvent, PropValue: string;
  40. begin
  41.   Count := GetPropList(Component.ClassInfo, tkAny, nil);
  42.   Size  := Count * SizeOf(Pointer);
  43.   GetMem(List, Size);
  44.   try
  45.     Count := GetPropList(Component.ClassInfo, tkAny, List);
  46.     for I := 0 to Count - 1 do
  47.     begin
  48.       PropInfo := List^[I];
  49.  
  50.       if PropInfo^.PropType^.Kind in tkMethods then
  51.         PropOrEvent := 'Event'
  52.       else
  53.         PropOrEvent := 'Property';
  54.  
  55.       PropValue := GetPropValue(Component, PropInfo^.Name);
  56.       Strings.Add(Format('[%s] %s: %s = %s', [PropOrEvent, PropInfo^.Name,
  57.         PropInfo^.PropType^.Name, PropValue]));
  58.     end;
  59.   finally
  60.     FreeMem(List);
  61.   end;
  62. end;
  63.  
  64. procedure TForm1.Button1Click(Sender: TObject);
  65. begin
  66.     ListComponentProperties(Button1, ListBox1.Items);
  67. end;
  68.  
  69. end.
  70.  
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

 

TinyPortal © 2005-2018