Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Using the Lazarus IDE
»
General
»
How to invoke an arbitrary method using RTTI?
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
Artificial Intelligence a...
by
Retrofoxed
[
Today
at 01:12:49 am]
Lazarus in wayland QT6 Pl...
by
TheMouseAUS
[
Today
at 12:21:24 am]
Read/Parse PDB file to ge...
by
marcov
[May 14, 2026, 11:45:56 pm]
show me the parameters ce...
by
n7800
[May 14, 2026, 11:23:09 pm]
MP3 encoder
by
Tomxe
[May 14, 2026, 09:48:37 pm]
Scripts to generate ofici...
by
valdir.marcos
[May 14, 2026, 09:48:31 pm]
Gtk3 widgetset - call for...
by
PascalDragon
[May 14, 2026, 09:30:45 pm]
StringGrid: which is "cur...
by
valdir.marcos
[May 14, 2026, 09:27:05 pm]
FPC Unleashed (inline var...
by
VisualLab
[May 14, 2026, 09:17:03 pm]
Release ray4laz 6.0
by
MikeHart
[May 14, 2026, 09:07:32 pm]
Pure Pascal LZ4, LZ5 and ...
by
LemonParty
[May 14, 2026, 06:50:43 pm]
Pls support Double Comman...
by
Hansvb
[May 14, 2026, 03:30:31 pm]
Can I get the position an...
by
CM630
[May 14, 2026, 02:37:08 pm]
When is it useful for a p...
by
Hansvb
[May 14, 2026, 02:18:50 pm]
text color visible
by
Paolo
[May 14, 2026, 12:10:14 pm]
Transparent form
by
rvk
[May 14, 2026, 11:02:39 am]
Connecting to AzureSQL
by
CharlyTango
[May 14, 2026, 10:21:29 am]
Qt does not position form...
by
dbannon
[May 14, 2026, 09:42:44 am]
How to compare floating p...
by
Sander
[May 13, 2026, 11:12:02 pm]
TA Chart Axes visibility ...
by
Nicole
[May 13, 2026, 08:27:54 pm]
new feature for IDE
by
n7800
[May 13, 2026, 08:20:14 pm]
Can /my/ AI help me with ...
by
440bx
[May 13, 2026, 07:28:37 pm]
SynEdit auto End of line ...
by
eldonfsr
[May 13, 2026, 05:02:39 pm]
[beyond fixing]FPGMAP acc...
by
Thaddy
[May 13, 2026, 01:13:34 pm]
Hint tools gives wrong hi...
by
Nicole
[May 13, 2026, 01:11:47 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: How to invoke an arbitrary method using RTTI? (Read 636 times)
cpicanco
Hero Member
Posts: 674
Behavioral Scientist and Programmer
How to invoke an arbitrary method using RTTI?
«
on:
September 01, 2024, 04:53:19 pm »
Does Free Pascal ({$mode objfpc}) supports invoking arbitrary methods with RTTI?
Did Michael wrote a continuation of this documentation:
https://www.freepascal.org/~michael/articles/rtti1/rtti1.pdf?
He mentioned that invoking arbritrary methods would be explored in next chapters.
This Chat GPT answer did not worked:
Code: Pascal
[Select]
[+]
[-]
uses
sysutils
,
rtti
;
type
TMyClass
=
class
procedure
MyMethod
;
end
;
procedure
TMyClass
.
MyMethod
;
begin
writeln
(
'MyMethod has been called'
)
;
end
;
var
ctx
:
TRttiContext
;
typ
:
TRttiType
;
method
:
TRttiMethod
;
instance
:
TObject
;
begin
instance
:
=
TMyClass
.
Create
;
try
ctx
:
=
TRttiContext
.
Create
;
try
typ
:
=
ctx
.
GetType
(
TMyClass
)
;
method
:
=
typ
.
GetMethod
(
'MyMethod'
)
;
if
Assigned
(
method
)
then
method
.
Invoke
(
instance
,
[
]
)
;
finally
ctx
.
Free
;
end
;
finally
instance
.
Free
;
end
;
end
.
PS.: There is a recent question in StackOverflow on how to use the invoke method:
https://stackoverflow.com/questions/78922855/in-lazarus-fpc-how-do-i-get-a-pointer-to-a-class-or-record-method/78927526?noredirect=1#comment139161075_78927526
)
Logged
Be mindful and excellent with each other.
https://github.com/cpicanco/
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Using the Lazarus IDE
»
General
»
How to invoke an arbitrary method using RTTI?
TinyPortal
© 2005-2018