Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Need to get event parameters along with their respective types separately


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 6 - Last Post: Feb 29, 2016 11:32 AM Last Post By: Remy Lebeau (Te...
Vishal Tiwari

Posts: 3
Registered: 3/8/16
Need to get event parameters along with their respective types separately  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2016 3:53 AM
I am using Delphi XE5.

I have am storing property and event names of provided Delphi VCL component using below code in an excel file.

procedure TForm1.Button1Click(Sender: TObject);
var
PropInfo: PPropInfo;
MyPTypeInfo : PTypeInfo;
MyPPropList : PPropList;

Count, I : Integer;
PropOrEvent, PropValue : String;
FileName : String;
begin
FileName := 'C:\MyFile_Delphi.xlsx';
ListBox1.Items.Clear;
GetPropList(Button1, MyPPropList);

try
Count := GetPropList(Button1, MyPPropList);
for I := 0 to Count - 1 do
begin
PropInfo := MyPPropList^[I];
if PropInfo^.PropType^.Kind in tkMethods then
PropOrEvent := 'Event'
else
PropOrEvent := 'Property';
PropValue := VarToStr(GetPropValue(Button1, PropInfo^.Name));

ListBox1.Items.Add(PropOrEvent + ' - ' + PropInfo^.Name);

end;
finally
ListBox1.Items.SaveToFile(FileName);
FreeMem(MyPPropList);
end;
end;
But with this I also need every event parameter names along with their respective type like:

procedure TForm1.FormConstrainedResize(Sender: TObject; var MinWidth, MinHeight,
MaxWidth, MaxHeight: Integer);
begin

end;

When I get this event name then at the same time, I need to get the result as :

Sender: TObject
MinWidth: Integer
MinHeight: Integer
MaxWidth: Integer
MaxHeight: Integer
May be via running one more loop for this.

How to get this ?

Thanks in advance.
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Need to get event parameters along with their respective types separately  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2016 11:07 AM   in response to: Vishal Tiwari in response to: Vishal Tiwari
Vishal Tiwari wrote:

I am using Delphi XE5.

I have am storing property and event names of provided Delphi VCL
component using below code in an excel file.

procedure TForm1.Button1Click(Sender: TObject);
var
PropInfo: PPropInfo;
MyPTypeInfo : PTypeInfo;
MyPPropList : PPropList;

You are using the old-style RTTI here, which is designed to support the
DFM file streaming mechanism. To attach an event handler the stream
reader only needs the name of the event handler, which it then uses
with the root components MethodAddress method to find the code address
of the method to construct the method pointer to assign to the event.
It needs no information about the event handler parameter, so there is
no way to get those with the old style RTTI.

You will have to use the new extended RTTI functionality here. Go
searching for TRttiContext, TRttiMethod etc. (all in the system.rtti
unit). That should turn up examples of use.


--
Peter Below
TeamB

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Need to get event parameters along with their respective typesseparately  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 26, 2016 12:32 PM   in response to: Peter Below in response to: Peter Below
Peter wrote:

there is no way to get those with the old style RTTI.

Actually, there is. The old RTTI provides the parameter names and type strings,
and in D2010+ it also provides a PTypeInfo for each parameter. See my other
reply for an example.

--
Remy Lebeau (TeamB)
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Need to get event parameters along with their respective typesseparately  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2016 1:21 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Peter wrote:

there is no way to get those with the old style RTTI.

Actually, there is. The old RTTI provides the parameter names and
type strings, and in D2010+ it also provides a PTypeInfo for each
parameter. See my other reply for an example.

really? Hadn't noticed that, but i'm well behind on features offered by
the newer Delphi versions. It has been ages since I actually needed to
use such things myself...

--
Peter Below
TeamB
Vishal Tiwari

Posts: 3
Registered: 3/8/16
Re: Need to get event parameters along with their respective typesseparately  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 27, 2016 6:49 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Peter wrote:

there is no way to get those with the old style RTTI.

Actually, there is. The old RTTI provides the parameter names and type strings,
and in D2010+ it also provides a PTypeInfo for each parameter. See my other
reply for an example.

--
Remy Lebeau (TeamB)

Would you provide the link of you reply?

Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Need to get event parameters along with their respective typesseparately  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 28, 2016 1:02 AM   in response to: Vishal Tiwari in response to: Vishal Tiwari
Vishal Tiwari wrote:

Remy Lebeau (TeamB) wrote:
Peter wrote:

there is no way to get those with the old style RTTI.

Actually, there is. The old RTTI provides the parameter names and
type strings, and in D2010+ it also provides a PTypeInfo for each
parameter. See my other reply for an example.

--
Remy Lebeau (TeamB)

Would you provide the link of you reply?


Check the source of the typinfo unit, this is a traditionally
undocumented area...

--
Peter Below
TeamB
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Need to get event parameters along with their respectivetypesseparately  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 29, 2016 11:32 AM   in response to: Vishal Tiwari in response to: Vishal Tiwari
Vishal wrote:

Would you provide the link of you reply?

My bad. I had posted that reply to StackOverflow instead, where Vishal had
asked the same question (I hate when people do that!). Here is the link
to my answer with the two RTTI examples:

http://stackoverflow.com/a/35659617/65863

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02