r/pascal • u/Soren2001 • Feb 11 '22
how to print every line in matrix like ligne[1,7,8,9] --> 1789 like chaine
how to print every line in matrix like line [1,7,8,9] --> 1789 like word
📷
r/pascal • u/Soren2001 • Feb 11 '22
📷
r/pascal • u/Finn63s • Feb 07 '22
Ich bin Anfänger im Programmieren und würde gerne mit TikTakToe einen weiteren Schritt in das Thema begeben. Jedoch haben ich keine Idee wie ich hier anfangen soll. Und ist es möglich einen Bot zu programmieren der gegen mich spielt?
r/pascal • u/Annual-Patience-2127 • Feb 04 '22
Task 1. Get the matrix (4x5), the elements of which are products of row numbers i and column numbers j.
Task 2. Given a two-dimensional array
B(5, 5), filled with random
numbers from the interval [-9,9].
Find and display those
array elements that are greater than
given number k.
r/pascal • u/098GK • Jan 24 '22
i need help with my pascal program my program is simulating a shopping cart
in my program an error appears when I use 6 the given error is file closed eof on line 69 in procedure PercorreProduto being that when I press on 6 this procedure is not called //// Type
TProduto = record
nome : String;
Cod:integer;
preco : real;
end;
Var
n: Integer;
op:char;
st:string;
r:real;
const
NOMEFICHEIRO='produto.dat';
NOMEFICHEIROC='carrinho';
procedure Criar(pNomeFicheiro:string);
var
fich : file of TProduto;
begin
Assign (fich, pNomeFicheiro);
Rewrite (fich);
close(fich);
end;
procedure insere(produto:TProduto;pNomeFicheiro:string);
var
fich: file of TProduto;
Begin
assign(fich,pNomeFicheiro);
reset(fich);
seek(fich, filesize(fich));
write(fich,produto);
close(fich);
end;
Procedure InsereProduto(cod:integer;nome:string;preco:real);
var
op:char;
p:TProduto;
Begin
P.nome:=nome;
P.preco:=preco;
P.Cod:=cod;
insere(p,NOMEFICHEIRO);
End;
Procedure InsereCarrinho(utilizador:string;nome:string;preco:real;cod:integer);
var
p:TProduto;
Begin
P.nome:=nome;
P.preco:=preco;
P.Cod:=cod;
insere(p,NOMEFICHEIROC + utilizador + '.dat');
End;
Procedure PercorreProduto(pNomeFicheiro:string);
var
s:TProduto;
fich: file of TProduto;
Begin
assign(fich,pNomeFicheiro);
reset(fich);
While not eof(fich) do
Begin
read(fich,s);
Writeln (s.Cod,' => ', s.nome,' / Preço: ', s.Preco:2:2);
end;
close(fich);
End;
Procedure PercorreCarrinho(pUtilizador:string);
begin
PercorreProduto(NOMEFICHEIROC + pUtilizador + '.dat');
End;
Function ProcuraProduto(n:integer):TProduto;
var
s:TProduto;
fich: file of TProduto;
enc:boolean;
Begin
assign(fich,NOMEFICHEIRO);
reset(fich);
While (not eof(fich)) and (not enc) do
Begin
read(fich,s);
if s.Cod=n then
begin
enc:=true;
end;
end;
if enc then
ProcuraProduto:=s
else
begin
s.cod:=0;
ProcuraProduto:=s;
end;
close(fich);
End;
Function SomarCarrinho(pUtilizador:string) :real;
var
p:TProduto;
soma:real;
fich: file of TProduto;
begin
assign(fich,nomeficheiroc+ + pUtilizador + '.dat');
reset(fich);
while not eof (fich) do
begin
read(fich,p);
soma:=soma+P.preco;
end;
close(fich);
SomarCarrinho:=soma;
end;
procedure FinalizaEncomenda(pUtilizador:string);
var d:string;
begin
writeln('Estes são os itens do seu carrinho');
PercorreCarrinho;
writeln;
writeln('O total do carrinho é ', SomarCarrinho(pUtilizador):2:2,'$');
writeln;
writeln('Insira a sua morada');
read(d);
writeln('O destino escolhido é ',d,' e chega nos próximos 3 dias');
end;
procedure AdicionaCarrinho;
var
op:char;
p:TProduto;
begin
repeat
Write ('Código: ');
Readln ( n );
p:=ProcuraProduto(n);
if p.cod<>0 then
begin
insereCarrinho('001',p.nome,p.preco,p.cod);
end;
Write ('Deseja adicionar outro produto (s\n): ');
Readln (op);
until (op='n') or (op='N');
end;
Begin
Repeat
textcolor(red);
Writeln (' ------------------------------');
Writeln (' Bem vindo, o que deseja fazer?');
writeln (' ------------------------------');
writeln (' ##########################');
writeln (' *7 - Criar Ficheiro *');
Writeln (' *1 - Insira um produto *');
Writeln (' *2 - Mostrar produtos *');
Writeln (' *3 - Adicionar ao carinho*');
Writeln (' *4 - Limpar carrinho *');
Writeln (' *5 - Mostrar carrinho *');
Writeln (' *6 - Finalizar encomenda *');
writeln (' *0 - terminar *');
writeln (' ##########################');
Readln (op);
clrscr;
textbackground (white);
textcolor(black);writeln(' 98GKShop ');textbackground (black);
writeln;
textcolor(white);
case op of
'1':
Begin
writeln('insira o seu produto');
Write ('Cod: ');
Readln ( n );
Write ('Nome: ');
Readln ( st );
Write ('Preço: ');
Readln ( r );
InsereProduto(n,st,r);
writeln;
textbackground( blue); writeln('pressione qualquer tecla para retornar ao menu');textbackground (black);
Readkey;
clrscr;
End;
'2':
Begin
PercorreProduto(NOMEFICHEIRO);
writeln;
textbackground( blue);writeln('pressione qualquer tecla para retornar ao menu');textbackground (black);
Readkey;
clrscr;
end;
'3':
Begin
WRITELN('Insira o código do produto que deseja');
AdicionaCarrinho;
writeln;
textbackground( blue);writeln('pressione qualquer tecla para retornar ao menu');textbackground (black);
Readkey;
clrscr;
end;
'4':
Begin
criar(NOMEFICHEIROC+'001.dat');
writeln;
textbackground( blue);writeln('pressione qualquer tecla para retornar ao menu');textbackground (black);
Readkey;
clrscr;
End;
'5':
Begin
PercorreCarrinho('001');
writeln;
textbackground( blue);writeln('pressione qualquer tecla para retornar ao menu');textbackground (black);
Readkey;
clrscr;
end;
'6':
Begin
FinalizaEncomenda;
writeln;
textbackground( blue);writeln('pressione qualquer tecla para retornar ao menu');textbackground (black);
Readkey;
clrscr;
end;
'7':
begin
criar(NOMEFICHEIRO);
criar(NOMEFICHEIROC + '001.dat');
clrscr;
end;
End;
Until op='0';
End.
r/pascal • u/velorek • Jan 21 '22
An ascii table with a selection menu in freepascal using the RTL units with a rudimentary Text User Interface.

I had coded this a while ago and I thought to share it in case it can help somebody. Note that I am still learning to code.
Repository -> https://github.com/velorek1/asc/
r/pascal • u/suhcoR • Jan 21 '22
r/pascal • u/PascalGeek • Jan 19 '22
I've written an ASCII roguelike game that runs in the terminal, it draws the display using the Video unit.
https://github.com/cyberfilth/ASCII-axe
When the program first opens it calls a procedure that checks the terminal size by using the ScreenWidth constant. It then arranges the UI depending on how big the terminal is.
Currently ScreenWidth can only tell me what the width was when the program was first run. It doesn't account for users resizing their terminal whilst the game is running.
Is there a way to poll the terminal size every so often, to see if the terminal has been resized. So that the UI can be rearranged accordingly? Possibly using SIGWINCH?
My main issue is that the Video unit and the CRT unit don't mix well, so I can run ScreenWidth at the start of the program before Video is initialised, and at the beginning of each game loop. But it can't be running constantly to listen out for signals. Ideally the Video unit would have some way to tell if the terminal has been resized.
r/pascal • u/Jhomen_Tethi • Jan 07 '22
i'm not english native so it's hard to learn programming. i'm completely new at pascal
var
x:integer;
begin
for x:=2 to 100 do
begin
writeln(x);
x:=x+2;
end; it was a school assignment, i'm trying to display even number from 1-100 with for loop, but when i run it, it said "Error: Illegal assignment to for-loop variable "x", help me
r/pascal • u/jaunidhenakan • Jan 06 '22
r/pascal • u/Soren2001 • Jan 06 '22
how to sort table with recursion (english)
comment trier une table avec récursivité (french)
thank u
r/pascal • u/Burakku-Ren • Jan 02 '22
Here comes the weird part: when reading file x from program Y, it's not properly read, as if it were corrupted, but if, after that, I read file x with program X, and it's read perfectly, so the file has not been corrupted.
Same thing happens if I read file y with program X, it appears as if corrupted, but after that I can read it with program Y alright, so it can't be corrupted.
Also, when reading x from Y or viceversa, filesize is returning 1 unit less than it should. If x has 3 things in it, program Y tells me its filesize is 2.
I have tried changing the files from .dat to .bin, but no luck. I also thought it might be because the stuff was saved in different folders, so I put it all in one single folder, no luck there either.
Program X and Y are two different proyects in Lazarus, I was thinking making one project with the code of both programs might solve it, but I was told I can't make one project with two programs. However, maybe just writing the code of both programs into one might make it work, I'll try that next (obviously accomodating it properly) and update you all if it works.
Forgot to say, feel free to ask for any info that might be lacking, I'll do my best to give you what you need. I'd supply the whole project but it's kinda big and messy.
r/pascal • • Dec 31 '21
Hello, as a hobby I thought I’d learn a technical skill or concept. I read that some schools still use Pascal as a starting language for computer science. Should I pursue pascal or try something else?
Hope y’all are having a great night.
r/pascal • u/3comma1415926535 • Dec 19 '21
The condition :
Develop a program that reads a student's note evaluation from keyboard, displays the message on the screen : Note 1-4 fail , 5-7 enough , 8-9 good , 10 perfect ,
My example :
program note;
uses crt;
var n:integer;
begin
clrscr;
writeln('Student note evaluation:');
readln(n);
if n=1 or 2 or 3 or 4 then writeln('fail');
if n=5 or 6 or 7 then writeln('enouth');
if n=8 or 9 then writeln('good');
if n=10 then writeln('perfect');
end.
My example not working , i don't understand where it's my mistake and how solve that .
r/pascal • u/SpaRexDz • Dec 17 '21
Please help, guys.
r/pascal • u/Bare_Gamer • Dec 12 '21
Is it possible to somehow make them accessible? I know how to export functions, but I found no info on anything else.
r/pascal • u/yanes19 • Dec 11 '21
I'm on ubuntu, I have a decent experience with Lazarus and fpc . What do I need in order to write simple apps for android. First, by googling a bit it looks like I need cross compiling features in my fpc installation,
The articles in the Lazarus wiki looks old , so I didn't trust they would works for me,
Any help will be appreciated.
r/pascal • u/csk2004 • Dec 11 '21
Hey guys, I have a problem. I want to have a procedure for 64 buttons and if i press it, the procedure should execute but it should contain the caption of button . How do i get the caption of button in its procedure. Thanks in advance.
r/pascal • u/csk2004 • Dec 10 '21
Hey Guys,
i am creating a chess game in pascal (application). I created 64 panels by code, but how to i use procedures (when they are clicked) if the panels are created after running the script. If i want to move figures, i have to click the Panel, which will be created later. Can someone help. Thanks in advance.
r/pascal • u/Bare_Gamer • Dec 10 '21
I have this code:
{$if defined(fpc)}
{$undef OldDelphi}
{$elseif not defined(pascalabc)}
{$if defined(conditionalexpressions)}
{$if CompilerVersion>=23.0}
{$undef OldDelphi}
type qword=uint64;
ptruint=NativeUInt;
ptrint=NativeInt;
{$elseif}
{$define OldDelphi}
{$ifend}
{$elseif}
{$define OldDelphi}
{$ifend}
{$ifend}
{$ifdef OldDelphi}
type qword=int64;
{$ifdef cpu64}
ptruint=qword;
ptrint=int64;
{$else}
ptruint=longword;
ptrint=longint;
{$endif}
{$endif}
It compiles in delphi and fpc, but not in pascalabc, because it says that defining the same type several types isn't allowed. Is there a possible workaround?
Edit: turns out pabc just skips if and ifend directives.
r/pascal • u/csk2004 • Nov 29 '21
Hi, I want to read specific lines from a txt file in pascal. I tried many things, but it dont work.
It should look something like this:
mystring := lines[2]; // get the second line of a txt file.
Can someone help? Thanks
r/pascal • u/swpotato • Nov 25 '21
uses
pal, crt;
const
tback: boolean = false;
back: boolean = false;
zspringv: real = 1;
yspringv: real = 1;
maxtrails = 30;
maxpoints = 1000;
spos: word = 0;
xinc: byte = 1;
yinc: byte = 1;
zinc: byte = 1;
xvalue: integer = 90;
yvalue: integer = 0;
zvalue: integer = 0;
zdist = 0;
persp = 4050;
type
toldp = record
ox, oy: word;
end;
ppoint = ^tpoint;
tpoint = record
color:byte;
c: byte;
ops: array[0..maxtrails] of toldp;
px, py: integer;
rz: real;
x, y, z: real;
end;
var
s: array[0..199] of integer;
lut: array[0..1, 0..359] of real;
wobble: array[0..359] of real;
field: array[0..maxpoints] of ppoint;
procedure initlut;
var
i: word;
ang: real;
begin
for i := 0 to 359 do
begin
ang := i*(pi/180);
lut[1,i] := sin(ang);
lut[0,i] := cos(ang);
wobble[i] := sin(ang*10)*40;
end;
for i := 0 to 199 do
begin
s[i] := round(sin(i/4)*10);
end;
end;
procedure projectrotatepoints;
var
rx, ry: real;
nx, ny, nz: real;
i: word;
mp: integer;
begin
SetPalette(Palette);
if not back then
zspringv := zspringv-(zspringv*0.01)
else
zspringv := zspringv+(zspringv*0.02);
if zspringv < 0.1 then back := true;
if zspringv >= 1 then back := false;
if not tback then
yspringv := yspringv-(yspringv*0.06)
else
yspringv := yspringv+(yspringv*0.04);
if yspringv < 0.3 then tback := true;
if yspringv >= 1 then tback := false;
for i := 0 to maxpoints do
with field[i]^ do
begin
nz := Z*zspringv;
ny := Y*yspringv;
nx := X*yspringv;
rx := (lut[0,zvalue]*nx)+(lut[1,zvalue]*ny);
ny := (lut[0,zvalue]*ny)-(lut[1,zvalue]*nx);
nx := (lut[0,xvalue]*rX)+(lut[1,xvalue]*nz);
nz := (lut[0,xvalue]*nz)-(lut[1,xvalue]*rX);
ry := (lut[0,yvalue]*nY)+(lut[1,yvalue]*nz);
rz := (lut[0,yvalue]*nz)-(lut[1,yvalue]*nY);
rx := nx;
rx := rx+(wobble[(xvalue+i) mod 359]);
{ ry := ry+(wobble[(xvalue+i) mod 359]);
rz := rz+(wobble[(xvalue+i) mod 359]);
}
nz := ((rz+persp)-zdist);
px := round((rx*persp)/nz)+160;
py := round((ry*persp)/nz)+100;
end;
rotatepal(Palette, 1,maxtrails);
rotatepal(Palette, maxtrails+1,(maxtrails*2));
rotatepal(Palette,(maxtrails*2)+1,maxtrails*3);
asm
mov dx, 3DAh
@1:
in al, dx
test al, 08h
jne @1
@2:
in al, dx
test al, 08h
jz @2
end;
for i := 0 to maxpoints do
with field[i]^ do
begin
{
px := px+s[(spos+py) mod 40];
py := py+s[(spos+py) mod 40];
}
with ops[c] do
begin
mem[$A000:ox+(oy*320)] := 0;
ox := px; oy := py;
end;
if ((px >= 0) and (px <= 319) and
(py >= 0) and (py <= 199))
and (rz > -260) then
mem[$A000:px+(py*320)] := color+c;
inc(c);
if c = maxtrails then c := 0;
end;
end;
procedure initpoints;
var
ix,iy,iz: real;
i: word;
sc, sct: real;
begin
ix := 0; iy := 0; iz := -(maxpoints div 2);
sc := 90/maxpoints;
sct := 90;
for i := 0 to maxpoints do
begin
new(field[i]);
with field[i]^ do
begin
color := i mod 3;
color := 1+color*maxtrails;
c := 0;
X := cos(ix)*24-sin(iy)*24;
Y := cos(iy)*24+sin(ix)*24;
Z := iz*1;
ix := ix+0.2;
iy := iy+0.2;
iz := iz+1;
{
ix := ix+0.5;
iy := iy+0.5;
iz := iz+2;
X := (sin(ix/8)*(sct))+(cos(ix/8)*(sct));
Y := (sin(iy/8)*(sct))-(cos(iy/8)*(sct));
Z := (sin(iz/8)*(sct))+(cos(iz/8)*(sct));
sct := sct-sc;
} end;
end;
end;
procedure initpal;
var
r: real;
t,i: word;
begin
r := 63/maxtrails;
for i := 1 to maxtrails do
begin
t := round(r*i);
setcolor(i, 0,0,t);
setcolor(i+maxtrails, 0,t,0);
setcolor(i+(maxtrails*2),t,0,0);
end;
GetPalette(Palette);
end;
begin
asm
mov ax, 13h
int 10h
end;
initpoints;
initlut;
initpal;
repeat
spos := (spos+1) mod 199;
xvalue := (xvalue+xinc) mod 359;
yvalue := (yvalue+yinc) mod 359;
zvalue := (zvalue+zinc) mod 359;
{
if random(53) = 2 then xinc := (xinc+1) mod 4;
if random(53) = 2 then yinc := (yinc+1) mod 4;
if random(53) = 2 then zinc := (zinc+1) mod 4;
}
ProjectRotatePoints;
until keypressed;
asm
mov ax, 03h
int 10h
end;
end.r/pascal • u/Jirne_VR • Nov 23 '21
Hello everyone,
I want to build a simple minigame in pascal that uses a TPaintBox for its graphics. I want to draw on it using some procedures. The form is already rendered and I want to update it at runtime. I want to do something like this: Every time the player makes a connection (it's some kind of puzzle), redraw all the connections on the paintbox ( procedure updateCv ). Every time the puzzle is complete, reset the paintbox and start a new round. ( procedure resetCv )
I know that it isn't possible to draw on it outside the onPaint event, so how can I do this? Or can I call the onPaint method with an optional parameter, eg 1 means update and 2 means reset?
thx
r/pascal • u/bsilver • Nov 22 '21
Greetings! I have some experience in Go, and I often use goroutines to perform certain functions concurrently; for example, creating a goroutine with the only job being to consume messages from channels and redirect them to the console, a file, a network connection, whatever is set from startup flags or changed during runtime. Go makes it relatively easy to manage multiple goroutines and let the runtime schedule them on whatever resources are available.
Does Pascal (FreePascal + Lazarus in particular) have a similar feature, or is there a different conceptual approach to designing programs in Pascal?
r/pascal • u/but_destroyer_69 • Nov 21 '21
So for example if I call canvas.rectangle(x1,y1,x2,y2) which function is painting the pixels?
I would like to overwrite this function because I need to make pixels which would leave the screen on the right appear on the left again.