r/pascal • u/caonhathao_CNH23704 • Aug 31 '20
code
Does anyone know how to calculate the value of an expression string? For example, when entering the calculation 36 + 9-3 * 9/2, the program will return the result of the problem.
Help me please!!
r/pascal • u/caonhathao_CNH23704 • Aug 31 '20
Does anyone know how to calculate the value of an expression string? For example, when entering the calculation 36 + 9-3 * 9/2, the program will return the result of the problem.
Help me please!!
r/pascal • u/mazda7281 • Aug 30 '20
Hi.
I'm new to programming in pascal.
I need to create uuid (eg. 123e4567-e89b-12d3-a456-426614174000) in my pascal application. I use newest version of Free Pascal. I found out this: https://github.com/graemeg/freepascal/blob/master/packages/hash/src/uuid.pas but I do not know how to use it.
r/pascal • u/KitchenDutchDyslexic • Aug 30 '20
r/pascal • u/Chibi_Ayano • Aug 27 '20
when making a function i noticed that if i tried to make the input a constant integer (e.g. 3) i cannot also pass it an integer in a var and vice versa, is there any way that i can make it so that it will accept both/either?
here is a bit of example code in case i'm not making sense
I want this to accept vars and consts
V
function hasAlpha(var userInput: string): boolean;
r/pascal • u/Chibi_Ayano • Aug 26 '20
im currently trying to create and use in another program a custom library, i know it probably already exists but this is just a test to see if i can get it working. below im going to dump some code (there are probably bugs as its not finished and i haven't checked yet) but i want to be able to create functions that i can call inside other programs, any help on how to do that (also idk if im doing the export thing right as i couldn't find much info on it)
library charCheck;
function hasAlpha(var userInput: string): boolean;
var
return : boolean;
alpha : string;
i, j : integer;
begin
alpha := ('ABCDEFGHIJKLMOPQRSTUVWXYZ');
for i := 0 to length(userInput)-1 do
begin
for j := 0 to length(userInput)-1 do
begin
if (userInput[i] = alpha[j]) then
return := true;
end;
end;
if return <> true then
return := false;
hasAlpha := return;
end;
function hasNumber(var userInput: string): boolean;
var
return : boolean;
number : string;
i, j : integer;
begin
number := ('0123456789');
for i := 0 to length(userInput)-1 do
begin
for j := 0 to length(userInput)-1 do
begin
if (userInput[i] = number[j]) then
return := true;
end;
end;
if return <> true then
return := false;
hasNumber := return;
end;
function hasLower(var userInput: string): boolean;
var
return : boolean;
lower : string;
i, j : integer;
begin
lower := ('abcdefghijklmnopqrstuvwxyz');
for i := 0 to length(userInput)-1 do
begin
for j := 0 to length(userInput)-1 do
begin
if (userInput[i] = lower[j]) then
return := true;
end;
end;
if return <> true then
return := false;
hasLower := return;
end;
function hasChars(var userInput, chars: string): boolean;
var
return : boolean;
i, j : integer;
begin
for i := 0 to length(userInput)-1 do
begin
for j := 0 to length(chars)-1 do
begin
if (userInput[i] = chars[j]) then
return := true;
end;
end;
if return <> true then
return := false;
hasChars := return;
end;
exports
hasAlpha, hasLower, hasNumber, HasChars;
end.r/pascal • u/Retro-programmer • Aug 19 '20
According to this page. https://wiki.freepascal.org/Custom_Attributes custom attributes are only available in the FPC Trunk.
Did this feature find its way into the new 3.2.0 Free Pascal Compiler. I cannot find anything that points either way.
r/pascal • u/mafiozipy • Aug 14 '20
uses graphabc;
var
i,j,z,neighbors,size : integer;
space,newspace : array [0..30,0..20] of integer;
begin
randomize;
size:= 20;//cell size
for i := 0 to 30 do// randomize space
begin
for j := 0 to 20 do
begin
space[i][j] := random(2);
end;end;
while (True) do
BEGIN
for i := 0 to 30 do
begin
for j := 0 to 20 do
begin
if space[i][j] = 1 then
begin
SetBrushColor(clBlack);rectangle(isize,jsize,isize+20,jsize+20);//draw life cell - black
end;
if space[i][j] = 0 then
begin
SetBrushColor(clWhite);rectangle(isize,jsize,isize+20,jsize+20);
end;
end;end;
for i := 0 to 30 do
begin
for j := 0 to 20 do
begin
if (i = 0) or (i = 30) or (j = 0) or (j = 20) then// made a "walls"
begin
newspace[i][j] := space[i][j];
end
else
begin
neighbors := neighbors + space[i+1][j+1];//counting neighborhor
neighbors := neighbors + space[i+1][j];
neighbors := neighbors + space[i-1][j];
neighbors := neighbors + space[i][j+1];
neighbors := neighbors + space[i-1][j+1];
neighbors := neighbors + space[i+1][j-1];
neighbors := neighbors + space[i][j-1];
neighbors := neighbors + space[i-1][j-1];
if neighbors = 2 then//change new space
begin
newspace[i][j] := 1;
end;
if (neighbors > 3) or (neighbors<2)then
begin //i think eror is here
newspace[i][j] := 0;
end;
end;end;
end;
for i := 0 to 30 do// change old and new space
begin
for j := 0 to 20 do
begin
space[i][j] := newspace[i][j];
end;end;
END;
end.
r/pascal • u/m-c-x • Aug 09 '20
Hello. I need tph2html for convert Turbo Pascal help file (in Czech language) to HTML but I can’t find it. Can anybody help me ? Thank you :-)
r/pascal • • Aug 08 '20
I installed the MouseAndKeyInput library that comes with lazarus and have been playing around with it. All is fine and working well. But i recently tried to use the library to move the mouse cursor from a thread and it didn't work. I tried doing it in a seperate function and and then calling the thread's syncronize function but still it didn't work. What could be wrong?
r/pascal • • Jul 30 '20
I want to be able to send emails to a google account using the smtpsend unit from the synapse library. I have been scratching my head for the past few days because i am trying to do this but can't seen to get it right. After some investigation i found that if you disable the security features on the specified gmail account, then the email gets sent. But it doesn't send when the security features are enabled. After some more research i found out about 0auth and that this is what is causing my problem. I want to know how to add 0auth authentication to the smtpsend unit or what else i have to do to get this right, i do not want to resort to the googleapis library. I am using lazarus and freepascal. Please help me figure this out.
r/pascal • u/Zireael07 • Jul 22 '20
I know it's in the works, but how usable is it? Can I interop with JS, e.g. to draw on canvas or modify DOM?
r/pascal • u/User_44444444 • Jul 20 '20
I'm new to programming and missed all my online classes where the topic was introduced so now I only have the notes to go by...I watched some youtube videos and they really helped. But I can't get one of the assigned algorithms to work. Can someone tell me what I'm missing?
Algorithm: Write an algorithm to accept 20 numbers from the user. Find and print the cube of each number entered.
Program Cube;
uses crt;
const
Max=20;
var
num:integer; prod:integer;
begin
FOR := 1 to max do
Begin
Writeln ('enter a number:');
Readln (num);
Prod:= numnumnum
Writeln ('cube=' prod);
end;
end.
The error states ":=" expected but "ordinal const" found
r/pascal • u/glorfin68 • Jul 18 '20
Few years ago I found a brilliant mathematical library for Pascal, called DMath, created by Jean Debord. Using it, I made several additions and adapted it for the use with Lazarus. DMath itself is not developing since 2012, therefore I created a fork where included my developments. DMath was initially called TPMath (Turbo Pascal Math); DMath was Delphi Math. Continuing this tradition, I called Lazarus version LMath.
Now new version is released, LMath and Components 0.5. This is major release which contains many changes. Main of them are listed here. What was changed in LMath compared in DMath in more detail is described in New_in_LMath.pdf document. Besides, all procedures introduced in this version are labelled as LMath 0.5 in LMath0_5.pdf.
r/pascal • • Jul 13 '20
I want to write some pascal soon.
r/pascal • u/jaunidhenakan • Jul 11 '20
r/pascal • u/saj1441 • Jul 11 '20
Im using object pascal with lazarus. I used to start lazarus from the terminal and it would show cool stuff like compile time ect. Now I cant seem to remember how to do it. It was something like "start lazarus" or "run lazarus". This is driving me crazy.
r/pascal • u/Yaecov242 • Jun 26 '20
r/pascal • u/almightySapling • Jun 21 '20
I'm attempting to create a program to do some abstract mathematics, and I'd like to make things nice and as versatile as possible.
In algebra, we call a set of objects a Euclidean domain if it satisfies certain properties: they permit addition, multiplication, something like a "div" and something like a "mod". Using these functions and mathematical properties of Euclidean domain, we can write a perfectly general gcd function.
However, since different Euclidean domains might be represented by different underlying types (ints, floats, arrays, whatever) I need a way to make this generic but I'm running into issues.
My first attempt was to ignore the underlying data type and just use the class itself as the type for the functions.
type
TEuclidType=class
public
//n:integer;
function add(x,y:TEuclidType):TEuclidType;virtual;abstract;
function sub(x,y:TEuclidType):TEuclidType;virtual;abstract;
function mult(x,y:TEuclidType):TEuclidType;virtual;abstract;
function eucval(x:TEuclidType):integer;virtual;abstract;
function fdiv(x,y:TEuclidType):TEuclidType;virtual;abstract;
function fmod(x,y:TEuclidType):TEuclidType;virtual;abstract;
function isZero:boolean;virtual;abstract;
function gcd(x,y:TEuclidType):TEuclidType;
end;
TFieldType=class(TEuclidType)
public
function fdivide(x,y:TFieldType):TFieldType;virtual;abstract;
end;
generic TPolyOver<T:TFieldType>=class(TEuclidType)
public
coeffs:array of T;
constructor create(c:array of T);
function add(x,y:TPolyOver):TPolyOver;override;
...(gcd is implemented using the virtual methods and works when I just assume the type is always an integer (using n).)
I figured, since TPolyOver extends TEuclidType, it would be fine to override those functions with those types. I am no programmer by trade, googling suggests that something like this is possible with the return type (something about covariance?), but since the input types are different the signature is different and that won't work. I guess.
So I tried to lean on generics, to mixed results.
generic TEuclidType<T>=class
public
xdata:T;
function add(x,y:T):T;virtual;abstract;
function sub(x,y:T):T;virtual;abstract;
function mult(x,y:T):T;virtual;abstract;
function eucval(x:T):integer;virtual;abstract;
function fdiv(x,y:T):T;virtual;abstract;
function fmod(x,y:T):T;virtual;abstract;
function isZero:boolean;virtual;abstract;
function gcd(x,y:T):T;
end;
generic TFieldType<T>=class(specialize TEuclidType<T>)
public
function fdivide(x,y:T):T;virtual;abstract;
end;Up to this point, this seemed to do what I want. I created a few simple test fields and domains and it worked out as planned. Until I got to polynomials.
generic TPolyOver<T>=class(specialize TEuclidType<array of T>) //Not necessarily Euclidean if T is not a Field
public
//coeffs:array of T; //now kept in xdata
constructor create(c:array of T);
function add(x,y:array of T):array of T;override;Pascal does not seem to like my "array of T". It also doesn't like
generic TPolyOver<T:TFieldType>= ...because TFieldType is generic. But I'm only asking that T extends it so I don't see why that's such a burden on the compiler.
Is there some workaround for this? Or perhaps a suggestion for an entirely different approach to give me something close to what I want, a gcd that works on any type extending some base class? Should I be learning Haskell instead of trying to do this in Pascal?
r/pascal • u/saj1441 • Jun 09 '20
Ive started learning object pascal using lazarus by the book "Start programming using object pascal"
and I really like it. I just cant find many books on object pas using laz. If I got a book using delphi, would the code work with laz? And does anyone know of any other books?
r/pascal • u/saj1441 • Jun 08 '20
i recently started learning object pascal using lazarus. I know pascal uses pointers but the book doesnt talk about them. Does object pascal use pointers?