0

I am programming in Pascal (compiling with the Free Pascal IDE) but I imagine the following issue could be in all programming languages, whether you have to declare variables or not.

In Pascal you have to declare your variables before you can use them. They can only be declared at the top of a function/procedure or, in the case of global variables, at top of the main program.

As my program got longer over the past year and more and more variables were declared, I have had to scroll back up all the time to check which variables I have declared in order to use them in a function or main part of the program.

Is there any solution to not have to scroll back up all the time?

Putting variables in a separate unit file and having the file opened next to the main program file is the only thing I can think of, but at this stage I have too many functions and classes to shift everything around that way. Too much rework of the code would have to be done.

Seb0029
  • 69
  • 8
  • 1
    Any decent IDE should (1) list the available variables when you press Ctrl+Space, Tab or something similar, (2) display a tooltip informing you about a variable's type and place of declaration when the cursor is hovering above it, and (3) take you to the variable's place of declaration when you Ctrl-Click it (or, for instance, press Ctrl+G with the caret in it). – Andreas Rejbrand Jun 28 '20 at 18:30
  • I use Notepad++ to program and use the IDE to compile and run. Searching the internet just now, I found out Notepad++ had a planned function list feature that has not been released yet. The Free Pascal IDE does not have the functionalities you mentioned. Your comment has pointed me in the right direction though. Thanks! – Seb0029 Jun 28 '20 at 18:37
  • 1
    The Free Pascal IDE is a IDE based on a Turbo Vision clone. So more TP than Delphi. Lazarus is the Delphi alike. – Marco van de Voort Jun 29 '20 at 11:31

2 Answers2

1

In Lazarus, the freeware and excellent IDE for FPC[1], there is a simple way to do this:

  • Place the mouse over a variable

  • If the variable has been declared, the IDE will visually mark it

  • If it is marked, single-clicking the variable will take you straight to where it is declared.

More generally, when you hover the mouse over a variable, the IDE will change its background color to something like light grey[2], including any other occurrences of it which are on-screen at the time, so by itself this is sufficient to locate the variable's declaration site if it happens to be on-screen, as it often is if the variable is a local.

[1] I don't know why anyone would use Notepad++ or another IDE for FPC considering how good Lazarus is.

[2] The top and bottom pixel rows of the changed background color are drawn darker than the others, which makes it look rather like (wearing my spectacles) the variable name is underlined.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • I have never used Lazarus. I started programming in the Turbo Pascal IDE in 2003 (started programming for the first time in 1997 at the age of 12) then a few years later in regular Notepad, then a few years after that I searched online for free text editors with Pascal support and found Notepad++. I am self-taught since the age of 12 (23 years ago) in a place and time where I did not have access to the internet. I worked with whatever I could get. A friend of the family gave me a cd that had turbo pascal on it. I'll give Lazarus a try. Thanks. – Seb0029 Jun 29 '20 at 16:25
  • Well, when you said in your q "compiling with the Free Pascal IDE", I wondered whether you meant Lazarus, because I'm not aware of anything else that could be described as *the* FPC IDE. The Delphi IDE is also very good - I use it myself all the time - but I'm not sure whether using its IDE with FPC complies with the licence for the Delphi Community (free) Edition. – MartynA Jun 29 '20 at 16:40
  • fpc-2.6.2.i386-win32.exe (https://sourceforge.net/projects/freepascal/files/Win32/2.6.2/) is what I use to compile. I've just installed Lazarus now but it's not compiling my program because it cannot find some of the dll files I'm using, eventhough they are in the same folder in which the program file is. Did some quick search online and cannot find a solution. – Seb0029 Jun 29 '20 at 19:25
  • f you program isn't compiling, which "program file" and DLL are in the same directory as one another? And wat is the **exact** error message Lazarus reports when the compilation fails? – MartynA Jun 29 '20 at 19:40
  • Program file: rpg4.pas; DLL files: SDL2.dll, SDL2_image.dll, SDL2_mixer.dll, SDL2_ttf.dll. Error: "Cannot find sdl2 used by rpg of the Project Inspector". – Seb0029 Jun 29 '20 at 19:45
  • Well, that can't be sorted out in the comments to an unrelated q, which this is. I suggest you post your compilation problem as a new q inlcuding a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – MartynA Jun 29 '20 at 19:49
  • Hasn't this - or the other answer - answered your q? – MartynA Jul 01 '20 at 13:52
0

Delphi IDE although a paid solution offers free community packages for students and such. i had a great time using it for my college assignments. its more user friendly as I had a lot of trouble navigating Lazarus. on delph I there is a side-panel that shows you all your stated variables,constants,uses,procedures and more.

Helper Shoes
  • 133
  • 7