freepascal

Building Delphi project from Visual Studio Code

♀尐吖头ヾ 提交于 2019-12-07 05:42:17
问题 I have already set up build and debug environment for Object Pascal inside Visual Studio Code via FPC and GDB, but I just made build process work for programs containing only 1 .pas file via "command": "fpc", "args": [ "-g", "-Px86_64", "helloWorld.pas" ], Now, I need to build quite big Delphi project group (something like solution?) and it contains main project file .groupproj. Is there a way to build the .groupproj via FPC somehow? Or at least some workaround like conversion to .lpi and

Is there a library for sanitizing query parameters for PostgreSQL or SQL in general, for FreePascal and Delphi?

让人想犯罪 __ 提交于 2019-12-07 01:03:30
问题 I got bitten my first sql escaping error (it was long overdue) when I tried to execute the PostgreSQL query below with a value containing an apostrophe eg. O'Brien , using FreePascal and Lazarus SQL.Add(format('select * from zones where upper(zn_name) >= %s and upper(zn_name) < %s order by zn_name',[sQuote(zoneMin), sQuote(zoneMax)])); In the query above SQuote is a function that wraps a string in single quotes. Is there some standard library for sanitizing SQL query parameters for Lazarus

How can I compile 64-bit Mac programs with Free Pascal?

旧城冷巷雨未停 提交于 2019-12-06 22:23:15
问题 I have an x86_64 library on my Mac compiled by GCC, and I want to link it with Pascal code compiled with Free Pascal 2.4. What options do I give to fpc to make it generate 64-bit code? Without any options, I only get 32-bit .o files. I'm using the fpc-2.4.0.intel-macosx.dmg download from SourceForge, but when I run fpc -i , the only target Macintosh platform it lists is "Darwin for i386," although the 2.4 release notes say it can target "64-bit Mac OS X (x86_64/ppc64)." 回答1: According to

Encode string to Base64 in Inno Setup (Unicode Version of Inno Setup)

天大地大妈咪最大 提交于 2019-12-06 14:45:57
Problem I tried to use the Pascal function EncodeStringBase64 , assuming Inno Setup had access to the Pascal standard library but it fails to find it and provides an Unknown Identifier error. https://www.freepascal.org/docs-html/fcl/base64/encodestringbase64.html I also found this code to carry out the conversion but it seems to be restricted to AnsiStrings. https://github.com/docker/toolbox/blob/master/windows/base64.iss Question Ideally I'd like to use the standard library function, is there any way that I can access it? If not, is the code using AnsiStrings safe to use on normal Unicode

How to search an array of bytes for “StringA”?

喜夏-厌秋 提交于 2019-12-05 19:43:43
Using FreePascal (or Delphi if no FP examples), given a 2048 byte buffer that is as an "array of bytes", how can I search the buffer for "StringA"? var Buffer : array[1..2048] of byte; ... repeat i := 0; BlockRead(SrcFile, Buffer, SizeOf(Buffer), NumRead); // Now I want to search the buffer for "StringA"? ... Thankyou I think this will work in fpc without extra Unicode/AnsiString conversion : function Find(const buf : array of byte; const s : AnsiString) : integer; //returns the 0-based index of the start of the first occurrence of S //or -1 if there is no occurrence var AnsiStr : AnsiString;

Casting between parent and child classes in delphi

让人想犯罪 __ 提交于 2019-12-05 16:29:51
I'm writing some software that targets two versions of very similar hardware which, until I use the API to initialize the hardware I'm not able to know which type I'll be getting back. Because the hardware is very similar I planned to have a parent class (TParent) that has some abstract methods (for where the hardware differs) and then two child classes (TChildA, TChildB) which implement those methods in a hardware dependent manner. So I would first instantiate an object of TParent check what kind it is then cast it to the correct child. However when I do this and call one of the abstract

Unable to enter critical section

妖精的绣舞 提交于 2019-12-05 12:12:10
Why is it imposible to enter critical section without Sleep(1)? type TMyThread = class(TThread) public procedure Execute; override; end; var T: TMyThread; c: TRTLCriticalSection; implementation procedure TForm1.FormCreate(Sender: TObject); begin InitializeCriticalSection(c); T := TMyThread.Create(false); end; procedure TMyThread.Execute; begin repeat EnterCriticalSection(c); Sleep(100); LeaveCriticalSection(c); sleep(1); // can't enter from another thread without it until false; end; procedure TForm1.Button1Click(Sender: TObject); begin EnterCriticalSection(c); Caption := 'entered';

Is there a library for sanitizing query parameters for PostgreSQL or SQL in general, for FreePascal and Delphi?

亡梦爱人 提交于 2019-12-05 04:52:16
I got bitten my first sql escaping error (it was long overdue) when I tried to execute the PostgreSQL query below with a value containing an apostrophe eg. O'Brien , using FreePascal and Lazarus SQL.Add(format('select * from zones where upper(zn_name) >= %s and upper(zn_name) < %s order by zn_name',[sQuote(zoneMin), sQuote(zoneMax)])); In the query above SQuote is a function that wraps a string in single quotes. Is there some standard library for sanitizing SQL query parameters for Lazarus/FreePascal or Delphi for that matter? Your application is vulnerable to a serious class of security

How can I compile 64-bit Mac programs with Free Pascal?

青春壹個敷衍的年華 提交于 2019-12-05 03:44:52
I have an x86_64 library on my Mac compiled by GCC, and I want to link it with Pascal code compiled with Free Pascal 2.4. What options do I give to fpc to make it generate 64-bit code? Without any options, I only get 32-bit .o files. I'm using the fpc-2.4.0.intel-macosx.dmg download from SourceForge, but when I run fpc -i , the only target Macintosh platform it lists is "Darwin for i386," although the 2.4 release notes say it can target "64-bit Mac OS X (x86_64/ppc64)." According to Jonas Maebe on the fpc-pascal mailing list , there are two options: Run fpc with the -Px86_64 option. (The -P

Writing a Scheme interpreter with FPC: Recursive data structures

感情迁移 提交于 2019-12-05 03:15:57
问题 Essentially, this is a question about recursive data structures in Pascal (FPC). As I would like to implement a Scheme interpreter like it is shown in SICP chapter 4, this question may be relevant for Schemers as well. :) S-expressions shall be represented as tagged data. So far, I have constructed a variant record, which represents numbers and pairs. Hopefully the code is readable and self-explanatory: program scheme; type TTag = (ScmFixnum, ScmPair); PScmObject = ^TScmObject; TScmObject =