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
New Splash Screen For Laz...
by
Tony Stone
[
Today
at 02:39:58 am]
Common File Dialogs Have ...
by
TRon
[
Today
at 02:06:32 am]
Possible to do this? (aca...
by
Warfley
[
Today
at 01:49:49 am]
AVRPascal – free code edi...
by
VisualLab
[
Today
at 01:14:40 am]
How to load dylib for fpw...
by
TRon
[
Today
at 01:12:31 am]
How to draw some rectangl...
by
Warfley
[
Today
at 01:05:00 am]
/lib/arm-linux-gnueabihf/...
by
TRon
[November 05, 2024, 11:55:38 pm]
Open Another Form LAMW An...
by
c4p
[November 05, 2024, 10:22:20 pm]
Camera OCR / Sorting / AI...
by
marcov
[November 05, 2024, 10:15:03 pm]
Binary String to Integer ...
by
MathMan
[November 05, 2024, 08:27:00 pm]
CalcEdit I think this is ...
by
wp
[November 05, 2024, 08:10:35 pm]
Lazarus have if_variant. ...
by
d2010
[November 05, 2024, 06:45:17 pm]
Lazarus Release Candidate...
by
LBox
[November 05, 2024, 06:35:54 pm]
Fields Editor hangs
by
Roald
[November 05, 2024, 06:13:16 pm]
Access violation whenever...
by
carl_caulkett
[November 05, 2024, 05:04:59 pm]
How to really prevent a c...
by
rvk
[November 05, 2024, 05:03:52 pm]
Confusion with signed typ...
by
marcov
[November 05, 2024, 05:03:15 pm]
[SOLVED] Synapse: How to ...
by
rvk
[November 05, 2024, 04:26:12 pm]
Required packages dependi...
by
korba812
[November 05, 2024, 03:17:49 pm]
Migrating GameWork first ...
by
dng8888g
[November 05, 2024, 01:32:12 pm]
Sending a signal/message ...
by
Thaddy
[November 05, 2024, 11:42:51 am]
Cross compiling
by
Thaddy
[November 05, 2024, 11:41:26 am]
Building a packet from sc...
by
Remy Lebeau
[November 05, 2024, 11:09:46 am]
Name of calling procedure...
by
Khrys
[November 05, 2024, 10:39:24 am]
Zooming and Panning in a ...
by
cdbc
[November 05, 2024, 07:27:43 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: How to invoke an arbitrary method using RTTI? (Read 211 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