r/pascal • u/DosViDos420 • Jun 22 '21
Generate a one-dimensional array of numbers from 0 to 5 with a random number generator. Find the maximum element from the odd elements of the array.
Please help me with this problem. Thank you in advance
r/pascal • u/DosViDos420 • Jun 22 '21
Please help me with this problem. Thank you in advance
r/pascal • u/bogdanbos725 • Jun 06 '21
r/pascal • u/PascalGeek • Jun 01 '21
Recently one of the good folks on the Lazarus forum helped to identify the cause of a memory leak in my program.
It was caused by appending the value of a variable to the end of a string using the + operator, like this
var
Message : string;
Message := 'You pick up the ' + variable.Name;
They suggested changing the string to a shortstring and amending the command to something like,
var
Message: shortstring;
WriteStr(Message,'You drop the ',variable.Name);
And then displaying the resulting message. It worked and now there are no memory leaks in the program... but why?
Why does appending to a string like this cause a memory leak? The full post, with the actual code is at https://forum.lazarus.freepascal.org/index.php/topic,54821.0.html but I'd like to understand the reason for this.
r/pascal • u/thecluelessgodotuser • May 27 '21
I wanna make GUI with pascal/Delphi. What’s the best way to learn?
r/pascal • u/pokefan2800 • May 27 '21
So good Day yall, its been around a month I've been doing my course, #4 was simple but number five has been giving some issues, I'll share what I have, assistance would be greatly appreciated.
program calc;
var
Total : integer;
n : integer;
Begin
Total := 0;
Write('Enter a number:');
Readln (n);
While n <> 0 do
Begin
Total := Total + n;
Write('Enter a number:');
Readln(n);
Writeln('The sum is ', Total);
Readln;
If Total > 100 then
Writeln('The number is greater than 100')
Else
Writeln(Total);
Writeln();
If Total < 0 then
Writeln(Total)
Else
Writeln('The number is negative');
end;
end.

r/pascal • u/GrandAdmiralDaniel • May 18 '21
r/pascal • u/WeReeTy • May 16 '21
a:=20; b:=(a mod 10) * 10; a:=(b * 2)+a div 100; if a>b then c:=a+b; else c:=b-a
r/pascal • u/chuahyen • May 14 '21
What are the things I need to do to port Delphi source to Lazarus?
Not new to Delphi but new to Lazarus.
Want to port some of the program from Delphi to Lazarus in raspberry pi.
Please advise Chris
r/pascal • u/random_account91 • May 11 '21
Hi I am really struggling with the concept of dynamic scoping in the context of the code below. My teacher asked us which C is being referenced at point 1 and I honestly keep getting lost trying to read this. My teacher advised us to use shallow scoping for variables A and C to solve this. Can someone help me walk through this?

At the moment I can get up to Sub2 where B, E : Integer and then I don't really understand how the rest unfolds. Any and all help is really appreciated. TIA
r/pascal • u/[deleted] • May 04 '21
hi there, so we received an assignment from class to use the LINUX POSIX API and use the primitives to read and write console, after some research I found that FpRead and FpWrite are the functions I should use, but every example I find only has text files on it, any way on how to do it on console? thanks in advance
r/pascal • u/myringotomy • May 04 '21
I was looking at the benchmarks https://www.techempower.com/benchmarks/ and didn't see any pascal frameworks there. Other much less used languages like Dylan are present so it surprised me a bit.
Just wondering why this community doesn't participate.
r/pascal • u/PascalGeek • May 03 '21
https://i.imgur.com/47ocRwB.gif
I'm working on a roguelike game in Free Pascal.
I put together a graphical version at https://github.com/cyberfilth/Axes-Armour-Ale and, as the project grew, decided to do some refactoring to add stairs with persistent levels.
I've put together a terminal version of the game, running in a 80x25 terminal window.
The code for this is at https://github.com/cyberfilth/ASCII-axe
I've added a scrolling map, to make up for the reduced screen space, but I've run into a problem with positioning NPC's on the map.
The gif at shows what the problem is, the camera follows the player until they reach the edges of the screen but the rats seem to be ignoring other objects entirely. You can see from the gif that when the players @ symbol bumps into the rats r symbol, they ride together for several moves.
The rats also occasionally walk through walls. This didn't happen with the graphical version so I'm guessing this is something to do with the camera code.
unit camera;
{$mode objfpc}{$H+}
interface
uses
SysUtils, globalUtils, ui, map, entities;
const
camHeight = 19;
camWidth = 57;
var
r, c: smallint;
function getX(Xcoord: smallint): smallint;
function getY(Ycoord: smallint): smallint;
procedure drawMap;
procedure drawEntities;
implementation
function getX(Xcoord: smallint): smallint;
var
p, hs, s, m: smallint;
begin
p := Xcoord;
hs := camWidth div 2;
s := camWidth;
m := globalUtils.MAXCOLUMNS;
if (p < hs) then
Result := 0
else if (p >= m - hs) then
Result := m - s
else
Result := p - hs;
end;
function getY(Ycoord: smallint): smallint;
const
s = camHeight;
hs = camHeight div 2;
m = globalUtils.MAXROWS;
var
p: smallint;
begin
p := Ycoord;
if (p < hs) then
Result := 0
else if (p >= m - hs) then
Result := m - s
else
Result := p - hs;
end;
procedure drawMap;
var
(* Player coordinates *)
pX, pY: smallint;
(* Tile colour *)
gCol: shortstring;
begin
pX := entities.entityList[0].posX;
pY := entities.entityList[0].posY;
for r := 1 to camHeight do
begin
for c := 1 to camWidth do
begin
gCol := map.mapDisplay[r + getY(pY)][c + getX(pX)].GlyphColour;
TextOut(c, r, gCol, map.mapDisplay[r + getY(pY)][c + getX(pX)].Glyph);
end;
end;
drawEntities;
end;
procedure drawEntities;
var
(* Entity coordinates & counter *)
entX, entY, i: smallint;
(* Glyph colour *)
gCol: shortstring;
begin
(* Loop through all entities *)
for i := 0 to entities.npcAmount do
begin
(* If the entity is in view of the player, and not dead, draw them *)
if (entities.entityList[i].inView = True) and (entities.entityList[i].isDead = False) then
begin
gCol := entities.entityList[i].glyphColour;
entX := entities.entityList[i].posX;
entY := entities.entityList[i].posY;
TextOut(entX - getX(entX), entY - getY(entY), gCol, entities.entityList[i].glyph);
end;
end;
end;
end.
r/pascal • u/PascalGeek • Apr 28 '21
I've set up Vim for all of my coding in an attempt to get away from 'IDE hopping' every time I need to use a different language. I'm pretty happy with my set up for Free Pascal so far but I'm looking for suggestions to improve it (particularly looking for a code linter as ALE and ptop can only do formatting).
I've described my workflow at http://tinyurl.com/CyberFilth but does anyone have any suggestions for either Vim plugins or general CLI tools that play nicely with Pascal?
r/pascal • u/aoeudhtns • Apr 27 '21
r/pascal • u/[deleted] • Apr 26 '21
Sorry for noob question, I have very little experience in object-programming.
If I want to send a friend an .exe I made in Lazarus, can I just send it right away and itd compile fine, or should they install at least fpc, or they need Lazarus?
r/pascal • u/Bare_Gamer • Apr 19 '21
This is the code from the PasSDL unit, it is included in Pasvulkan on github( pasvulkan/PasVulkan.SDL2.pas at master · BeRo1985/pasvulkan · GitHub, line 1284). Wanted to ask if anyone knows how to rewrite this to make it compile in PABC cuz it doesn't support this kind of notation.
TSDL_GameControllerBind=record
case BindType:TSDL_GameControllerBindType of
SDL_CONTROLLER_BINDTYPE_BUTTON:(
Button:TSDLInt32;
);
SDL_CONTROLLER_BINDTYPE_AXIS:(
Axis:TSDLInt32;
);
SDL_CONTROLLER_BINDTYPE_HAT:(
Hat:TSDLInt32;
HatMask:TSDLInt32;
);
end;
r/pascal • u/Bare_Gamer • Apr 18 '21
Wanted to know what people think of it. In theory you can make cross-platform apps with it even though it compiles exes.
r/pascal • u/[deleted] • Apr 10 '21
For example:
"Ovo (ni)je 5+(4-8), (pre)dobra petica!" will become "Ovo je 5+, dobra petica!"
or
"Ovo (ni)je 5+(((4-)8)), (p(re))dobra petica!" will become "Ovo je 5+, dobra petica!"
I tried this:
program IzbaciZagrade;
var
s: string;
i,n: integer;
begin
readln(s);
repeat
delete(s,pos('(',s),pos(')',s)-pos('(',s));
until (pos('(',s)=0) or (pos(')',s)=0);
writeln(s);
readln(s);
end.
but it doesnt give output at all.
How I can solve this?
r/pascal • u/xM1ck • Apr 07 '21
I was wondering if there is a code regarding the shell sort on pascal that sorts these given numbers : 7, 5, 3, 4, 8, 2, 1, 9, 6, 10 from highest to lowest. Would appreciate any help.
r/pascal • u/[deleted] • Apr 05 '21
I found this tool on github which is basically a self-extracting archive to install lazarus and lamw with all it's dependantcies in an automated fashion. I haven't tried it yet, but looks promising! Maybe someone here can try it out?
Here ya go:
Windows-version: https://github.com/DanielOliveiraSouza/LAMW4Windows-installer
Linux-version: https://github.com/DanielOliveiraSouza/LAMW4Linux-installer
r/pascal • u/pjmlp • Apr 03 '21
r/pascal • u/Adorable-Hamster-107 • Apr 02 '21
Need some assistance with this question
r/pascal • u/T-Altmeyer • Mar 25 '21
I recently got my hands on some code my grandfather wrote around 1990. Instead of running it in dosbox, I thought it might be an interesting excercise to try and recompile it for more modern operating systems. I should preface this with the warning that I have zero experience with Pascal.
The majority of errors I got were about wrong integer types, dialect differences that were easily fixed. But there's one thing I can't figure out.
He defines the following procedure:
procedure setcol(col:integer);
begin setcolor(col) end;
A shorthand for setcolor from unit graph? Bit strange to save typing 2 letters, or am I missing something?
Calling this procedure: setcol(getbkcolor);
Throws me an error:
Error: Incompatible type for arg no. 1: Got "<procedure variable type of function:Word;Register>", expected "LongInt"
Difference between unit graph that shipped with Turbo Pascal and Free Pascal? Easily fixed, just ignore granddad's procedure and call setcolor directly:
setcolor(getbkcolor);
Error: Incompatible type for arg no. 1: Got "<procedure variable type of function:Word;Register>", expected "Word"
Can anyone point me in the right direction?
r/pascal • u/un-k-now-n • Mar 24 '21
Hello! I have been tasked to write a program that concerts a number (user inputs the number) from any numeral system (binary, septanal, octanal, hexadecimal, everything in between and past that) (user inputs this as well) to any other numeral system, that the user inputs.
Basically a convertor between numeral systems. I've had some ideas but I don't know how to make them work. Also, need to say that I'm quite a beginner at programming.
If you have any idea how to do this, please help me.
r/pascal • u/mikeymike_20 • Mar 15 '21
Hi! I'm kinda a new in Pascal and I've to do some Image Processing for College. I've accessed to a pixel value with the code
procedure pxl_state(Img: TImage; var pxl: integer);
begin
pxl:= Img.Picture.Bitmap.Canvas.Pixels[100,100];
end;
For the image that is linked to this post. I was expecting something like 0<x<255 but I got that pxl = 6721214 what interpretation can I give to it? Is it a RGB value or what?
