Recent

Author Topic: record structure display while editing question  (Read 1396 times)

440bx

  • Hero Member
  • *****
  • Posts: 4305
record structure display while editing question
« on: May 09, 2024, 06:49:15 am »
Hello,

consider code where the following declaration exists:
Code: Pascal  [Select][+][-]
  1. const
  2.   FlagLabelValues : array[TFLAG_LABEL_IDS] of pchar =  { index: flvi          }
  3.   (
  4.    { fli_actions                        } 'ACTIONS:',
  5.    { fli_read                           } 'READ:',
  6.    { fli_written                        } 'WRITTEN:',
  7.  
  8.    { fli_carry_flag                     }   'CF: ',
  9.    { fli_parity_flag                    }   'PF: ',
  10.    { fli_auxiliary_carry_flag           }   'AF: ',
  11.    { fli_zero_flag                      }   'ZF: ',
  12.    { fli_sign_flag                      }   'SF: ',
  13.    { fli_trap_flag                      }   'TF: ',
  14.    { fli_interrupt_enable_flag          }   'IF: ',
  15.    { fli_direction_flag                 }   'DF: ',
  16.    { fli_overflow_flag                  }   'OF: ',
  17.    { fli_io_privilege_level             } 'IOPL: ',
  18.    { fli_nested_task_flag               }   'NT: ',
  19.    { fli_resume_flag                    }   'RF: ',
  20.    { fli_virtual_8086_mode_flag         }   'VM: ',
  21.    { fli_alignment_check_flag           }   'AC: ',
  22.    { fli_virtual_interrupt_flag         }  'VIF: ',
  23.    { fli_virtual_interrupt_pending_flag }  'VIP: ',
  24.    { fli_cpuid_instruction_flag         }   'ID: '
  25.   );
  26.  

when debugging, hovering on the presence of that identifier will cause a popup window to show the values in the array (see attachments.)

when editing, hovering on the the identifier displays a very abbreviated version of the array (see attachments.)

Is there a way to tell the editor to show the entire array (or at least more than just its definition) ?

Thank you for your help.


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Khrys

  • New Member
  • *
  • Posts: 35
Re: record structure display while editing question
« Reply #1 on: May 09, 2024, 07:46:09 am »
I'm afraid this isn't possible - here's why:

const  symbols in Free Pascal actually come in two flavors: typed and untyped constants:

Code: Pascal  [Select][+][-]
  1. const
  2.   ALPHA = 1;          // Untyped constant
  3.   BETA: Integer = 2;  // Typed constant (Integer)

Untyped constants are truly constant; their value can never be changed under any circumstances. They are similiar to  #define  macro constants in C in that they are basically textually substituted in the source code (with some exceptions), and as a consequence it isn't possible to i.e. take the address of an untyped constant.

Typed constants on the other hand aren't really constant at all: with the  {$WRITABLECONST}  modeswitch disabled ({$J-}, which is the default behaviour!) typed constants can be reassigned as you wish - they behave pretty much exactly like (static) variables (ability to take address, generates linker symbol etc.). For example, this is perfectly legal code:

Code: Pascal  [Select][+][-]
  1. procedure DoSomething();
  2. const
  3.   CallCounter: Integer = 0;
  4. begin
  5.   // Do some work...
  6.   CallCounter += 1;
  7.   WriteLn(Format('DoSomething() was called %d time(s) so far', [CallCounter]));
  8. end;

In C you'd use a static variable for this purpose:

Code: C  [Select][+][-]
  1. void do_something()
  2. {
  3.     static int call_counter = 0;
  4.     // Do some work...
  5.     call_counter++;
  6.     printf("do_something() was called %d time(s) so far\n", call_counter);
  7. }

So, the point I'm trying to make is this: Typed constants under the hood are indistinguishable from regular variables to the compiler, so in essence what you're asking the IDE to display when hovering is the value of a variable, which of course is only possible at runtime. Note that in the popup while debugging, memory addresses are shown.

The solution to this would be to use untyped constants, but unfortunately those can only be ordinals, floats, sets, chars, strings and the  nil  pointer - no arrays.

440bx

  • Hero Member
  • *****
  • Posts: 4305
Re: record structure display while editing question
« Reply #2 on: May 09, 2024, 08:00:16 am »
Hi Khrys,

Thank you for the reply.  Maybe I wasn't clear.  I just want the editor to show me what was typed, nothing else.  IOW, I don't want any operation done on the array, just a little popup that shows the text that defines the array.

Yet, IOW, instead of having to jump to its definition (by right clicking and jumping to it) and then coming back to the original spot, I just want the editor to show the definition in a little popup window (saves having to jump there and back.)


(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Khrys

  • New Member
  • *
  • Posts: 35
Re: record structure display while editing question
« Reply #3 on: May 09, 2024, 09:11:51 am »
Oh, you mean a preview of the source... my bad  :-[

Yes, that would be really convenient actually. You mentioned right-click jump, that's a hassle for sure... I usually do  CTRL + left click  and then jump back with  CTRL + H  or one of those extra buttons my mouse has (two buttons near the thumb that allow jumping back and forth - not only in browsers, but also in Lazarus)

440bx

  • Hero Member
  • *****
  • Posts: 4305
Re: record structure display while editing question
« Reply #4 on: May 09, 2024, 09:29:03 am »
Oh, you mean a preview of the source... my bad  :-[
Don't worry about it.  I re-read what I wrote in my OP and, on second thought, I don't think I made it really clear what I was looking for.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10063
  • Debugger - SynEdit - and more
    • wiki
Re: record structure display while editing question
« Reply #5 on: May 09, 2024, 03:03:39 pm »
I am not aware of such a feature.

Currently, indeed the value in the debug hint comes from the debugger.
I.e., from the running executable and/or the debug info associated with it => that is either the memory of the process or from hardcoded info in the debug info in the exe file on disk.

In theory codetools could be extended to read the source before the hint, and display such code. Other than "in theory" I can't comment on it.

Well that, and that I personally would not want such a feature to be active in my setup. I prefer the small hint (for the few cases when I actually use hints).
If I need to see sources, then I have them open in a 2nd (or 3rd or 4th even 5th...) Source-editor window. (my 2 cents)

440bx

  • Hero Member
  • *****
  • Posts: 4305
Re: record structure display while editing question
« Reply #6 on: May 09, 2024, 03:49:50 pm »
Thank you Martin.

Since the editor can currently show a small hint, I wondered if there was an option to make it show more than just that one-liner definition.

If I need to see sources, then I have them open in a 2nd (or 3rd or 4th even 5th...) Source-editor window. (my 2 cents)
Normally I do the same but, sometimes I just need a quick memory refresh and going to a different window and locating the definition I'm interested in is "a lot of work" for something that could potentially be done very quickly.

FWIW, I got used to that feature from using IDA Pro.  In IDA Pro, hovering over a number of identifiers causes it to show the text associated with the identifier, e.g, hovering over a function name causes it to display some of the beginning instructions.  I find the feature useful and I miss it when coding because it saves time (no need to jump around in the code or go to another window.)

It's nice to know the feature isn't available.  At least I know the reason I don't have it isn't because I've missed setting an editor's option to the appropriate value somewhere.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10063
  • Debugger - SynEdit - and more
    • wiki
Re: record structure display while editing question
« Reply #7 on: May 09, 2024, 04:15:47 pm »
This is the info, I currently have on those hints. https://wiki.lazarus.freepascal.org/Lazarus_IDE_Tools#Hints_from_comments

440bx

  • Hero Member
  • *****
  • Posts: 4305
Re: record structure display while editing question
« Reply #8 on: May 09, 2024, 04:38:35 pm »
This is the info, I currently have on those hints. https://wiki.lazarus.freepascal.org/Lazarus_IDE_Tools#Hints_from_comments
That's good information, thank you Martin.

Now I have another question, I figured I'd have a look at the "parent page" https://wiki.lazarus.freepascal.org for other potentially useful information.  I noticed that the parent page does not have a link to the "Lazarus IDE Tools" page.  Is that an unintended omission or is that page reachable in some way I missed ?
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10063
  • Debugger - SynEdit - and more
    • wiki
Re: record structure display while editing question
« Reply #9 on: May 09, 2024, 04:58:45 pm »
Not sure what you mean by "parent page"?  The wiki isn't strictly organized as a "tree".

The main page certainly can't link to every page within the wiki. And as the wiki has lots of different content on Fpc and Lazarus it is expected that most of it isn't on the main page.

I don't know what the odds are on getting that changed. Probably not for that single page, don't know if an entry point (e.g. portal?) could be created, and what the requirements would be.

But other than linking it from the main page => it's a wiki. Open for improvement.

Quote
I figured I'd have a look at the "parent page" https://wiki.lazarus.freepascal.org for other potentially useful information.
Probably easier to follow the category pages (at the bottom of the page). Though they may need maintenance too.

In the IDE itself, many of the IDE Windows support F1 to take you to (old) wiki pages.

And (from my current signature) https://wiki.lazarus.freepascal.org/New_IDE_features_since

440bx

  • Hero Member
  • *****
  • Posts: 4305
Re: record structure display while editing question
« Reply #10 on: May 09, 2024, 05:04:21 pm »
Good stuff to know... thank you Martin.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018