Re: [fpc-pascal] Floating point question
On Tue, Feb 6, 2024 at 6:13 PM Rafael Picanço via fpc-pascal wrote: > type > {$IFDEF CPU86}{$IFDEF CPU32} > TLargerFloat = Extended; > {$ENDIF}{$ENDIF} > > {$IFDEF CPUX86_64} > TLargerFloat = Double; > {$ENDIF} Why (re-invent the wheel)? Why not use Math.Float? IIRC then this is Extended, double or Single depending on CPU type. And always the largest precision the CPU supports. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Floating point question
On Sun, Jan 28, 2024 at 10:21 AM Bernd Oppolzer via fpc-pascal wrote: > The problem now is: > > the printout of my value suggest an accuracy which in fact is not there, Which is because I was too lazy to cater for that. Notice the :20:20 in the writeln statement: I tell the compiler how many digits to use there and it just does as I tell it to. Floating point calculations will always have rounding errors. Notice that when a calculation can be off by x percent and you do y calculations then the end result may be off by x*y percent (worst case scenario). If you need infinite precision, there are libraries providing that, they're just not provided with fpc. E.g. the (old) Windows calculator gives 8427.02291667 as the result. E.g you can do the whole calculation using fractions and then convert the end result to floating point. This will give: 8427.022916668 using Double (64-bit) 8427.022916625 using Extended (80-bit) These are the same as in my previous example, indicating that most of the "inaccuracy" is in the 11/480 part. Conclusion: It is **not** a bug, it as expected. B.t.w. I tested with Delphi 7 and there the accuracy is even one digit less precise than in fpc (it goes 1 digit earlier "off"). -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Floating point question
On Sat, Jan 27, 2024 at 6:23 PM Thomas Kurz via fpc-pascal wrote: > Hmmm... I don't think I can understand that. If the precision of "double" > were that bad, it wouldn't be possible to store dates up to a precision of > milliseconds in a TDateTime. I have a discrepancy of 40 seconds here. Consider the following simplified program: var tt: double; ee: extended; begin tt := (8427 - Double(0.5)) + (12/ Double(24.0)) + (33/Double(1440.0)) + (0/Double(86400.0)); ee := (8427 - Extended(0.5)) + (12/ Extended(24.0)) + (33/Extended(1440.0)) + (0/Extended(86400.0)); writeln('tt=',tt:20:20); writeln('ee=',ee:20:20); end. === Now see what it outputs: C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas Free Pascal Compiler version 3.2.2 [2021/05/15] for i386 ... C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test tt=8427.022916668000 ee=8427.022916625000 C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc -Px86_64 test.pas Free Pascal Compiler version 3.2.2 [2021/05/15] for x86_64 .. C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test tt=8427.022916668000 ee=8427.022916668000 On Win64 both values are the same, because there Extended = Double. On Win32 the Extended version is a bit closer to the exact solution: 8427 - 1/2 + 1/2 + 33/1440 = 8427 + 11/480 Simple as that. Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Floating point question
On Sat, Jan 27, 2024 at 1:40 PM Thomas Kurz via fpc-pascal wrote: > 2. According to both C, Sqlite and Excel, the value of "t" in line 41 should > be "8427.0229167". FPC gives me a difference of approximately 39/86400. Again: if I cast all flots involved to double both the result of maketime and the calculation (8427 - 0.5) + (12/ 24.0) + (33/1440.0) + (0/86400.0) give this value: 8427.022916668000 -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Floating point question
On Sat, Jan 27, 2024 at 1:40 PM Thomas Kurz via fpc-pascal wrote: > My problems are: > > 1. The "writeln" in line 32 correctly prints "0." when (cross-) compiling > to win64, but "39.375" when compiling to win32 (with ppc386). On Win64 all math is done with double precision, on win32 all literal floating point values in your code will be interpreted as Extended. Cast everything to Double and the result will be the same on Win64 and Win32. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] case statement
On Thu, Dec 14, 2023 at 5:01 PM Adriaan van Os via fpc-pascal wrote: > I always use "OTHERWISE instead of ELSE, but that's my personal > preference. +1 Seeing OTHERWISE in source code just makes me smile. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TPath enhancements (Issue #40513): can somebody test with Delphi 12?y
Put a new implementation in the bugreport. Did not test the "wah is an illegal chatacter", IMO that should be a seperate issue. Currently based upon these rules: { Concatenates the paths. If one or more of the paths is absolute, it will use the right most absolute path as base path and then concatenates the remaining paths to that. E.g. ['\a','b','\c','d'] will return '\c\d'; If ValidateParam is True, and any of the paths contains an invalid path character an exception is raised. No checks are done wether or not a given paths exists. E.g. ['\a','b','\c:'] will hapilly return the non-sensical path '\c:' } My tests now give these results: OK: ['']: Got: '', Expected: '' OK: ['','']: Got: '', Expected: '' OK: ['','','']: Got: '', Expected: '' OK: ['a','b','c']: Got: 'a\b\c', Expected: 'a\b\c' OK: ['a','b','\c']: Got: '\c', Expected: '\c' OK: ['a','\b','c']: Got: '\b\c', Expected: '\b\c' OK: ['\a','\b','c']: Got: '\b\c', Expected: '\b\c' OK: ['\a','\b','\c']: Got: '\c', Expected: '\c' OK: ['\a','b','\c:']: Got: '\c:', Expected: '\c:' OK: ['a','<>','\b','c','\d'] --> EArgumentException, (as expected) FAIL: ['c:','a','b']: Got: 'c:\a\b', Expected: '?' <== don't know what the expected value should be here NOT ValidateParams OK: ['']: Got: '', Expected: '' OK: ['','']: Got: '', Expected: '' OK: ['','','']: Got: '', Expected: '' OK: ['a','b','c']: Got: 'a\b\c', Expected: 'a\b\c' OK: ['a','b','\c']: Got: '\c', Expected: '\c' OK: ['a','\b','c']: Got: '\b\c', Expected: '\b\c' OK: ['\a','\b','c']: Got: '\b\c', Expected: '\b\c' OK: ['\a','\b','\c']: Got: '\c', Expected: '\c' OK: ['\a','b','\c:']: Got: '\c:', Expected: '\c:' OK: ['a','<>','\b','c','\d']: Got: '\d', Expected: '\d' -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TPath enhancements (Issue #40513): can somebody test with Delphi 12?y
On Sun, Nov 19, 2023 at 3:50 PM Bart wrote: > Thanks again for testing. What about ['c:','a','b'] Does it return c:a\b, or c:\a\b (on Windows), or IOW: does it take into account driveletters? The first one IMO would be correct. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TPath enhancements (Issue #40513): can somebody test with Delphi 12?y
On Sun, Nov 19, 2023 at 2:31 PM Michael Van Canneyt via fpc-pascal wrote: > > This raises the question what the result of > > TPath.Combine(['a','\b',c'','\d','e']) would be (I would then expect > > either \b\c or \d\e)? > > \d\e > > > > > If ValidateParams is True, will it raise an error on invalid path > > characters in an argument that will not be used for the final result > > e.g. ['a','<|>','c:\foo']? > > Yes. All arguments are checked. Thanks again for testing. Where is EInOutArgumentException defined? Probably it's defined as class(EInOutError)? If so, what is the value of the ErrorCode property in this case? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TPath enhancements (Issue #40513): can somebody test with Delphi 12?
On Sun, Nov 19, 2023 at 12:59 PM Michael Van Canneyt via fpc-pascal wrote: > The output is in linux.txt and windows.txt Thanks for testing. It seems that it'll pick the last absolute path it finds, not the first one in the argument list. It seems that DoTest('regular 1','a','\b','c'); will give '\b\c' That's confucing given that the Delphi docs suggest that if an absolute path is found (being not the firts argument), then this path will be the function result. If that were to be true, I would expect the result to be '\b' in that case. This raises the question what the result of TPath.Combine(['a','\b',c'','\d','e']) would be (I would then expect either \b\c or \d\e)? If ValidateParams is True, will it raise an error on invalid path characters in an argument that will not be used for the final result e.g. ['a','<|>','c:\foo']? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TPath enhancements (Issue #40513): can somebody test with Delphi 12?
On Sun, Nov 19, 2023 at 11:04 AM Sven Barth via fpc-pascal wrote: > Also: does this depend on the operating system and/or file system? Cause > Linux file systems have different invalid characters (usually only slash and > NUL) than NTFS or FAT. Determining FileSystem at runtime, is that even possible? Adjusting the TPath.HasValidPathChars and TPath.GetInvalidPathChars functions for *nix maye be rather easy (there laready is non-windows code in that unit) ValidateParams may even mean (ATM nobody seems to know) that the params must represent a valid path (either on it's own or after concatenation). -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] TPath enhancements (Issue #40513): can somebody test with Delphi 12?
Hi, I'm trying to implement the new features that were added in Delphi 12 to TPath. I've made a naive implementation based upon available documentation. Some questions about how it is supposed to behave are missing though: 1. The docs state that an exception is raised if the given paths contain invalid characters. Does the vlaue of the ValidateParams have any influence on this? 2. If not: what does this ValidateParams parameter do then? 3. if multiple paths are absolute (e.g. the 2nd, 3rd and 6th path is absolute): what will be returned? (My guess: either the first absolute one it finds, or the last one.) Could anybody with Delphi 12 test the TPath.Combine(const Paths: array of string; const ValidateParams: Boolean = True): string; function with the test program that is in the bugtracker (https://gitlab.com/freepascal.org/fpc/source/-/issues/40513#note_1645757436)? Does it behave like the implementation I came up with? If a parameter is "invalid", but it is not used in the result (e.g. because there is a valid absolute path as the second or later argument in the array), will there be an exception? Without (black box) testing it'll be impossible to implement these features. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] overriden or not ?
On Fri, Aug 18, 2023 at 10:21 AM Adriaan van Os via fpc-pascal wrote: > > Is there a way to see if a specific class/object method has been overridden > or not ? There's an example of this in Lazarus Controls unit: // Check if SetTextBuf is overridden, otherwise // we can call RealSetText directly if TMethod(@Self.SetTextBuf).Code = Pointer(@TControl.SetTextBuf) then //not overridden -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Choice of exceptions to use?
On Sun, Jun 4, 2023 at 11:58 AM Graeme Geldenhuys via fpc-pascal wrote: > Initially I was leaning towards the Range exception, but now I'm > thinking that maybe the Argument exception is more appropriate > (based on the descriptions seen in the linked docs). I would go for range exception, since the offending coordinates are out of range. Invalid Argument for me would apply to situations like a wrong type for a format specifier. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Size of set.
On Tue, May 23, 2023 at 2:14 AM Mikael Backman via fpc-pascal wrote: > Is there any way to decide the number of elements in a set? > there any way to traverse the elements in a set? Couldn't you use PopCnt for that? You would need to know the SizeOf() the type of the set in question. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] StrIComp
On Sat, Apr 29, 2023 at 10:30 PM Thomas Kurz via fpc-pascal wrote: > Is it intentional that StrIComp (from the strings unit) gives an access > violation if one of its arguments is NIL? Yes. Delphi does so too. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Converting old pascal written for Pascal/MT+ compiler
On Tue, Apr 4, 2023 at 6:00 PM Tomas Hajny via fpc-pascal wrote: > Well, managed types are not very likely in code imported from a Pascal > compiler not knowing units... Well, his fpc.cfg might define string to be ansistring... -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Converting old pascal written for Pascal/MT+ compiler
On Tue, Apr 4, 2023 at 9:43 AM Jacob Kroon via fpc-pascal wrote: > What is the technical downside to using "const", or is it just cosmetic ? If your local "writeable constant" is of type string, and strings are longstrings, and the writeable const is assigned a value that is the result of a string concatenation, then you'll have a memory leak. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] possible bug in blockwrite
On Sun, Mar 5, 2023 at 7:02 PM Travis Siegel via fpc-pascal wrote: > On tp, I could open a file with a blocksize of 1, > > reset(file1,1); > ... > For example. > > Let's say I have a 5 byte string: > > st1 := '12345'; > > Now, if I blockwrite this to the file under tp: > > blockwrite(f1,st1); That will not compile under TP (tested with TP 6.0) It needs a third parameter "count". ... > blockwrite(f1,st1,6); > > The reason it needs the extra byte is because the byte 0 (the one that > stores the size of the string) is also written to the file. TP did not > behave this way, though I don't know about delphi, though I'd doubt it dit. TP also does this, just tested. The first byte in the file is $05. Normally one would do BlockWrite(f, S[1], Length(S)); > Is this a bug, or is this a deliberate design decision, and if so, can > we talk about changing it's behavior? Your memory just serves you wrong. ... > st1 := #49+#50+#51+#13; > > then the same code: > > val(st,number,code); > > produces an error, and code has the value of 4, (the place in the string > where the error occurred), but number has a value of 0. > > In tp, number would still have a value of 123, because it would simply > ignore the carriage return at the end of the string. In TP 6.0, code is set to 4 and number to zero (but the value of number shall be undefined if code <> 0) Again, your memory serves you wrong -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] For Loop with QWord
On Tue, Jan 3, 2023 at 3:49 PM James Richters via fpc-pascal wrote: > Var > > I: QWord; > > Begin > > For I := 1 To N Do > It generates an error: > Error: Ordinal expression expected > If I change it to LongInt, then it works, but the question is, why can’t I > use a Qword here if I know I will never need I to be a negative number? IIRC then you can only use native type or smaller as a loop variable in for loop. You can use it in a while or repeat loop though. On 64-bit you can use qword as a loop variable in a for loop. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] CodeTools complete code
On Wed, Oct 5, 2022 at 2:17 PM Hairy Pixels via fpc-pascal wrote: > > CodeTools is part of Lazarus. ... > > Ok thanks. I’m not a Lazarus user so I don’t really follow those forums. > Ok, that makes me kinf of curious wether you and I mean the same when we refer to CodeTools. I mean the part of the Lazarus IDE that does code completion etc. Since you don;t use Lazarus, you must mean something else? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] CodeTools complete code
On Wed, Oct 5, 2022 at 8:33 AM Hairy Pixels via fpc-pascal wrote: > Does CodeTools not understand generic class function calls? Here is the class > in question: CodeTools is part of Lazarus. So, better ask on the Lazarus ML. (And yes, CodeTools has problems with generics.) -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Get highest element of a StringList
On Sat, Sep 10, 2022 at 6:01 PM James Richters via fpc-pascal wrote: > Is there a way to get the highest element of a stringlist other than: > > For Loop := 0 to MyStringList.Count-1 do You can use the for .. in loop. > It would be nice to not have the -1 > Could High() be made to work if the argument was a stringlist? Probabaly it could, but it's not likely going to happen. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Feature Announcement: Function References and Anonymous Functions
On Mon, May 30, 2022 at 7:25 AM Sven Barth via fpc-pascal wrote: > === code begin === > > Sort(lamba (left, right) as > if left < right then -1 > else if left > right then 1 > else 0); > This doesn't look like Pascal at all. I definitively hope this is not the future of our beautiful language. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Issue with CSVDocument
On Mon, Feb 7, 2022 at 9:54 PM James Richters via fpc-pascal wrote: > The part of my program that checks for the BOM is bigger than the actual CSV > read and write. Please let me know if the crash issue with no BOM gets fixed > so I can delete all this stuff that checks for it. That part can be a lot shorter: Open the file as a TFileStream Read the amount of bytes the UTF8-BOM has int an appropriate buffer. Check you really read that amount of bytes. Compare the buffer to the expected UTF8-BOM. This is a snippet from a function I have lying around: FS := TFileStreamUtf8.Create(Fn, fmOpenRead or fmShareDenyNone); try Len := FS.Read({%H-}Buf[0], BufLen); if (Len > 2) and (Buf[0]=$EF) and (Buf[1]=$BB) and (Buf[2]=$BF) then begin //UTF8 BOM -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Interface section overload procedures are all public
On Sun, Jan 23, 2022 at 6:12 PM Rainer Stratmann via fpc-pascal wrote: > // making only one procedure bugtest public in the interface section > // makes all other bugtest procedures public as well! > // Lazarus 2.0.0+dfsg-2 > // FPC-Version: 3.0.4 > // OS: Linux Debian 32 Bit Not so in fpc 3.2.2. So, most likely a bug that got fixed. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] StrToInt is using ShortString buffer?
On Wed, Jan 12, 2022 at 11:33 PM Sven Barth via fpc-pascal wrote: > You can see it in Florian's commit to the branch about range checking where > he added the DestSize parameter. Yes, I discovered that. Will study a bit how this is done, just for the fun of it. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] StrToInt is using ShortString buffer?
On Wed, Jan 12, 2022 at 10:28 PM Bart wrote: > Could you naybe point me to where in the compiler this "magic" happens? > (fpc_Val_UInt_Shortstr() signature needs to be changed IMO) Never mind, I just notice a new branch val_range_check was created that just does this. I'll get on trying to fix hte range check errors then. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] StrToInt is using ShortString buffer?
On Wed, Jan 12, 2022 at 3:13 PM Michael Van Canneyt via fpc-pascal wrote: > From the definition you can see it is a compilerproc function, meaning that > the > compiler writes direct calls to this. > To change the signature of the function means the compiler itself also must > be changed. Could you naybe point me to where in the compiler this "magic" happens? (fpc_Val_UInt_Shortstr() signature needs to be changed IMO) -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Not available duties
On Fri, Dec 24, 2021 at 12:02 PM Adriaan van Os via fpc-pascal wrote: > I got a message from UPS this morning stating > > "! Duties, taxes, and fees totaling NaN are due for this delivery." > > Oops, I don't hope I will ever get a message from UPS > > "! Duties, taxes, and fees totaling INF are due for this delivery." Submit to https://thedailywtf.com/ ? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] ExtractStrings by line in Windows
On Thu, Nov 4, 2021 at 2:52 PM Ryan Joseph via fpc-pascal wrote: > > Maybe use SomeString.Split([LineEnding'], ...)? > > Split has an overload that takes an array of string as first paramter. > > Thanks, I guess I need to use a different way to work on all platforms. If you cast LineEnding to a string, it should work on all platforms I guess (since it invokes the overload with the array of string as separatorlist). -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] ExtractStrings by line in Windows
On Wed, Nov 3, 2021 at 1:57 PM Hairy Pixels via fpc-pascal wrote: Maybe use SomeString.Split([LineEnding'], ...)? Split has an overload that takes an array of string as first paramter. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] String.Split(const Separators: array of Char; Options: TStringSplitOptions)
Hi, I must be missing something obvious. But given the following definition of the Split() helper function for strings: Function Split(const Separators: array of Char; Options: TStringSplitOptions): TStringArray; overload; (fpc 3.2.2) Why does this not compile: var SA: TStringArray; ... SA := S.Split([#0..#32],TStringSplitOptions.ExcludeEmpty); test.pas(236,59) Error: Incompatible type for arg no. 2: Got "TStringSplitOptions", expected "Char". I feel I must be blind... -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to create AnsiString with specific code page?
On Wed, Sep 15, 2021 at 12:32 PM Bart wrote: > This should work > > type > StringCP1251 = AnsiString(1251) That should be type StringCP1251 = type AnsiString(1251); -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to create AnsiString with specific code page?
On Wed, Sep 15, 2021 at 12:14 PM Abuy via fpc-pascal wrote: > I need string with Windows-1251. Tried var msg: AnsiString(1251) but > this does not work. What I am doing now is This should work type StringCP1251 = AnsiString(1251) var S: StringCP1251; -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Hello, new Pascal programmer. had a question!
On Tue, Aug 31, 2021 at 12:23 PM Liam Proven via fpc-pascal wrote: > I've got Lazarus running here and it's more of the same. But I > discovered that I have `fpc` in the terminal and I had a "Hello world" > program running in 30 seconds there... something that took hours in > Delphi. Menu->Project->New Project->Simple program And now you have exactly the same as in the FP IDE, but with the additional benefits of CodeTools. I came from TP 3.0->Tp6.0, so I understand where you came frome. But nowadays I find the FP IDE and even TP (in my DOS VM) cumbersome compared to Lazarus. None of the things I got used to work there (nor do they do in D3 or D7 for that matter). -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Hello, new Pascal programmer. had a question!
On Sat, Aug 28, 2021 at 3:21 PM joseph turco via fpc-pascal wrote: > I am a new programmer, and I thought I'd learn Pascal. You're very welcome. > I saw that with FreePascal, most users are using Lazarus. I don't want to use > this and would rather work in the console, > and use the free pascal IDE.I'm not really interested in using any GUI tools. Assuming that you have modern hardware that you do your programming on: Even if you only want to write console programs, using Lazarus as your IDE hase advantages over using the FP IDE. The Lazarus IDE comes with CodeTools which has code completion and much, much more features that you cannot do without once you're used to having them, even if you only use a few of them. I know: I came from D3 Pro, which at that time was a better compiler and a more stable IDE than Lazarus 0.9.something. But every time I came back to D3 (even just for testing something), I ended up trying to do Ctrl-Click on an identifier (to see it's definition: the IDE opens the source file at the position where it is declared), Ctrl+C on a variable in a new line of code, (just to declare it in the relevant var section) and of course that does not work. So, if you're on Windows, *nix or a Mac, my advice is to use Lazarus as your IDE of choice. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?
On Thu, Aug 12, 2021 at 6:27 AM Michael Van Canneyt via fpc-pascal wrote: > >> As a programmer, switching version systems should be a no-brainer. > > > > My brain begs to differ... > > Well, sorry to say, but I don't understand this. > > What's so hard about it ? > > It's like switching car brands from a VW to an Audi or so. To me it feels more like switching from Pascal to C#. But maybe I'm just a little braindead. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to get fpc and lazarus sources when svn has shut down?
On Wed, Aug 11, 2021 at 11:37 PM Michael Van Canneyt via fpc-pascal wrote: > As a programmer, switching version systems should be a no-brainer. My brain begs to differ... -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Fwd: Linker error on simple program (windows)
On Thu, Jun 24, 2021 at 11:10 AM Sven Barth wrote: > Thus for 3.2.0 and 3.2.2 you indeed need to use the workarounds you mentioned. Not a problem. It just surprised me. Will this be fixed in 3.2.4? (The linker error is a bug IMO, compilation should have failed with a sensible message) -- Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Linker error on simple program (windows)
Given this unit: unit ExtMath; {$mode objfpc} interface function LeadingZeroBits(n: Byte): Integer; inline; implementation function LeadingZeroBits(n: QWORD; BitSize: Integer): Integer; begin Result := 0; end; function LeadingZeroBits(n: Byte): Integer; begin Result := LeadingZeroBits(QWORD(n), SizeOf(Byte)*8); end; end. and this program program test; {$mode ObjFPC} uses Extmath; var b: byte; L: Integer; begin b := 0; L := LeadingZeroBits(b); end. On Windows this won't build with 3.2.2 or 3.2.0. It will build with 3.0.4. C:\Users\Bart\LazarusProjecten\bugs\Console\linkerror>fpc test.pas Free Pascal Compiler version 3.2.2 [2021/05/15] for i386 Copyright (c) 1993-2021 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling test.pas Compiling extmath.pp test.pas(9,3) Note: Local variable "L" is assigned but never used Linking test.exe test.pas(13,1) Error: Undefined symbol: EXTMATH_::=::\_LEADINGZEROBITS$QWORD$LONGINT::=::\LONGINT test.pas(13,1) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: C:\devel\fpc\3.2.2\bin\i386-win32\ppc386.exe returned an error exitcode The error goes away if I remove the inline directive from the function definition in the interface section, or if I also declare the other function (which gives the linker error) in the interface section. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Will the size of an executable depend on the uses clause
On Wed, Jun 16, 2021 at 5:14 PM Bo Berglund via fpc-pascal wrote: > My use case here is that I created a Windows version of Linux "uptime" by > starting in Lazarus with a new Project and selecting Program. Choose Simple Program from that dialog. No uses clause at all, so everything you need, you add it yourself. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TRegistry documentation
On Wed, Jun 16, 2021 at 2:26 PM Jean SUZINEAU via fpc-pascal wrote: > I think there is a way to do this with a single program. Using Lazarus IDE I tried to set Execution level to "requireAdministrator", but then the program simply would not run (it would not ask for the admin password), so in the end I just used something like: uses WinUtils; procedure CheckIsAdmin; begin if not WinUtils.IsWindowsAdmin then begin writeln('This program requires administrator priviliges.'); writeln; Halt; end; end; Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TRegistry documentation
On Wed, Jun 16, 2021 at 2:21 PM Jean SUZINEAU via fpc-pascal wrote: > I guess that what was meaning Bart by hardcat is that you need to > transtype the result this way: > var dw: DWord; > begin > dw:= DWord( Registry.ReadInteger(...)) ; Indeed. This is a lossless operation. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TRegistry documentation
On Wed, Jun 16, 2021 at 9:08 AM James Richters via fpc-pascal wrote: > > >You can have a look too at TRegDataType type, it seems there is nothing > >special for DWord. > > > > I got the list of functions you mentioned in Lazarus.. Here are all the ones > that can read: As I said before, it is compatible with Delphi. See: http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Win.Registry.TRegistry_Methods -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TRegistry documentation
On Tue, Jun 15, 2021 at 2:44 PM Jean SUZINEAU via fpc-pascal wrote: > I'm not sure which one will best match the DWord type. You'll have to use the Integer / Int64 variant and hardcats it to DWord/QWord. IIRC this is Delphi compatible. Of course it is peanuts to implement Read/WriteD/QWord() yourself if you subclass TRegistry (and call the subclass TRegistry). I have a Windows only implementation of TRegistry which actually implements this. (My implementation of the registry does not support TRegIniFile b.t.w.) -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Abstract classes ignored
On Sun, Apr 18, 2021 at 7:56 PM Travis Siegel via fpc-pascal wrote: >... but the last time I asked them > about pricing, they told me it'd cost $1000 for just delphi 7, and that > only costed $995 when it first came out, nearly 20 years ago. Wow! Long time ago, I bought Delphi2 (it was bundled with Delphi 1, and that was the one I needed, since I was on Win 3.10) for about ƒ200. (€1.00 = ƒ2.20). It came with a full manual (on paper that is). Those were the days -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Directory Tree
On Tue, Apr 6, 2021 at 12:29 PM James Richters via fpc-pascal wrote: > Or Am I going to be better off going graphical with Lazarus for something > like this? TShellTreeView in Lazarus should do exactly what you want. It's not console though. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Hide warning number
On Thu, Mar 25, 2021 at 8:08 PM Ryan Joseph via fpc-pascal wrote: > Is there a way to hide a warning for all files from the command line? The > "not inlined" warnings (6058) are too numerous to even be useful anymore so > I'd like to disable it. From my fpc.cfg: #Don't show the "function X; marked as inline is not inlined" warning -vm6058 -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpreport: can not use two ObjectLists as datasource in one report
On Fri, Mar 19, 2021 at 7:14 PM Michael Van Canneyt via fpc-pascal wrote: > > Done: 0038639 , but i am not able to set the severity to 'feature' > > Hm. Strange. I did it for you. This has been disabled for "normal" reporters, since too many reporters marked their reports as major or even block. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] JSONStringToString question
On Sun, Mar 14, 2021 at 4:15 PM Michael Van Canneyt via fpc-pascal wrote: > Fixed. Thanks for the patch. > There was a second issue, which is now also fixed. You set target to fpc 4.0 The simple patch I made can be backported/merged to 3.2 fixes branch? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] JSONStringToString question
On Sun, Mar 14, 2021 at 2:55 PM Bart wrote: > I think I have a fix, will report it. Reported as https://bugs.freepascal.org/view.php?id=38622 Possible patch attached in the bugreport. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] JSONStringToString question
On Sun, Mar 14, 2021 at 1:49 PM Bart wrote: > Do you know if we have a test suite for this function, so I can test > if there ar regressions when I try to fix it? Found it already. I think I have a fix, will report it. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] JSONStringToString question
On Sun, Mar 14, 2021 at 12:43 AM Michael Van Canneyt via fpc-pascal wrote: > > Do I misunderstand the purpose of this function or is this a bug? > > Seems like a bug. I'll report it then. Do you know if we have a test suite for this function, so I can test if there ar regressions when I try to fix it? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] JSONStringToString question
From : https://www.freepascal.org/docs-html/current/fcl/fpjson/jsonstringtostring.html Function result Pascal string with escaped characters replaced {$mode objfpc} {$h+} uses fpjson; var S1, S2: TJSONStringType; begin repeat write('S: ');readln(S2); S1 := JSONStringToString(S2); writeln(S1); until S2=''; end. C:\Users\Bart\LazarusProjecten\ConsoleProjecten>fpc test.pas Free Pascal Compiler version 3.2.0 [2020/06/04] for i386 Copyright (c) 1993-2020 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling test.pas Linking test.exe 15 lines compiled, 0.2 sec, 233536 bytes code, 10196 bytes data C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test S: \u0041\ A (as expected) S: \u0042 B (as expected) S: \"\u0041\ "A (as expected) S: \"\u0041\" "A" (as expected) S: \u0041\u0042 AAB (Huh??) Do I misunderstand the purpose of this function or is this a bug? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Unicode chars losing information
On Sun, Mar 7, 2021 at 5:31 PM Marco van de Voort via fpc-pascal wrote: > Probably it is not in the BMP and thus needs more position than one. Length(Char) is 5 according to fpc, I see 5 "graphemes", which suggest that all of them fit into 1 WideChar? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Windows Defender considers fp.exe a malicious program
On Fri, Feb 12, 2021 at 9:10 AM Alexander Bunakov via fpc-pascal wrote: > As of trunk r48648, Windows Defender deletes fp.exe after compilation > because it considers it an infected file. It claims that fp.exe is > infected with Trojan:Win32/Fuerboos.E!cl and quarantines the file. I exclude the folders where fpc/lazarus reside from scanning. Also the folders where I develop my programs. If you don't you're bound to get strange bugs and thing like this. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Question about System.Move()
On Sun, Jan 10, 2021 at 12:09 PM Sven Barth via fpc-pascal wrote: > If after the Move only one of the two references is reachable anymore > (because e.g. some internal count variable "ends" the array before that > element) then you don't need to care about increasing the reference > count, cause there is only one reference after all (in that case you > must *not* use an assignment to clear the value, but e.g. FillChar, > cause the reference count must not be touched). Only if you'd really > duplicate the element you'd need to take care of that. I came up with this: Assume that: FData is defined as Array of T (T being generic) procedure MoveDataManaged(StartIndex: SizeUInt; Offset: SizeInt; NrElems: SizeUInt); var i: SizeUInt; begin if Offset>0 then begin for i := StartIndex + NrElems-1 downto StartIndex do begin if IsManagedType(T) then //finalize before overwriting Finalize(FData[i+Offset]); FData[i+Offset] := FData[i]; if IsManagedType(T) then Finalize(FData[i]); FillChar(FData[i], SizeOf(T), 0); //erase old data, not necessary after finalize end; end else begin for i := 0 to NrElems-1 do begin if IsManagedType(T) then Finalize(FData[StartIndex+i+Offset]); FData[StartIndex+i+Offset] := FData[StartIndex+i]; if IsManagedType(T) then Finalize(FData[StartIndex+i]); FillChar(FData[StartIndex+i], SizeOf(T), 0); end; end; end; I tested this with T being Array of Char (so FData being an array of array of Char). Leaving out any of the Finalize statements will make HeapTrace barf at me about unfreed memory blocks. Does it make any sense? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Question about System.Move()
On Sun, Jan 10, 2021 at 12:09 PM Sven Barth via fpc-pascal wrote: > If after the Move only one of the two references is reachable anymore > (because e.g. some internal count variable "ends" the array before that > element) then you don't need to care about increasing the reference > count, cause there is only one reference after all (in that case you > must *not* use an assignment to clear the value, but e.g. FillChar, > cause the reference count must not be touched). Only if you'd really > duplicate the element you'd need to take care of that. > OK, thanks for that. I'll have to get my head around all the caveats. Why did I ask in the first place? Because I was doing some work on TDeque implementation (fixing a simple range check error in TDeque.IncreaseCapacity). Inside that procedure simple loop approach is used and I thought I could maybe improve that, because when we increase capacity by less than a factor 2, you cannot simply move data in one go and speed difference (with moving data > 256 MB) might be significant. I then contemplated all the above issues (I don't want to break current implementation), but as far as I understand things TDeque cannot be safely used with managed types as it is now. There is more code that would need to finalize elements (PopBack, PopFront, Insert, Clear) and certainly it does not support Objects (classes). Which is fine, as long as you know it. We could try to extend it, but now we have Generics.Collections etc: do we already have a better generic Deque (double ended queue) implementation somewhere? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Question about System.Move()
On Sat, Jan 9, 2021 at 8:14 PM Yuriy Sydorov via fpc-pascal wrote: > > So, I'll use a for loop to copy the data. > > > > I assume that doing Arr[Index] := Default(T) will also finalize the > > element if that element ismanaged? > > For class object instances call Arr[Index].Free, for other managed types or > records containing managed types > Finalize(Arr[Index]) should work. In the base class, is there a way to check wether Arr[Index] is an object instance or a managed type or a datatype containing a managed type? Now the for loop (I abandoned the use of Move) does something like this: Arr[NewIndex] := Arr[OldIndex]; //do I have to finalize/free Arr[NewIndex] also in this case? Arr[OldIndex] := Default(T); //I understand this is not enough in those cases I could of course add an (empty) method FinalizeOrFreeElement(Elem: T); to the base class and call that inside the loop, but that feels a bit sloppy. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Question about System.Move()
On Sat, Jan 9, 2021 at 5:12 PM Yuriy Sydorov via fpc-pascal wrote: > > 2. Is it OK if the elements of the array are (or contain) managed types? > > You need to manually finalize/free elements which are overwritten before > calling Move. So, if I move Arr[3] to Arr[1], I first have to finilize/free Arr[1]. After that move the bytes in Arr[3] are exactly the same as in Arr[1] (by definition of how move works) AFAIU. Is that a problem with refcounts, because they would be the same also but the number of copies increased? > Also if you intend to use Move for duplication of elements of managed types, > it is better to use for-loop to copy each > element separately to allow proper increments of references. > > > 3. Are there caveats if T is a specialization of a generic type definition? > Thanks for explaning. OK, since this is a generic class, Systme.Move() can be safe, but it is not guaranteed (almost by definition you never know what is going to be in the specialization. So, I'll use a for loop to copy the data. I assume that doing Arr[Index] := Default(T) will also finalize the element if that element ismanaged? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Question about System.Move()
Hi, This may be a silly question. I use System.Move() to move items in a dynamic array, like Move(FData[0], FData[OldEnd], FStart*SizeOf(T)); Where T is the type of the elements in the array. This seems to work as expected. I have some questions though: 1. Does this depend on the alignment of the array? 2. Is it OK if the elements of the array are (or contain) managed types? 3. Are there caveats if T is a specialization of a generic type definition? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Avoiding File conflicts
On Tue, Jan 5, 2021 at 3:30 PM wkitty42--- via fpc-pascal wrote: > provided the other program opens the file for creation properly (eg: > blahDenyAll), right? Maybe use fmShareExclusive when opening the file. That name suggest you can only open if you are the only one? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Avoiding File conflicts
On Mon, Jan 4, 2021 at 3:19 AM James Richters via fpc-pascal wrote: > I suspect that I happen to see the file is there and try to read it before > the program that created the file is done writing it. > What is the proper way to detect the file is in use so I don't bother trying > to open it until it's done being written? Simple approach? Use filemode = fmOpenRead and use a try..except block to open the file? Opening will fail if the file is locked by another process (triggering the exception). -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On Fri, Nov 20, 2020 at 7:21 PM Sven Barth via fpc-pascal wrote: >> You know that fpc trunk now supports coloured output of the compiler >> (messages)? > > > Only on *nix and those versions of Windows 10 that support VT100 codes. > I know, and there he can see how this capability is detected, hence my reference to the compiler. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] I'm working on automated Help Output for console apps
On Fri, Nov 20, 2020 at 4:38 PM Graeme Geldenhuys via fpc-pascal wrote: > We often have color output and > full Unicode support - so we can output color and emojis to highlight certain > success > or error states in the output. It would be nice to incorporate that into > command > line help output too, but I'll have to test how well FPC supports that, and > how > cross-platform it is. You know that fpc trunk now supports coloured output of the compiler (messages)? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding file to string to the RTL
On Tue, Oct 6, 2020 at 10:12 AM Michael Van Canneyt via fpc-pascal wrote: > // Assume TEncoding.SystemEncoding > Function GetFileAsString(Const aFileName : RawByteString) : RawByteString; > // Specify encoding > Function GetFileAsString(Const aFileName : RawByteString; aEncoding : > TEncoding) : RawByteString; > // Assume TEncoding.Unicode contents > Function GetFileAsString(Const aFileName : UnicodeString) : UnicodeString; > // Specify encoding, return Unicode string. > Function GetFileAsString(Const aFileName : UnicodeString; aEncoding : > TEncoding) : UnicodeString; Now I want to get the contents of a file, which contains either UTF8 or some single-byte encoding, and the filename is NOT in my locale (e.g. it may be chinese, which I cannot represent in RawByteString), but when I specify the filename as UnicodeString I am forced to receive the contents Unicode as well. From my perspective that sucks. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] basic question on begin, end;
On Wed, Sep 23, 2020 at 4:25 PM dano none via fpc-pascal wrote: for i := start to stop do for j := start2 to stop 2 do CompoundStatement if functionally the same as for i := start to stop do begin for j := start2 to stop 2 do CompoundStatement end; A Compound Statement is a statement that consists of more than one statement and as such must be enclosed in a begin/end pair. Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] String literals and code page of .pas source file
On Wed, Sep 9, 2020 at 5:25 PM Tomas Hajny via fpc-pascal wrote: > A simple question - is TLabel.Caption declared as Utf8String No. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] String literals and code page of .pas source file
On Wed, Sep 9, 2020 at 8:37 AM LacaK via fpc-pascal wrote: > I am still confused how this CodePage aware stuff is expected to work and > when implicit conversios are included (as far as I understand here ONLY > declared/static codepage plays role) and when dynamic codepage is taken into > account and when not? You are not the only one. Given that I am on Lazarus, so all my source files are UTF8 encoded I got confused by this: unit1 {$codepage utf8} interface const msCopy = 'Kopiëren...'; Than in main program: Label1.Caption := msgCopy; This does not show the text correctly. I have to include {$codepage utf8} in the source code file that contains the "Label1.Caption := msgCopy;" otherwise it does not display correctly. So basically I have that in all source code that does display text (in a GUI). And if I do so, I can omit the codepage directive in unit1. This is a bit counter intuitive to me. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How reliable are Hashlists in Contnrs
On Mon, Aug 24, 2020 at 9:25 PM Lars via fpc-pascal wrote: > Is there a such thing as a perfect hashlist which never has a collision, No, there are infinite possible items you can add to a haslist, but only a finite number of available hashes. It's the pigeon hole principle: https://en.wikipedia.org/wiki/Pigeonhole_principle -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Is there a FindAllDirs command like FindAllFiles?
On Sat, Jul 25, 2020 at 12:24 AM Bo Berglund via fpc-pascal wrote: > But I would like to enumerate the subdirectories themselves (without > the content). Take a look at how FindAllFiles is implemented. It should be relatively easy to modify it so that it discards files and only adds folders to the list. Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Return value of StrToHostAddr and StrToHostAddr6 in sockets unit
On Wed, May 13, 2020 at 10:40 AM Noel Duffy via fpc-pascal wrote: > > And maybe change the var into an out I agree, it gives unnecessary warning about uninitialized variables. > As I've already learned the hard way, the sockets unit is compiled in > "fpc" mode, so there's no "out" parameters. Otherwise I would definitely > have used one. {$modeswicth out} perhaps? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Compiler mode for code in rtl and rtl-extra
On Mon, May 11, 2020 at 9:30 AM Michael Van Canneyt wrote: > You are correct. The unit is compiled in fpc mode, which means no "result" > variable, no out param (replace with var). > > We can envision changing this mode, but then the whole unit needs to be > verified and checked for correct functioning, Maybe one could apply {$modeswitch out} ? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPCMake and Makefile.fpc question
On Wed, May 6, 2020 at 8:03 AM Sven Barth via fpc-pascal wrote: > Not in the makefile.fpc, That is unfortunate. > but fpcmake allows you to pass a list of supported targets (usually -Tall is > used to allow all targets), but you'd need to pick each one. This does mean > however that everyone that wants to try a target that's not supported has to > generate the makefile (I don't know if Lazarus only has the one compared to > FPC). > For example officially Lazarus doesn't support powerpc-darwin anymore, but > one could probably still use it there with some fixes (I should really test > that...) I would at least want to weed out targets we definitively do not support like embedded platforms and DOS. But in the end that's up to the Lazarus devs. I just wanted to know how that could be done. Thanks @all for the info. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Different behaviour between FPC 2.6.4 and FPC 3.0.4
On Tue, May 5, 2020 at 10:05 PM Rainer Stratmann wrote: > Did I overlooked something? Your function returns a functiontype? Is that intended? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] FPCMake and Makefile.fpc question
Hi, Here's the first line of the Lazarus Makefile: - # # Don't edit, this file is generated by FPCMake Version 2.0.0 # default: all MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin wasm-wasm sparc64-linux As you can imagine that's way more targest than Lazarus actually supports. And the Makefile is cluttered with hundreds of unnecessary lines, which makes identifying an actual bug in the Lazarus build process (which might be in the Makefile) rather difficult. Is it possible to control this in the makefile.fpc file? Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] PLEASE I NEED AN URGENT HELP, cant run Bundle.sh Succefully.
On Mon, Apr 6, 2020 at 2:28 PM mr.jenuine mr.jenuine via fpc-pascal wrote: > ... but when i run the bundle.sh i get error warning as shown below; You run a linux shell script in Windows? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Why external execution so slow? (fixed)
On Wed, Apr 1, 2020 at 5:22 PM Marco van de Voort wrote: > I think I'll put this under a special porunidle option in trunk and fpc > 3.2.0 , so to only trigger this when needed. Hmm.. porunidle -> poRunIdle (to be consistent in namegiving)? Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Range check error warning.
On Wed, Mar 25, 2020 at 10:30 PM wrote: > what? you don't like laughing bearded guys? LUL means penis (and I'm putting it nicely here) in Dutch. Google translate translates it as either asshole (anatomically rahter incorrect), cock, or prick. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Range check error warning.
On Wed, Mar 25, 2020 at 7:48 PM wrote: > [wargames] seems like the winning move is to not play the game. [/wargames] > LUL LUL ?? What does that stand for? Better not say that to someone who speaks Dutch (like me) ;-)) -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Range check error warning.
On Tue, Mar 24, 2020 at 6:00 PM fredvs via fpc-pascal wrote: > OK, I stop. This works? {$mode objfpc} {$apptype console} const foldhiddenbit = byte(7); foldhiddenmask = byte(1 shl foldhiddenbit); currentfoldhiddenbit = byte(6); currentfoldhiddenmask = byte(1 shl currentfoldhiddenbit); intermediate = word(byte(foldhiddenmask) or byte(currentfoldhiddenmask)); intermediate2 = Word(not intermediate); foldlevelmask = byte(lo(intermediate2)); //byte(not (byte(foldhiddenmask) or byte(currentfoldhiddenmask))); begin writeln('intermediate=',intermediate); writeln('foldlevelmask=',foldlevelmask); end. Prints: intermediate=192 foldlevelmask=63 -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Operator precendence of ^
On Mon, Mar 16, 2020 at 8:31 AM Maël Hörz wrote: > But I could not find any mention of the derefence operator ^. As was explained to you in https://forum.lazarus.freepascal.org/index.php/topic,48911.0.html, the dereferencing a pointer (by using ^) isn't an operator. -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fpc trunk = Operator is not overloaded: "Class Of TBlobField" and "Boolean"
On Sun, Mar 8, 2020 at 3:59 PM fredvs via fpc-pascal wrote: > To resume, the problem comes from "if fld1 is tblobfield". No, you miss the point: > if fld1 is tblobfield and (self.fblobintf <> nil) then begin This will not compile anymore since the operator precedence of IS has been altered (to conform to docs and Delphi) So it is now parsed as: if fld1 is (tblobfield and (self.fblobintf <> nil)) then begin Use: if (fld1 is tblobfield) and (self.fblobintf <> nil) then begin Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] ptop and comma.
On Mon, Feb 24, 2020 at 10:11 AM Sven Barth via fpc-pascal wrote: > You are wrong. Halt() sets the error code provided as parameter. Terminate by > itself does not. > Terminate leads to the destructor being called while Halt exists the program > in a hard way. But as Tomas wrote, when a program terminates all memory is > returned to the OS so that is not really a problem. If you really dislike the memory leak (since it's not "nice programming"), maybe you can set ExitCode before calling terminate? (Untested idea (TM)) -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TProcess and zombie processes in *nix systems
On Tue, Jan 21, 2020 at 9:41 PM Graeme Geldenhuys wrote: > 2. Anybody else experience this zombie processes hanging > around in *nix systems? Is there any option in TProcess > to prevent that? https://bugs.freepascal.org/view.php?id=11797 -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TIniFile.WriteString gives file with BOM, bad
On Fri, Jan 10, 2020 at 11:30 PM AlexeyT via fpc-pascal wrote: > Can you add TIniFile.WriteBom property? it's not quite enough, I need to > disable it globally in entire app (I have ~10 ini objects), so > additional global default is needed (like Lazarus has global variables). Open a ticket in the bugtracker? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TIniFile.WriteString gives file with BOM, bad
On Fri, Jan 10, 2020 at 5:57 PM AlexeyT via fpc-pascal wrote: > 1) don't write BOM via WriteString It doesn't AFAICS. The BOM is written in UpdateFile. > 2) if BOM is there, allow ReadString to find section at the file begin: > BOMCHARS[ref] I can read/write IniFiles with BOM with fpc r43847, with and withoud DefautSystemCodePage := CP_UTF8. TIniFile might benefit from a WriteBom (Boolean) property ? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TIniFile.WriteString gives file with BOM, bad
TIniFile manually adds the BOM to the first Line. Then SaveToFile is called, which (if FEncoding = Utf8) will add the BOM again? Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] StringList encoding question
Hi, Consider this code: {$codepage utf8} {$mode objfpc} {$H+} uses SysUtils, Classes; var SL: TSTringList; S: String; begin writeln('DefaultSystemCodePage = ',DefaultSystemCodePage); SL := TStringList.Create; {$if fpc_fullversion > 30200} SL.WriteBom := False; {$endif} SL.SkipLastLineBreak := True; S := 'ä'; //S has CodePage CP_UTF8 SL.Add(S); SL.SaveToFile('slU.txt'{$if fpc_fullversion > 30200}, TEncoding.UTF8{$endif}); SL.SaveToFile('slA.txt'{$if fpc_fullversion > 30200}, TEncoding.ANSI{$endif}); SL.Free; end. Tested with fpc trunk (form a few days ago). It outputs: DefaultSystemCodePage = 1252 (I'm on Windows as you might have guessed) The file slA.txt contains the bytes C3 A4 (which is ä in UTF8 encoding) The file slU.txt contains the bytes C3 83 C2 A4 I struggle to understand why. What is the codepage of the stringlist's internal list of strings (array of TStringItem's)? It seems that the stringlist considers it's internal TStringItem.FString that has #$C3A#$A4 to have a codepage of CP_ACP (always)? Bart -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Strange experience with TJsonConfig.Clear
On Sat, Nov 23, 2019 at 7:47 PM Bart wrote: As I was afraid: User error! Cfg.JSONOptions := Cfg.JSONOptions + [joIgnoreTrailingComma]; This forces a reload of the file (since Filename isn't empty at this point). (B.t.w. fpc trunk raise an error : An unhandled exception occurred at $00438A84: EJSON: Duplicate object member: "Naam" $00438A84 TJSONDATA__DOERROR, line 1388 of ./fcl-json/src/fpjson.pp $0043C593 TJSONOBJECT__DOADD, line 3411 of ./fcl-json/src/fpjson.pp $0043C5CA TJSONOBJECT__ADD, line 3426 of ./fcl-json/src/fpjson.pp That's better than screwing up the file ... ) -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Strange experience with TJsonConfig.Clear
Hi, I experienced some strange behaviour with TJSONConfig.Clear. I'm using fpc 3.0.4 32-bit on Win10-64. (While I do have fpc trunk as well, the program is a Lazaurs GUI program and I don't like using Lazarus (trunk) in combination with fpc trunk.) I have a TJSONConfig that I use to store addresses. var CFG: TJSONConfig ... Cfg.Filename:= Fn; Cfg.Clear; Cfg.Formatted := True; Cfg.JSONOptions := Cfg.JSONOptions + [joIgnoreTrailingComma]; ... //write general info Cfg.SetValue(jpInfoCopyRight, Utf8Decode(ABook.Copyright)); //write addresses, List is a TSTringList Cfg.SetValue(jpaPerson, List, True); This creates a file like "AdresBoek" : { "Info" : { "CopyRight" : "Copyright (c) 2011 by Flying Sheep Inc. & Bart Broersma", }, "Personen" : { "Persoon000" : { "Naam" : "Een", "Voornaam" : "äëï" }, } } So far so good. Now I simply run that code again and now I get: "AdresBoek" : { "Info" : { "CopyRight" : "Copyright (c) 2011 by Flying Sheep Inc. & Bart Broersma", }, "Personen" : { "Persoon000" : { "Naam" : "Een", "Voornaam" : "äëï", "Naam" : "Een", "Voornaam" : "äëï" }, } } It duplicates all entries for Persoon000 (and does that for all following Keys in Personen) and will repeat that upon each run. This of course sucks, because when I change e.g. "Naam", it still writes the old value. And since I don't write keys with empty values (if "Naam" is empty string, it is not stored), I can no longer clear "Naam", because the old value remains and will be read back. Also the filesize grows to very huge very soon. Now when I add a check in the code __after__ Cfg.Clear to see if I still can read the entry with Cfg.GetValue, it is there. Cfg.Clear; //write general info if Cfg.GetValue(jpInfoCopyRight,'')<>'' then writeln('Cfg.GetValue(jpInfoCopyRight) NOT empty'); Cfg.SetValue(jpInfoCopyRight, Utf8Decode(ABook.Copyright)); //write addresses, List,Persons,Def are TSTringList if Cfg.GetValue(jpaPerson, Persons, Def) then writeln('Cfg.GetValues ',jpaPerson,' = TRUE'); Cfg.SetValue(jpaPerson, List, True); Sure enough it ouputs: Cfg.GetValue(jpInfoCopyRight) NOT empty Cfg.GetValues /AdresBoek/Personen/Persoon000 = TRUE Isn't TJSONConfig.Clear supposed to clear all contents? The weirdness in this is: - This only started to happen after unrelated code changes (the code to save was not altered at all), before that I behaved as I expected. - Why does it duplicate the values of Person, but not the value of jpInfoCopyRight? - When I move Cfg.Clear to the line below Cfg.JSONOptions := Cfg.JSONOptions + [joIgnoreTrailingComma], then it behaves normally again. The application is build with -Criot -gh -gt. It raises no exceptions and no memory leaks are reported. I was unable to reproduce the issue in a simple test program that just writes values to a TJSONConfig. (In fact I started out writing simple test programs reading and writing TJSONConfig before trying to attempt to convince my addressbook application to write to a TJSONConfig in the first place) Before you ask: my app doesn't use threads. Any thoughts on this? -- Bart ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal