Recent

Author Topic: Show source code comments during runtime ?  (Read 732 times)

FrankBKK

  • New Member
  • *
  • Posts: 41
Show source code comments during runtime ?
« on: July 24, 2024, 10:49:58 am »
Is there a way to show source code comments (or certain code parts, defined by e.g. line# or procedure name)
during runtime of the compiled program ?

I can of course open the source code during runtime as text file, filter what I need and show it for example in a memo,
but can this be achieved without having access to the source code during runtime ?








Thaddy

  • Hero Member
  • *****
  • Posts: 16145
  • Censorship about opinions does not belong here.
Re: Show source code comments during runtime ?
« Reply #1 on: July 24, 2024, 10:52:18 am »
No. FPC is a compiled language.
BUT during debugging of course this is possible. The debugger synchronizes that, depending on settings.
If I smell bad code it usually is bad code and that includes my own code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8007
Re: Show source code comments during runtime ?
« Reply #2 on: July 24, 2024, 11:09:14 am »
You can, however, do something like

Code: [Select]
WriteLn(stderr, 'Entering ' + {$I %CURRENTROUTINE%} + '(), ' + {$I %FILE% } + ' line ' + {$I %LINE% });

i.e. instruct the compiler to insert certain information into a string.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

FrankBKK

  • New Member
  • *
  • Posts: 41
Re: Show source code comments during runtime ?
« Reply #3 on: July 24, 2024, 11:40:23 am »
Thanks Mark, I will give it a try ...

MarkMLl

  • Hero Member
  • *****
  • Posts: 8007
Re: Show source code comments during runtime ?
« Reply #4 on: July 24, 2024, 12:22:58 pm »
Various languages which are interpreted or semi-interpreted (i.e. not fully-compiled, Thaddy's point) will allow you to recover ("reflect upon") the source and/or Abstract Syntax Tree without reference to the original source files; in some cases this may be manipulated. This does not include mainstream compilers.

The above is somewhat beginner-friendly. The remainder is not.

You will, in some cases, be able to get access to RTTI information, but this definitely does not include descriptive comments. You might also be able to use debugging information to cross-reference- to some extent- between a location in memory and a sourcecode line.

You will also be able to use an external debugger to generate a backtrace from the point at which a program dumps its state an exception etc.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

CCRDude

  • Hero Member
  • *****
  • Posts: 611
Re: Show source code comments during runtime ?
« Reply #5 on: July 24, 2024, 12:53:24 pm »
... filter what I need and show it for example in a memo ...

This is a yet unspecified part :)

What do you need?

RTTI and debug information (e.g. unit lineinfo) have already been mentioned; I want to throw in Custom Attributes, which are a great way to define a lot of additional data that can be used during runtime. If you're just looking at classes or published properties, you can define your custom "comment" attribute and have that available during runtime.

 

TinyPortal © 2005-2018