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
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
SetPart ?
by
circular
[
Today
at 01:10:21 pm]
Help basic Image Quality ...
by
Thaddy
[
Today
at 12:46:01 pm]
const declaration
by
DonAlfredo
[
Today
at 11:45:36 am]
H2Pas can't handle EXP CA...
by
Zvoni
[
Today
at 10:28:37 am]
CADSys4 3D.
by
zamtmn
[
Today
at 09:58:22 am]
TImage colors incorrect
by
Thaddy
[
Today
at 09:26:22 am]
Any RequestOpenDirectory ...
by
eolandro
[
Today
at 08:50:30 am]
Add additional Components...
by
cdbc
[
Today
at 07:03:25 am]
Creating a SDL child wind...
by
TRon
[
Today
at 06:17:08 am]
String replace or add ' ...
by
Thaddy
[
Today
at 06:14:41 am]
File operations blocking ...
by
atlatl
[
Today
at 05:44:51 am]
Nested declarations insid...
by
440bx
[
Today
at 04:26:28 am]
[solved] triple click
by
dbannon
[
Today
at 01:46:22 am]
SDL2 image rotation Probl...
by
Fred vS
[
Today
at 01:13:15 am]
TRichMemo High Lighted te...
by
What I can do
[January 15, 2025, 11:20:37 pm]
Lazarus/FPC Flatpak appli...
by
Chronos
[January 15, 2025, 09:56:54 pm]
The mouse and using ptcgr...
by
TBMan
[January 15, 2025, 09:15:40 pm]
SDL2: Runtime Error 216 o...
by
TRon
[January 15, 2025, 07:44:59 pm]
Iterator on non-existing ...
by
Warfley
[January 15, 2025, 05:45:03 pm]
Batch "publish" of all pr...
by
MarkMLl
[January 15, 2025, 05:42:45 pm]
[solved] Setting the init...
by
TBMan
[January 15, 2025, 04:28:08 pm]
MQTT Client
by
cdbc
[January 15, 2025, 03:06:25 pm]
Issue getting and setting...
by
d7_2_laz
[January 15, 2025, 02:28:48 pm]
Problem with cell comment
by
kjteng
[January 15, 2025, 02:17:57 pm]
[SOLVED]Troubles when con...
by
bytebites
[January 15, 2025, 01:15:16 pm]
« previous
next »
Print
Pages: [
1
]
Author
Topic: How to invoke an arbitrary method using RTTI? (Read 303 times)
cpicanco
Hero Member
Posts: 655
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