Re: [fpc-pascal] client certificate mandatory and verification
Hello, This doesn't seem to have an easy solution right now. Many of the functions needed to set up openssl for this doesn't even seem to have imports in the FPC package. You'd then have to import the functions and implement a custom TSSLSocketHandler, and then hook it using either (fphttpapp.)Application.HTTPHandler.HTTPServer.OnGetSocketHandler or TSSLSocketHandler.SetDefaultHandlerClass(); Some pointers: https://stackoverflow.com/questions/4261369/openssl-verify-peer-client-certificate-in-c https://stackoverflow.com/questions/21050366/testing-ssl-tls-client-authentication-with-openssl https://stackoverflow.com/questions/16291809/programmatically-verify-certificate-chain-using-openssl-api https://stackoverflow.com/questions/3412032/how-do-you-verify-a-public-key-was-issued-by-your-private-ca Best regards, Flávio Em sáb., 23 de mar. de 2024 às 08:47, Jos Wegman via fpc-pascal < fpc-pascal@lists.freepascal.org> escreveu: > Hi, > > Out of the info on the wiki I created a simple Webserver with a > server-certificate. > To get this code working you need to create the necessary certificate. > For this I used xca from https://hohnstaedt.de but you can use OpenSSL to > do the same. > > > [code=pascal] > program webserver; > > {$mode objfpc}{$H+} > > uses > {$ifdef UNIX} > cthreads, cmem, > {$endif} > fphttpapp, > httpdefs, > httproute, > opensslsockets; > > var > fUseSSL: boolean; > const > fCertificatePassword: string = 'hello'; > fCertificateHostName: string = 'localhost'; > fCertificateFileName: string = 'Server.crt'; > fCertificatePrivateKey: string = 'Server.key'; > > procedure route1(aReq: TRequest; aResp: TResponse); > begin > aResp.Content := 'Route 1 The > Default'; > end; > > procedure route2(aReq: TRequest; aResp: TResponse); > begin > aResp.Content := 'Route 2'; > end; > > begin > HTTPRouter.RegisterRoute('/', @route1); > HTTPRouter.RegisterRoute('/2', @route2); > Application.Port := 1999; > fUseSSL :=true; > Application.UseSSL := fUseSSL; > if fUseSSL then > begin > Application.CertificateData.KeyPassword := fCertificatePassword; > Application.CertificateData.HostName := fCertificateHostName; > Application.CertificateData.Certificate.FileName := > fCertificateFileName; > Application.CertificateData.PrivateKey.FileName := > fCertificatePrivateKey; > end; > Application.Threaded := True; > Application.Initialize; > Application.Run; > end. > [/code] > > My questions are: > > *- How can I modify this example to enforce the use of a client > certificate? - How can I verify a client certificate in the server?* > > In the TLS handshake a client certificate is optional but the server can > ensure that it is mandatory. > > Any help, pointers, sample code is appreciated. > > Sincerely, > > Jos > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class
Em sáb., 19 de nov. de 2022 18:27, Sven Barth via fpc-pascal < fpc-pascal@lists.freepascal.org> escreveu: > (...) > >// this kind of constraint that uses T does not work yet >generic TList> = class > procedure Sort; >end; > > (...) > No? Sad, I use this all the time in Java. Best regards, Flávio > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class
Hi, Thanks for the clarifications (although in some aspects I'm more confused now LOL). If you really want the performance gains (and if you're convinced of these gains, of course) maybe you could implement inlined functions for each key native datatype taking an offset for the field. And if you have computed or complex keys, creating an indirection list would probably have speed gains. -- Best regards, Flavio Em sáb., 19 de nov. de 2022 00:26, Vojtěch Čihák via fpc-pascal < fpc-pascal@lists.freepascal.org> escreveu: > Hi, > > > > I specialized my generic abstract class in a different unit with this type: > > > > TRec = record > > A: Integer; > > B: Integer; > > end; > > > > (A is for sorting, B is for testing of stability, i.e. for MergeSort, > TimSort) > > > > and compare function, declared with inline; directive: > > > > function MyComptFunc(const ARec, BRec: TRec): Integer; > > var i, aCnt: Integer; > > begin > > aCnt:=CFComplex; > > for i:=0 to aCnt do > > Result:=(BRec.A-ARec.A); > > inc(CFCnt); > > //InterlockedIncrement(CFCnt); > > end; > > > > The reason for this complex compare function is that it also measure > number of comparisons and it can simulate more expensive comparisons (like > sorting strings). > > > > For a while, I added this unit to the second "uses" section > (implementation) of the other unit, which is impractical, but I had > > temporary access to the compare function. I tested again with ShellSort, > sorting 2'000'000 values takes: > > 1380ms inlined > > 1515ms not inlined, ~9% slower > > 1430ms when compare func. is a parameter ~4% slower > > > > I pass variables by value. But you are right, when I shave the function > like this: > > > > function MyComptFunc(const ARec, BRec: TRec): Integer; > > begin > > Result:=(BRec.A-ARec.A); > > end; > > > > the results are: > > 750ms inlined > > 950ms not inlined, ~21% slower > > 835ms when compare func. is a parameter ~10% slower > > > > so the gain of inlining is higher for sorting primitive types. > V. > > __ > > Od: "Flávio Etrusco via fpc-pascal" > > Komu: "FPC-Pascal users discussions" > > Datum: 18.11.2022 20:45 > > Předmět: Re: [fpc-pascal] How to inline CompareFunc to Sort method in > generic abstract class > > > > > Em seg., 14 de nov. de 2022 15:26, Vojtěch Čihák via fpc-pascal < > fpc-pascal@lists.freepascal.org> escreveu:, > What do you mean by "be inlined"? The 'inline' directive instructs the > compiler (or is it the linker? 😬) to try copying the whole function > inline, also avoiding the call (stack) setup; you can't do this for this > for a general purpose method. > I'm curious how you got that 6% figure, it seems rather large. Is this > comparing the parameter vs virtual method approach or comparing a fully > inline (no indirect call of any kind) sort function to some other option? > Are you passing the variables by reference? > Best regards, > Flávio > > > -- > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to inline CompareFunc to Sort method in generic abstract class
Em seg., 14 de nov. de 2022 15:26, Vojtěch Čihák via fpc-pascal < fpc-pascal@lists.freepascal.org> escreveu: > Hi, > > I wrote a generic abstract class - a list based on dynamic array (i.e. > array of T;) and this class can be specialized elsewhere with any type > (records or classes). > Part of the class is sorting. There are more ways how to deliver *compare > function* to sorting method. I can pass it as a parameter or I can define > it as: function Compare(A, B: T): Integer; virtual; abstract;. But this way > the function cannot be inlined. > > Question: Is there a way how to *inline* compare function to sorting > method in this general purpose generic abstract class? > > Thanks. > > PS: The gain is 6-7%. > Hi, What do you mean by "be inlined"? The 'inline' directive instructs the compiler (or is it the linker? 😬) to try copying the whole function inline, also avoiding the call (stack) setup; you can't do this for this for a general purpose method. I'm curious how you got that 6% figure, it seems rather large. Is this comparing the parameter vs virtual method approach or comparing a fully inline (no indirect call of any kind) sort function to some other option? Are you passing the variables by reference? Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Feature announcement: implicit generic function specializations
Hi, Em sáb., 30 de abr. de 2022 às 09:13, Mattias Gaertner via fpc-pascal escreveu: > > AFAIK it is planned for mode objfpc to support distinguishing types via > template count as in mode delphi: > > type > TMyClass = class > end; > generic TMyClass = class > end; > generic TMyClass = class > end; This seems very likely to generate confusion, doesn`t it? Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
[fpc-pascal] Object-oriented file (path) handling library
Hello, is there something simliar to Java's java.io.File or java.nio.Path for FPC? Google makes me think there isn't... Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC Debug line numbers
2017-11-06 19:49 GMT-02:00 James Richters : > I've noticed that line numbers are sometimes off, sometimes quite a bit when > I receive a run-time error. I had one today, it specified the correct > function that was responsible for generating the error, however the line > number was way off, it reported line 1463 but the entire function in > question goes from line 708 to line 785. There is nothing remotely related > at line 1463, it's a completely unrelated procedure that could not have > possibly been called at the point the runtime error was received.The list > of procedure/function calls was accurate, just not the line number, which > makes it very difficult to figure out exactly what part of the function had > the problem. > > I am using FPC 3.0.4rc1, compiling with the text IDE and I have option > "Generate also backtrace line information" selected. > > Does anyone know what might cause the line numbers to be incorrect? Didn't the unit have any include file? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC install on windows with limited rights
Hi, 2017-11-02 17:54 GMT-02:00 Graeme Geldenhuys : > On 2017-11-02 07:17, Michael Van Canneyt wrote: >> >> The installer is made with inno setup. There are several inno extract >> tools >> available, e.g.: >> http://constexpr.org/innoextract/ > > > Thank you Michael, that worked perfectly. Strange that the inno setup > executable (the FPC installer) doesn't have a parameter to do that itself. I > have seen installers in the past that allows for that, but I don't know what > program they used to generate that installer. Microsoft Installer (oops, now Windows Installer) implement this "natively", and I assume most MSI-based generators/packagers support it. AFAICS it would require quite a few enhancements (and modifications to the user scripts) to abstract away per-machine vs per-user declarations in InnoSetup. FWIW since InnoSetup is scriptable it seems one can implement this manually using a few hacks: https://stackoverflow.com/questions/21556853/make-inno-setup-installer-request-privileges-elevation-only-when-needed Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Underscores in numerical literals - grouping
On Mon, Nov 21, 2016 at 10:09 PM, James Richters wrote: > I use notepad++ Vertical editing ALL THE TIME, you cannot do vertical editing > effectively with a proportional font. For those who aren't familiar with > it, you can hold down ALT and highlight many lines vertically making a very > tall cursor, you can then start typing and what you type will be on all lines > with the tall cursor.. thus you can very quickly and easily shift entire > blocks over, or even fix something on many lines at once. This is very > helpful when you have something that used to be inline and now you want to > make a procedure out of it for example. > The editor can just switch to a monospaced font when the vertical/column selecion-mode is toggled, this is what Eclipse does. BTW SynEdit also supports column selection, it's just not available in the menu. In the Options Dialog you can assign key mappings to Column and Normal Selection Mode. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bug in FPC 3.0.0 (was: Bug in FPC 3.0.0?)
On Wed, Feb 24, 2016 at 9:00 AM, Michael Van Canneyt wrote: > > > On Wed, 24 Feb 2016, Flávio Etrusco wrote: > >> On Wed, Feb 24, 2016 at 8:39 AM, Marco van de Voort >> wrote: >>> >>> In our previous episode, Mark Morgan Lloyd said: >>>> >>>> > (remember recent discussion about IfThen pseudo-function). >>>> >>>> More relevant to your situation, I remember discussion about adding an >>>> identifier to WITH to use as an explicit shortcut, i.e. something like >>>> >>>> with foo= bar do >>>>foo.someField := ... >>> >>> >>> Not relevant since the With code in this case must remain delphi >>> compatible. >> >> >> I, for one, would vote in favor making the documentation discourage >> the use of 'with' and adding a warning in compiler... > > > I don't see why. > > I use "with" extensively. I see nothing wrong with this useful construct. > > The problem of the 'new identifier inserted in scope' exists, but is rare > enough for me to tip the balance in favour of using "with". It has maybe > happened once or twice in 25 years that I got bitten by it. > > I find that perfectly acceptable. > > For people that worry about this, the solution of Jonas should be ample to > detect/avoid mistakes. > > Michael. I loved 'with' while I was learning Delphi/Pascal and hated after the first few months since using it professionaly. I truly believe it warrants/deserves some advice in the documentation, for the beginners. With the code completion in Lazarus there's even less reason to use it - besides any possibly missing compiler optimization... Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bug in FPC 3.0.0 (was: Bug in FPC 3.0.0?)
On Wed, Feb 24, 2016 at 8:39 AM, Marco van de Voort wrote: > In our previous episode, Mark Morgan Lloyd said: >> > (remember recent discussion about IfThen pseudo-function). >> >> More relevant to your situation, I remember discussion about adding an >> identifier to WITH to use as an explicit shortcut, i.e. something like >> >> with foo= bar do >>foo.someField := ... > > Not relevant since the With code in this case must remain delphi compatible. I, for one, would vote in favor making the documentation discourage the use of 'with' and adding a warning in compiler... Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] if-then-else expression
On Feb 2, 2016 7:41 PM, "geneb" wrote: > > (...) > > So it's not solving a /problem/ it's lessening an inconvienence(sp!). > > I would've gone with IIf(). :) > > > g. > The problem with Iff() is: 1) it either retains normal function behavior and thus has to evaluate both expressions (i.e. suboptimal performance and allowing side effects); 2) or add inconsistency by using function syntax but different behavior. Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Methods for autoupdating fpc programs?
On Mon, Oct 5, 2015 at 1:58 PM, Jürgen Hestermann wrote: > > > Am 2015-10-04 um 19:11 schrieb mic...@gmail.com: >>> >>> But that makes no sense to me. If the OS is designed to potentially >>> remove >>> running programs (or parts of it) from memory it cannot allow overwriting >>> the file on disk in any case. When it does so, it cannot remove parts >>> from >>> memory because it may not be available on disk anymore. So it must >>> disallow >>> the disk change from the beginning, otherwise it may not be able to >>> remove >>> anything. >>> >> >> http://askubuntu.com/questions/44339/how-does-updating-running-application-binaries-during-an-upgrade-work >> >> >> http://unix.stackexchange.com/questions/49299/what-is-linux-doing-differently-that-allows-me-to-remove-replace-files-where-win >> >> >> http://superuser.com/questions/251129/moving-a-file-while-its-in-use-how-does-it-work >> > > In these links I didn't find any explanation that tell me if (and if yes, > why) it *sometimes* does not work. AFAIK (and the articles seem to confirm that) no "part is replaced" and no parts are (necessarily) held in memory: a new file is created on disk and the old file is kept on disk, tough not mapped the file name, until all processes that hold "pointers" to the old file are finished. IIRC NTFS works like that too and Windows actively creates locks to files in use to avoid deletion. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] What's wrong with this simple test program
> > Delphi will compile this (like FPC does), but it will fail at runtime. Trust me here, I did the mistake a few times myself when I thought about too many other things. > > Regards, > Sven > Yes and this is just sad. Is there a reasonable case for not disallowing call of constructor as method outside constructors (of the class itself)? Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Brook Framework and Template Engines
On Fri, Dec 12, 2014 at 10:14 AM, silvioprog wrote: > On Fri, Nov 14, 2014 at 11:18 AM, Fabrício Srdic > wrote: >> >> Hello, >> >> What's the current status of the Brook Server Pages project? >> >> What's the recommended template engine to use with Brook Framework? >> >> Best regards > > Hello, > > Just waiting someone to fix this leak problem: > > https://github.com/remobjects/pascalscript/issues/61 > > -- > Silvio Clécio You know that for OSS projects you can't just "wait" and expect it to be fixed, right ;-) Is it really necessary (and optimal) do create a TPSScript for each request or should you cache instances for each thread? What version of PascalScript should I download/checkout to test? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Question about functions returning a string
On Fri, Nov 28, 2014 at 5:54 PM, Ewald wrote: > Hi, > > Take the following function prototype (in {$mode objfpc}{$H+} for the > record): > > Function SomeFunction(const Data: PChar; const Len: LongWord): > String; cdecl; public; > > Looking at the dissasembly of this function, I see that is actually has > three arguments. It looks more like this from an assembler perspective: > > Function SomeFunction(HiddenArgument: Pointer; const Data: PChar; > const Len: LongWord): String; cdecl; public; > > Which is, well, quite fascinating really. What is it doing there? I > suspect it has something to do with the result type of the function, > being a string? > > Can anybody shed some light on this? > > -- > Ewald Are you sure it's not the result that is passed in the first parameter? http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] [OT] Generics and Type Constraints sample
On Fri, Oct 31, 2014 at 12:08 PM, silvioprog wrote: > On Fri, Oct 31, 2014 at 11:23 AM, Sven Barth > wrote: >> >> Am 30.10.2014 20:49 schrieb "silvioprog" : >> > TMath, constructor> = class >> >> It is not yet possible to reuse a type parameter directly in the parameter >> declaration. There already exists a bug report though. >> >> Regards, >> Sven > > Very nice! > > Some link? I will follow it. > Probably this: http://bugs.freepascal.org/view.php?id=25678 It was easy to find just searching "generics" in unresolved FPC tickets ;-) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fgl unit bug in generic class TFPGMap
On Mon, Oct 27, 2014 at 3:45 PM, Sven Barth wrote: > Am 26.10.2014 05:51, schrieb Flávio Etrusco: > >> On Fri, Oct 3, 2014 at 12:42 PM, Dennis Poon >> wrote: >>> >>> I think I found a bug in TFPGMap. >>> Hope some of you can verify it. >>> >>> The bug seems to relate to the binary search used in the method "FIND" >>> but >>> it does not occur for all string key values or at all capacity of the >>> map. >>> Seems only occur at the second item added and when it is certain string >>> values. >>> >>> I tried to debug it but cannot step into the codes of fgl unit so cannot >>> find the cause. >>> >>> Please help. >>> >>> Dennis >>> >>> = >>> unit Unit1; >> >> (...) >>> >>>TMapOfObjects=class(specialize TFPGMap < String, TObject> ) >> >> (...) >> >> I don't see any calls to 'Sort' or 'Sorted' in your code. 'Find', as >> you note, does a binary search thus expects the items to be sorted. >> You can also use 'IndexOf' instead. > > But a map should not need any call to Sort, because it's the map's task to > organize its data structure in such a way that Find does work as it should. > > Regards, > Sven That's my opinion too, I just replied based on the source code. Actually I had written some comments WRT that in my reply but removed it before sending because I don't know the history of the component. I was going to say something like: it's very unfortunate that the "most discoverable" map for FPC is a simple list of pairs and doesn't have clear/standard map API, and instead exposes its guts. Maybe Find should call IndexOf if Sorted = False for now? Regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fgl unit bug in generic class TFPGMap
On Fri, Oct 3, 2014 at 12:42 PM, Dennis Poon wrote: > I think I found a bug in TFPGMap. > Hope some of you can verify it. > > The bug seems to relate to the binary search used in the method "FIND" but > it does not occur for all string key values or at all capacity of the map. > Seems only occur at the second item added and when it is certain string > values. > > I tried to debug it but cannot step into the codes of fgl unit so cannot > find the cause. > > Please help. > > Dennis > > = > unit Unit1; (...) > TMapOfObjects=class(specialize TFPGMap < String, TObject> ) (...) I don't see any calls to 'Sort' or 'Sorted' in your code. 'Find', as you note, does a binary search thus expects the items to be sorted. You can also use 'IndexOf' instead. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] how do I get Run Time info from a published method?
On Mon, Sep 29, 2014 at 11:54 PM, Dennis Poon wrote: > say for example: > > type > TmyClass = class > published > procedure Something (sender : Tobject);virtual; > end; > > var > myClass : TmyClass; > > then somewhere > > AddMethodToQueue(@myclass.Something); > > > Is it possible within AddMethodToQueue, I can query the Run Time Type Info > of the method passed in ? > > > > procedure AddMethodToQueue(const TheEvent : TNotifyEvent); > var aMethodObjectname : String; > begin > //I can already do this > aMethodObjectName := TObject(TMethod(TheEvent).Data).ToString; > > //how do I check the RTTI of TheEvent and get the name of the method > i.e. 'Something'? >//since it is published, it should be possible, right? > > end; > > Thanks in advance. > > Dennis > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal Simply: vObj := TObject(TMethod(TheEvent).Data); vMethodName := vObj.MethodName(TMethod(TheEvent).Code); ? Regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] with statement using mulltiple objects
On Wed, Sep 17, 2014 at 4:38 AM, Frederic Da Vitoria wrote: > 2014-09-17 3:11 GMT+02:00 Flávio Etrusco : >> >> On Tue, Sep 16, 2014 at 8:09 PM, Philippe wrote: >> > on compiler implementation: >> > >> > I read in this list that the group lost months due a "with" problem. >> > >> > People use "with", and I guess lot of people use it! >> > >> > I checked the reference >> > http://www.freepascal.org/docs-html/ref/refsu58.html#x155-16500013.2.8 >> > and >> > there is not any warning ... just: >> > >> > The statement >> > >> > With A,B,C,D do Statement; >> > >> > is equivalent to >> > >> > With A do >> > With B do >> > With C do >> >With D do Statement; >> > >> > without any warning ... >> > >> (...) >> >> Why would it? As people replied in your thread, this has always been >> the behavior (at least in TP and Delphi), so if anything the only >> thing lacking is some minor documentation. >> Also please don't hijack threads. > > > I guess different communities have different rules, but I don't understand > (and I'd better understand if I don't want to do the same mistake): in what > way was Philippe's post hijacking? This question goes to Philippe too, as he > wrote "we may be out of subject" which shows he felt something wrong. > > -- > Frederic Da Vitoria > (davitof) > The mistake was actually mine :-$ I had deleted part of the thread and didn't realize this was the old thread. Sorry Phillippe, and sorry for the noise everybody. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] with statement using mulltiple objects
On Tue, Sep 16, 2014 at 8:09 PM, Philippe wrote: > on compiler implementation: > > I read in this list that the group lost months due a "with" problem. > > People use "with", and I guess lot of people use it! > > I checked the reference > http://www.freepascal.org/docs-html/ref/refsu58.html#x155-16500013.2.8 and > there is not any warning ... just: > > The statement > > With A,B,C,D do Statement; > > is equivalent to > > With A do > With B do > With C do >With D do Statement; > > without any warning ... > (...) Why would it? As people replied in your thread, this has always been the behavior (at least in TP and Delphi), so if anything the only thing lacking is some minor documentation. Also please don't hijack threads. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] with statement using mulltiple objects
On Mon, Sep 15, 2014 at 2:55 AM, Sven Barth wrote: > On 14.09.2014 18:05, Philippe wrote: >> > > Take this example: > > === code begin === > (...) > > procedure TestWith; > var > p: PTest; > begin > New(p); > > with p^ do begin > Prop1 := 42; > Prop2 := 21; > end; > > Dispose(p); > end; > > procedure TestWithout; > var > p: PTest; > begin > New(p); > > p^.Prop1 := 42; > p^.Prop2 := 21; > > Dispose(p); > end; > > begin > > end. > > === code end === > > This is the relevant code generated for TestWith: > > === asm begin === (...) > === asm end === > > As you can see the expression p^ is only evaluated once in the TestWith case > while it's evaluated twice in the TestWithout one. So it's only minimally > faster in this example (one less memory access), but if you use enough > members of TTest it a more or less tight loop it might even be noticeable. > > Regards, > Sven I expected FPC would optimize this (with just -O1) :-( -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Find/open files in search paths
On Sun, Jul 20, 2014 at 7:24 AM, denisgolovan wrote: > Hi all > > Does anybody know if Lazarus IDE has something similar to View units > (Ctrl+F12) tool, but searching in all search paths defined in project > settings? > It would allow to open modules much quicker than using standard Open file > dialog. > > -- > Regards, > Denis Golovan There's the Code Browser. It's not as convenient as the Open Type/Resource dialogs in Eclipse yet - but I bet patches in that regard are also welcome :-) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Dynamic arrays, yet another pitfall
On Sun, Feb 9, 2014 at 12:34 PM, Jürgen Hestermann wrote: > (...) > With the following declaration and code: > > --- > var A,B: array of integer; > ... > SetLength(A,10); > B := A; > SetLength(B,20); > --- > > both variables A and B point to the same array with 20 Elements. > Changing A changes B and vice versa. > But a slight modification > > --- > SetLength(A,0); > B := A; > SetLength(B,20); > --- > > makes both variables A and B totaly decoupled! Although B is still assigned > to be the same as A each variable is now a separate array with individual > lengths and elements. Variable A has the length 0 and variable B is of > length 20. Changing the length for one of them does no longer change the > length of the other. If someone thinks about dynamic arrays as black boxes > without the need to know the details because they are handled in the > background then he will certainly be baffled by this. > (...) In other words: dynamic arrays are like AnsiStrings without the copy-on-write semantics. I'd certainly wish Borland copied the COW semantics :-/ -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Adding files to a tar file
On Tue, Jan 21, 2014 at 10:45 PM, luciano de souza wrote: > Hello all, > > This code should add all the files of a directory in a tar file. > > program e01; > {$mode objfpc}{$H+} > > uses > libtar, sysutils; > > var > archive: TTarWriter; > search: TSearchRec; > > BEGIN > archive := TTarWriter.create('arquivo.tar'); > with archive do > begin > try > FindFirst('/home/luciano/Documentos/*', faAnyFile, search); > repeat > if (search.name <> '.') and (search.name <> '..') then > AddFile(search.name); > until FindNext(Search) = 0; > finally > free; > end; > end; > END. > > The program compiles, but I got an error. The message says that the > first file of the directory can't be opened. > > What is wrong? Probably because Search.Name contains only the filename, but AddFile expects an absolute path (or relative to GetCurrentDir)? > My second doubt is: I am running this program in Ubuntu 13.10. If I > run it in Windows, will a external library be necessary or all the > code is included in lib tar unit? > > Regards, AFAICS all the code is included in the libtar unit. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
OT: (y) WAS: [fpc-pascal] How to stop a HttpApp via request?
>> >> Worked like a charm. Thank you very much Michael! (y) > > > What does (y) mean ? LOL I was puzzled too. And found a "funny" topic in Yahoo Answers :-o But in the end found it's a shortcut for Thumbs Up in Microsoft Messenger. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Understanding virtual methods
On Tue, Aug 20, 2013 at 2:34 AM, Xiangrong Fang wrote: > Hi Flavio, > > Your findings confirmed mine, but not telling me why? I don't know why, maybe FPC used to be more strict about the use of inherited, or the docs are simply wrong. > It seems that the "virtual" keyword has no use at all! It does, and the documentation is correct in this respect. > To confirm this, I just removed the > "inherited" call in TDerived, then re-run the program with or without > "virtual/override", the result is exactly same, i.e. with c2 (declared as > TBase), the following statements ALWAYS calls constructor of TDerived, NOT > TBase: > > c2 := TDerived.Create; > c2 := TBase(TDerived.Create); As I said - or tried to say ;) - in the other post, there won't be a difference when invoking the constructor on a "class literal" directly. The second line will generate the exact same code as the first one; you're instantiating a TDerived instance then "upcasting" it to TBase. > This is not same as the description in: > http://www.freepascal.org/docs-html/ref/refsu26.html Note this page is about methods and you're using constructors in your example. I would recommend you first do your tests on method declarations, and later learn about class references (i.e. "class of" declarations) and constructors. > BTW, the above documents are talking about objects, but I am using classes, > is there any difference here? > > Shannon AFAIU per the first page you sent, you can't shadow/reintroduce a virtual method in an object; when you redeclare a virtual method it overrides the base one. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Build Lazarus Ide - On "make bigide": lazaruspackageintf.pas(102, 1) Fatal: Internal error 2013081601
On Tue, Aug 20, 2013 at 1:54 AM, Osvaldo Filho wrote: > Anyone coud help-me? > > user1@movotcf:~/Documentos/Desenvolvimento/pascal/svn/ex/lazarus1010$ make > bigide > make -C packager/registration > make[1]: Entrando no diretório > `/home/user1/Documentos/Desenvolvimento/pascal/svn/ex/lazarus1010/packager/registration' > /bin/rm -f ../units/x86_64-linux/fcllaz.ppu > /usr/local/bin/ppcx64 -MObjFPC -Scghi -O1 -g -gl -vewnhi -l -Fu. > -Fu/usr/local/lib/fpc/2.7.1/units/x86_64-linux/rtl -FE. > -FU../units/x86_64-linux -Cg -dx86_64 fcllaz.pas > Hint: Start of reading config file /etc/fpc.cfg > Hint: End of reading config file /etc/fpc.cfg > Free Pascal Compiler version 2.7.1 [2013/08/19] for x86_64 > Copyright (c) 1993-2013 by Florian Klaempfl and others > Target OS: Linux for x86-64 > Compiling fcllaz.pas > Compiling registerfcl.pas > Compiling lazaruspackageintf.pas > lazaruspackageintf.pas(102,1) Fatal: Internal error 2013081601 > Fatal: Compilation aborted > make[1]: ** [fcllaz.ppu] Erro 1 > make[1]: Saindo do diretório > `/home/user1/Documentos/Desenvolvimento/pascal/svn/ex/lazarus1010/packager/registration' > make: ** [registration] Erro 2 > (...) >From the git log, revision 25266 introduced a check that forces this error. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Understanding virtual methods
On Mon, Aug 19, 2013 at 10:44 PM, Xiangrong Fang wrote: > Hi All, > > I am reading this document: > http://www.freepascal.org/docs-html/ref/refsu29.html and doing an > experiment with the following code: > > program project1; > {$mode objfpc}{$H+} > type > TBase = class > constructor Create; virtual; > end; > TDerived = class(TBase) > constructor Create; override; > end; > > var > c1, c2: TBase; > c3: TDerived; > > constructor TDerived.Create; > begin > WriteLn('Entering TDerived.Create'); > inherited Create; > WriteLn('Leaving TDerived.Create'); > end; > > constructor TBase.Create; > begin > WriteLn('Entering TBase.Create'); > Writeln('Leaving TBase.Create'); > end; > > begin > WriteLn('Creating a TBase and assigning to TBase variable...'); > c1 := TBase.Create; > WriteLn('Creating a TDerived and assigning to TBase variable...'); > c2 := TDerived.Create; > WriteLn('Creating a TDerived and assigning to TDerived variable...'); > c3 := TDerived.Create; > end. > > > The problem is, it makes NO DIFFERENCE at all in the following cases: > > CASE 1: > > TBase.Create; > TDerived.Create; > > CASE 2: > > TBase.Create; virtual; > TDerived.Create; virtual; > > CASE 3: > > TBase.Create; virtual; > TDerived.Create; override; > > According to the document, "inherited" cannot be used in non-virtual > methods, At least that's the result I would expect :) I can confirm your findings; contrary to the documentation, a simple test works correctly (the compiler prints no warnings or hints, both method and constructor work correctly, calling either a non-virtual from virtual, and virtual from non-virtual). > and it is wrong to use virtual in sub-class. It doesn't say that, it simply says that the redeclaration will not override the base implementation (the different behavior for 'object' is news to me!). FWIW your test doesn't actually "exercise" inheritance, since virtual constructors only make a difference when you call from a class reference (similarly, you'll only see a difference in virtual methods when calling from a base-typed variable). Code>>> var MyClass: TComponentClass = TDataModule; begin MyClass.Create(nil); <<< will instantiate a TDataModule. Code>>> var MyControl: TControl; begin MyControl := TButton.Create; MyControl.ExecuteDefaultAction; <<< will invoke TButton's implementation of ExecuteDefaultAction. > But my test shows the contrary. BTW, I am running Linux on 64bit platform. > > Regards, > Shannon Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Embedded ARM7 and long strings
On Fri, Jul 26, 2013 at 2:21 AM, Carsten Bager wrote: >> > The {$LONGSTRINGS OFF} directive is given at the beginning of the program, >> > and that >> > eliminates any problems with "long strings" using the 2.05 compiler. That >> > does not seem to >> > work with the new compiler. >> > >> > Is there a way around this problem? >> > >> > Carsten >> >> Did you try {$H-}? Sure, AFAIR it was just a shorthand {$LONGSTRING}, > > I tried but it did not change anything. > Carsten > > >> Best regards, >> Flávio Ok, I can reproduce here. Typecasting the array to string fixes the problem. You should file a bug ticket. (And maybe this belonged to the fpc-dev list...) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Embedded ARM7 and long strings
On Wed, Jul 24, 2013 at 4:07 AM, Carsten Bager wrote: > (...) > > The {$LONGSTRINGS OFF} directive is given at the beginning of the program, > and that > eliminates any problems with "long strings" using the 2.05 compiler. That > does not seem to > work with the new compiler. > > Is there a way around this problem? > > Carsten Did you try {$H-}? Sure, AFAIR it was just a shorthand {$LONGSTRING}, but there's no mention of the latter in the manual: http://www.freepascal.org/docs-html/ref/refsu11.html Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] string memory management
On Fri, Apr 19, 2013 at 1:36 AM, Xiangrong Fang wrote: > Hi All, > > I'm studying how pascal manages strings. I wrote a simple test program: > > program stringtest; > {$mode objfpc}{$H+} > uses Classes, sysutils; > function test: PString; > var > s : string; > begin > New(Result); > Result^ := FloatToStr(Random); > // s := FloatToStr(Random); > // Result := @s; > end; > var > i : Integer; > begin > Randomize; > with TList.Create do try > for i := 0 to 9 do Add(test); > for i := 0 to Count - 1 do begin > WriteLn(PString(Items[i])^); > end; > finally > Free; > end; > end. > > The program runs fine, but: > > 1. I don't know whether I have to MANUALLY free memory for these strings to > prevent leak? > 2. Does the IDE provide any facility to analyze memory usage of a program > and report if there are any leaks? (There are Tools/Leak View, but I don't > know how to get .trc file, or is it what I thought. > > Thanks. I think this can answer a few questions: http://www.freepascal.org/docs-html/ref/refsu12.html#x35-380003.2.6 AFAICS your code will leak both the String contents and the PString pointer. You have to store the result from test() and call Finalize or assign '' to it (actually its "dereference"). > var > i : Integer; p: PString; > begin ... > for i := 0 to Count - 1 do begin > WriteLn(PString(Items[i])^); p := PString(Items[i]); p^ := ''; // or Finalize(p^); Dispose(p); > end; Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] "Function header doesn't match" error
On Sun, Mar 31, 2013 at 7:36 AM, Mark Morgan Lloyd wrote: > I wonder whether anybody could throw some light on a curious error. I've > just tried to move a class definition into the interface part of a unit, so > that I could easily add a class helper, but I'm getting an error > > borgumserverinterface.pas(927,24) Error: (3048) function header doesn't > match any method of this class > "TzzConnection.ExecuteSQL2(TStringList,Boolean="FALSE"):Boolean;" > > If I move the class back into the implementation part there's no error. > Simplified code as below: > > interface > > uses > Classes, SysUtils, StrUtils, BorgUMFingerD, BorgUMCode, sqldb; > > type > TzzConnection= class(TObject) > .. > public > .. > function ExecuteSQL2(sl: TStringList; > relaxInuseCheck: boolean= false): boolean; > .. > > implementation > > uses pqconnection, ibconnection, Custom, postgres3dyn, ibase60dyn, Regexpr; > .. > > function TzzConnection.ExecuteSQL2(sl: TStringList; relaxInuseCheck: > boolean= false): boolean; > .. > > It's that final declaration that goes wrong, but I can fix it by moving the > class back into the implementation part. FPC 2.6.2 on Linux x86. > > -- > Mark Morgan Lloyd > markMLl .AT. telemetry.co .DOT. uk The simplified code also fails? Removing the default parameter value from the implementation makes any difference? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TStream descendant to compress/decompress gzip data from another stream
On Thu, Mar 28, 2013 at 8:51 AM, José Mejuto wrote: > El 28/03/2013 1:06, Ewald escribió: > > Google found an old thread on lazarus mailing list about this ("FPC, gzip and stream") but without any solution, everything mentioned there has either the limitations of TCompressionStream/TDecompressionStream (no gzip format) or TGZFileStream (not able to work wit ObjectPascal streams). >>> >>> >>> Hello, >>> >>> .gz is a quite simple format, but it can not be implemented as a TStream >>> (only) descendant because in a single .gz file many files could be added so >>> something like the class to handle .zip files should be used. >> >> >> Sorry to just drop in on this quite late, but isn't gzip a compression >> algorithm and not a file format as such? gzip (the command line utility) >> only compresses one file and *doesn't* put this in a multi-file container. >> To get `multi-file gzips`, you will first want to bundle the files and >> compress this bundle (files -> tar -> gzip) or compress the files separately >> and then bundle them together (files -> multiple separate gzipped files -> >> tar). Or are we talking about a different gzip here? >> > > Hello, > > Just quoting the RFC1952 about .gz format: > > --- http://tools.ietf.org/html/rfc1952 > > 2.2. File format > > A gzip file consists of a series of "members" (compressed data > sets). The format of each member is specified in the following > section. The members simply appear one after another in the file, > with no additional information before, between, or after them. > > --- > > So I think it is legal to concatenate several .gz files and get a final .gz > with several files inside. > > In the other hand, yes, the usual behavior in .gz is to store only one file. > > -- "Members" refer to each available section according to the flags. Re-read this whole paragraph you posted and a few following you'll realize only one "file" is allowed in a gzip file/blob. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Amazon S3
On Thu, Mar 21, 2013 at 1:39 PM, silvioprog wrote: > 2013/3/21 Marcos Douglas >> >> On Thu, Mar 21, 2013 at 12:30 PM, silvioprog wrote: >> > 2013/3/21 Sven Barth >> > (...) >> >> As I said to you, I can help to codify this part... but you didn't >> answer my last question (link #14) and now you talk about "closed >> source". >> If you has some code and it works and you want to put this in Brook's >> sources, I can help you. But if you stay thinking "closed source", >> please tell now. >> I keep wondering If you keep thinking it is more worthwhile closed >> source or open... please tell us so I can be move on. >> >> Thank you. >> >> Marcos Douglas > > > I'll not give the answer now because I have not decided yet (if it will be > closed, free or open source). I don't wanna rush things. And nothing > prevents you from continuing. > > It's not pleasant you spend hours and hours implementing a new feature, and > your concurrent copy it easily to his project and not give the credits to > the author. I want to avoid it as much as possible. > > Sorry for my english please. > > -- > Silvio Clécio A little OT: in what aspect is Habari a rival to your projects? Does it fulfill the licenses? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a proposal about "with" syntax
On Mon, Mar 18, 2013 at 10:42 AM, Sven Barth wrote: > Am 18.03.2013 10:36 schrieb "Xiangrong Fang" : > (...) >> I cannot recall if there is already a notion of "alias" in free pascal, if >> not then we just introduce this idea within the scope of "with" expression. > > Which is why I suggested "absolute" as this already carries the note of "a > is the same as b". > > Though considering that we already have an "alias" token that would also be > an alternative... Reading your comment, maybe "same" is a worth candidate ;-) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a proposal about "with" syntax
On Sun, Mar 17, 2013 at 2:10 PM, Sven Barth wrote: > On 17.03.2013 15:33, Flávio Etrusco wrote: >> >> (...) >> static int IndexOf(List p_list, T p_item); > > > So you're basically just talking about generic methods here? Yes. Or actually not, it also involves allowing non-specialized/not-completely-defined variables. > The Delphi > compatible syntax for your two examples are: > > === code begin === > > function Alias1(Source: T): TAlias1; > > === code end === This time I tried with 2.7.1 :) But it also gives "Error: Generics without specialization cannot be used as a type for a variable". Is something planned regarding this case? Thanks a lot. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a proposal about "with" syntax
On Sun, Mar 17, 2013 at 6:59 AM, Sven Barth wrote: > On 17.03.2013 06:00, Flávio Etrusco wrote: >> >>type generic TAlias1 = class(TObject) >> function Alias1: T; >>end; > > This already works. In 2.7 I assume, because it doesn't work in 2.6.2. Great anyway :) >> function Alias1(Source: T): TAlias1; > > I don't really get what you want to express with that... This is a Java a construction, I don't know whether it exists in other languages. In Java you specify it before the result type. It means the parameterized result is be based on the parameter it receives. You can also "bind" several parameters: static int IndexOf(List p_list, T p_item); -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a proposal about "with" syntax
> On 17/03/2013 12:54, Marco van de Voort wrote: >> >> Since it is a pseudo variable declaration, I would assume VAR syntax and >> just use ":" ? This is indeed better. On Sun, Mar 17, 2013 at 10:51 AM, Martin wrote: > Or maybe it should require a "variable" declaration (or otherwise declared > identifier with fixed type). > > Otherwise it goes into an undesirable direction: > > Function Foo; > begin > with a: SomeInteger do Work(a); > with a: SomeBoolean do Work(a); > end; > > a is first integer, then boolean within the same scope. *Very* confusing. This is what already happens between the members of "aliased" variables, and that's IMO reason for the proposal. So I don't see a problem, on the contrary, it's progress since it needs a more direct/clearer user "error" to be bitten by it. > And very close to the next step (which of course can be rejected by the > compiler) It would be better. > Function Foo; > begin > with a: SomeInteger do begin > Work(a); > with a: SomeBoolean do Work(a); // masking a > end; > end; > > But if the inner a was Integer too, then maybe it should work? Unless it > gets a similar special status like a loop variable? I don't think so. > --- > IIRC in other threads on this topic, some people explicitly stated they > wanted this feature so the would not need to declare "a" first (I may > remember this wrong). > IMHO starting with the first loop hole of allowing an undeclared identifier > to be used, is just opening the door to more and more weakening of the > language requirement. > Besides, it does not hurt, if "a" needs to be declared. My POV is "with" already implies an undeclared variable. Regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a proposal about "with" syntax
On Sun, Mar 17, 2013 at 12:16 AM, Daniel Gaspary wrote: > On Sun, Mar 17, 2013 at 12:07 AM, 印場 乃亜 wrote: >> On 2013/03/17, at 11:37, Flávio Etrusco wrote: >>> Daniel, I find this hack as ingenious as atrocious ;-) >>> But thinking about it a bit, when FPC gets generic methods you can >>> make this kind of workable! > > I was thinking about this, not specifically generic methods, but some > new generic resource. Indeed. What I was thinking would actually need generic functions, bounded generics and generics with type-erasure ;-) So you'd write, say: >>>> type generic TAlias1 = class(TObject) function Alias1: T; end; function Alias1(Source: T): TAlias1; <<<< And yet you wouldn't be able to name the alias... -Flávio PS. I can't believe Embarcadero went for ":" instead of "=" for declaring bounded/restricted generics :-/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a proposal about "with" syntax
> Actually the only thing that makes me uncomfortable about the keyword "as", > is that > it strangely reminds me of SQL. I suppose that isn't a bad thing though. No problem with SQL, but "as" is already safe typecast, remember? ;-) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] a proposal about "with" syntax
On Sat, Mar 16, 2013 at 10:14 PM, Xiangrong Fang wrote: >> > I don't know what's make it complex if there are 2 or more subject in >> > the with? >> >> Context. A conflict case the two object were of the same class. > > > Are you saying this case: > > with MyClassInstance1 as m, MyClassInstance2 do begin > m.Property1 := 123; > Property2 := 456; > end; > > Here you don't know Property2 belongs to which object instance?? No, he's saying that *his hack* using class helper wouldn't cover this case (two objects in the same 'with' clause). Daniel, I find this hack as ingenious as atrocious ;-) But thinking about it a bit, when FPC gets generic methods you can make this kind of workable! > (...) > To summarize, "as" does NOT try to eliminate context ambiguity (also it > won't make a clear context ambiguous), but provided some convenience when > needed. As Sven said this feature has already been requested a few times. I don't remember whether it was permanently vetoed by FPC developers or just is in the to-do, but vaguely remember people arguing it's "un-pascal" because of the local variable/scope - which is unfortunate, because IMO the 'with' syntax is one of the most abominable un-pascal things Borland introduced in the language, and *forcing* the AS syntax (but probably with some other keyword like ALIAS) would make it much more palatable. Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Porting C macro
On Tue, Mar 12, 2013 at 5:30 AM, Darius Blaszyk wrote: > function GETNEXT(x: pLList): pLList; inline; > begin > exit(pLList(pchar(x) - pchar(pLList(nil)^.next))); > end; > > And let LList be declared as: > > LList = record > len: integer; > next, prev: pLList; > name: PChar; > nextname: PChar; > flag: integer; > end; AFAICS you're missing an "address" operator: @(pLList(nil)^.next) Otherwise you decrement by 'next' value - which I hope is zero ;-) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Set size limit
On Mon, Mar 11, 2013 at 10:54 AM, Daniel Gaspary wrote: > On Mon, Mar 11, 2013 at 10:43 AM, Jonas Maebe > wrote: >> A set is basically a bitpacked array of boolean. Element X is set to true if >> you add X to the set, and to false if you remove it again. That means that >> if you have a set with 600 possible values, you need at least 600 bits, >> regardless of how many elements are inside it. >> >> The above also shows an alternative to sets in that case: you can use a >> bitpacked array[TMyEnum] of boolean instead. Of course, then you can't use >> the regular set operators. >> >> Jonas > > Your explanation made the implementation problem clear to me. And the > alternative is interesting. > > Thank you. I was going to raise the possibility of declaring more than one subset using ranges, but I just noticed that {{{ TMySet = set of 300..305; . }}} doesn't compile. Isn't that supported by Delphi? Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Porting C macro
On 3/11/13, Darius Blaszyk wrote: > > > I'm stuck porting a macro from C. Below is the original define. The > part I'm struggeling with is the right most part after the - sign. > > > #define GETNEXT(x) ((LList *)(((char *) x) - ((char *) & (((LList > *)0)^.next > > Does anyone know what is meant with the define? > Obviously LList is a linked list struct that has a prev and next > variable. But what does the & and 0 mean? > > Appreciate any > help. > > Regards, Darius AFAICS they mean "address" and "nil", respectively, so that part will return the offset of "next" inside and item of LList. -Flávio -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Sigsegv with refcounting interface
> > var > vintfl: TInterfaceList; > BTW You should use a IInterfaceList variable > procedure addintf(const aintf: IUnknown); > (...) > addintf(TInterfacedObject.Create); > (...) It's a pity, but I don't know whether it's fixable (or if needs to be "fixed") in the compiler. The TInterfacedObject has RefCount = 0 after construction, so you should always to assign it to a variable. In a sense a RefCounted object only exists while someone has a reference to it, so in that case the object non-existant ;-) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Result: string
On Mon, Mar 4, 2013 at 5:23 PM, Juha Manninen wrote: > On Mon, Mar 4, 2013 at 9:21 PM, José Mejuto wrote: >> What's the expected output of this code ? >> >> function TheA(): string; >> begin >> Result:=Result+'A'; >> end; >> >> writeln(TheA()); >> >> I thought that when the result type is an automated one its value gets >> initialized... Maybe I'm wrong... > > Yes you are wrong. It is very illogical because a local string > variable is initialized to be empty but the return value is not. > Delphi has the same problem. > > I once made even a report about it: > http://bugs.freepascal.org/view.php?id=20907 > > > Regards, > Juha Delphi would present this problem "only" in some situations (which is worse), and it didn't even show a warning when the result is a string :-/ -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Regression? Problem passing a packed record to a overriden, virtual, abstract method in fpc 2.7.1.
On Mon, Feb 25, 2013 at 11:45 PM, Reimar Grabowski wrote: > On Tue, 26 Feb 2013 00:02:33 +0100 > Reimar Grabowski wrote: > >> But from command line it works. So it is not a FPC problem. > I am really sorry for communicating with myself but I have spoken too early. > Now I can reproduce the problem using just FPC, no Lazarus involved. > It gets triggered when compiling with range checking (-Cr) or with veryfying > object method call validity (-CR). > At least now I know where the problem is and can workaround it by disabling > both. > 2.6.2 works correctly. > > R. FWIW even with these settings I can't reproduce the bug. Not even enabling -O3 -Ou. (FPC 2.6 on Win32, compiling from Lazarus) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Bitpacked dynamic array support
You can use sets or TBits. Unless you mean packed arrays of byte or word, etc. In this case you just declare "myvar: packed array of byte". -Flávio On Mon, Dec 17, 2012 at 5:46 PM, denisgolovan wrote: > Hi guys > > It looks like currently FPC does not support dynamic bitpacked arrays. > I wonder how much work it will take to make support for it? > > For some things, it's a really useful functionality. > > -- > Regards, > Denis Golovan > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: File Enumeration speed
On Sat, Jul 28, 2012 at 9:07 AM, leledumbo wrote: >> does the operating system keep an index somewhere ? > > ls doesn't, find does AFAIK. > "find" doesn't have any index over "ls". You may be thinking of "locate" (actually "located") that keeps a textfile with the list of files. Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Creating video files
Apart from _the_ multi-platform commandline video converter, ffmpeg? http://ffmpeg.org/ It's the back-end for WinFF (and most other utilities like these). Also, I would expect VirtualDub to run fine with WINE. -Flávio On Wed, Jun 20, 2012 at 11:00 AM, Krzysztof wrote: > Hmm, external application is nice idea. But VirtualDub is windows > only. Anyone know multi-platform comandline video converter? What I > found is Mencoder. I must test it > > 2012/6/20 Gerhard Scholz : >> In my opinion, the easiest way is to create a series of BMP's and then use >> VirtualDub or VirtualDubMod (I think it's at Sourceforge). >> >> Greetings >> >> - Original Message - >> From: "Krzysztof" >> To: "fpc-pascal" >> Sent: Tuesday, June 19, 2012 3:53 PM >> Subject: [fpc-pascal] Creating video files >> >> >>> Hi, >>> >>> I would like to write video (created from series of bitmaps) to some >>> popular video formats like avi, flv. Is this possible? Has FPC >>> bindings for video librarys? >>> I googled that WinFF (http://winff.org/html_new/) is written in FPC >>> and Lazarus, so I supose that some bindings exists but can't find any >>> in http://wiki.freepascal.org/Multimedia_Programming >>> >>> Regards. >>> ___ >>> fpc-pascal maillist - fpc-pascal@lists.freepascal.org >>> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> >> ___ >> fpc-pascal maillist - fpc-pascal@lists.freepascal.org >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Currency and ABS(-674.59)
On Tue, Mar 6, 2012 at 12:11 PM, Jonas Maebe wrote: > > On 06 Mar 2012, at 13:28, michael.vancann...@wisa.be wrote: > >> As far as I know, Currency is always a scaled int64, and didn't interpret >> the >> request as a request to change that. > > > The problem is that on i386 (and in Delphi on i386), operations on the > currency type are handled using the fpu. (...) This comes as a big surprise to me. I always thought the docs definition (http://docwiki.embarcadero.com/RADStudio/en/Internal_Data_Formats#The_Currency_type) implied the FPU wasn't used. I wonder how that didn't turn out on the rare times I used the Currency type. I'm glad I never worked with banking/financial systems :-$ -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Trim(): incompatibility with Delphi
On Mon, Mar 5, 2012 at 11:36 PM, leledumbo wrote: >> Fpc Trim(): Trim whitespace from the ends of a string. > > Where did you get that? The documentation > (http://www.freepascal.org/docs-html/rtl/sysutils/trim.html) doesn't say > so... > And a simple test confirms the docs (FPC 2.6): ShowMessage(Trim('test ') + Trim (' !')); -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] fcl-web TFPHttpServer component problem
> >> Also the HTTP server is >> implemented as a component (TComponent descendant), so I gather the >> thoughts was that some day they would like it to sit on the Lazarus >> component palette, where it will be dropped onto some form or data >> module - thus rendering that application frozen too. > > It was never meant as such. > > It is meant as the "main program loop", as Leonardo surmised. The component > is meant to be simple. > > And using a TComponent does not automatically mean that it will sit on the > component palette. I use TComponent because I like the automated memory > management it offers; e.g. it also means the TDatamodules it creates for > servicing requests can be owned by the server component itself. > > If you want still to have a "main program", you should use a thread and > create the component in the thread. Which is exactly what happens in a > service application, the intended environment for the component. > > Michael. I have to agree this is a very odd interface. IMHO setting a property is expected to return quickly; a call that's meant to be used as "program loop" should be a explicit method and named accordingly... (Listen/Run/Execute/ActivateAndWait/etc) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Free Pascal 2.6.0rc1 released
Yes, RolByte/Word/Dword/QWord are implemented in 2.6.0rc1. On Mon, Nov 7, 2011 at 8:27 PM, Peter wrote: > HI, > > Does this release include intrinsic ROL & ROR? > 'Bug' 6300 is shown as fixed, but I can find no mention in the new features > list. > > http://bugs.freepascal.org/view.php?id=6300 > > > > > > On 05/11/11 23:27, Marco van de Voort wrote: >> >> Hello, >> >> We have placed the first release-candidate of the Free Pascal Compiler >> version 2.6.0 on our ftp-servers. >> >> You can help improve the upcoming 2.6.0 release by downloading and >> testing this release. If you want you can report what you have done here: >> http://wiki.freepascal.org/Testers_2.6.0 >> http://bugs.freepascal.org/view.php?id=6300 >> Changes that may break backwards compatibility are documented at: >> http://wiki.freepascal.org/User_Changes_2.6.0 >> >> Downloads are available at the FTP server at: >> >> ftp://freepascal.stack.nl/pub/fpc/beta/2.6.0-rc1/ >> >> Enjoy! >> >> The Free Pascal Compiler Team >> >> >> Free Pascal Compiler >> >> Version 2.6.0rc1 >> >> >> ** >> What's New in 2.6.0rc1 >> >> ** >> >> Free Pascal 2.6.0 is a new major version of the Free Pascal compiler. >> >> Please also see http://wiki.freepascal.org/User_Changes_2.6.0 for a list >> of changes that may affect the behaviour of previously working code, and >> how to cope with these changes. >> >> Some highlights are: >> >> Platforms: >> * iPhoneSimulator target >> >> Compiler: >> * Many new language features: >> * Objective-Pascal dialect, supported on all Mac OS X and iOS targets >> * constref parameter modifier for "const by reference" >> * Pascal boolean types with multiple sizes (boolean16/32/64) >> * ISO 7185 language mode (except for I/O). Features amongst others: >> * nested procedure variables >> * non-local goto's >> * Mac Pascal mode improvements >> * nested procedure variables >> * univ modifier >> * Intrinsics >> * sar (shift arithmetic right) >> * bsf/bsr (bitscan forward/reverse) >> * Delphi compatibility mode improvements >> * Nested types, class variables and class local constants >> * Advanced records syntax (no constructors yet) >> * (for..in) Enumerators in records >> * Class and record helpers >> * Generic records, arrays and procedural types >> * Delphi-compatibility of generics improved >> * Scoped enumerations >> * Custom messages for "deprecated" directive >> * Ability to use "&" for escaping keywords >> * New ARM code generator features >> * ARM VFPv2 and VFPv3 floating point unit support >> * Thumb-2 support >> >> Packages: >> * Many improvements to the rtl >> * Many improvements to the database units (fcl-db) >> * Objective-Pascal interfaces to Foundation, AppKit, CoreData and >> WebCore >> * OpenGL headers updated to OpenGL 4.0 >> >> Details about these new features can be found at >> http://wiki.freepascal.org/FPC_New_Features_2.6.0 >> >> See http://bugs.freepascal.org/changelog_page.php for the list of reported >> bugs that have been fixed in this release. >> ___ >> fpc-pascal maillist - fpc-pascal@lists.freepascal.org >> http://lists.freepascal.org/mailman/listinfo/fpc-pascal >> >> > > ___ > fpc-pascal maillist - fpc-pascal@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A list of CORBA interfaces - how?
Oops, seems I completely misread your post. The problem is cite is the kind of (or exactly) the one you're trying to fix :-$ Thanks for Marcos for pointing that out. -Flávio 2011/9/20 Flávio Etrusco : > On Tue, Sep 20, 2011 at 3:28 AM, Graeme Geldenhuys > wrote: >> Hi, >> >> I'm porting some of my old Delphi code which used interfaces >> extensively. Since I moved to FPC years ago, I liked the idea of >> CORBA-style interfaces, and mostly use them under FPC projects. >> >> Anyway, some of my code used IInterfaceList / TInterfaceList, but that >> uses IIInterface, which is an alias for IUnknown, which is COM-style >> interfaces only. >> >> What is the equivalent for CORBA style interfaces? Just a TList storing >> pointers? >> >> Regards, >> - Graeme - >> >> -- > > I've just found this: http://62.166.198.202/view.php?id=6036 > And this really works! :) Even 'as' operator works (so the error > message in FPC 2.4.4 is misleading). > You can iterate over TClass.GetInferfaceTable, and if you declare an > interface name it'll appear there (I checked). Not sure whether > there's some way (or hack) to compare an (unnamed) interface with the > VMT pointer there... > > Best regards, > Flávio > > PS. A few days ago when Marcos Douglas was asking about CORBA vs COM I > didn't find this information :-/ > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] A list of CORBA interfaces - how?
On Tue, Sep 20, 2011 at 3:28 AM, Graeme Geldenhuys wrote: > Hi, > > I'm porting some of my old Delphi code which used interfaces > extensively. Since I moved to FPC years ago, I liked the idea of > CORBA-style interfaces, and mostly use them under FPC projects. > > Anyway, some of my code used IInterfaceList / TInterfaceList, but that > uses IIInterface, which is an alias for IUnknown, which is COM-style > interfaces only. > > What is the equivalent for CORBA style interfaces? Just a TList storing > pointers? > > Regards, > - Graeme - > > -- I've just found this: http://62.166.198.202/view.php?id=6036 And this really works! :) Even 'as' operator works (so the error message in FPC 2.4.4 is misleading). You can iterate over TClass.GetInferfaceTable, and if you declare an interface name it'll appear there (I checked). Not sure whether there's some way (or hack) to compare an (unnamed) interface with the VMT pointer there... Best regards, Flávio PS. A few days ago when Marcos Douglas was asking about CORBA vs COM I didn't find this information :-/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to do conditional compilation with macros
On Sun, Sep 18, 2011 at 9:19 AM, Marco van de Voort wrote: > In our previous episode, Fl?vio Etrusco said: >> > http://delphi.wikia.com/wiki/FreePascal_detection_and_versioning >> > >> > a typical usage: >> > >> > {$if FPC_FULLVERSION> 20204} >> > ? // means greater than 2.2.4 here >> > ?{$ifndef} >> > >> >> Not wanting to hijack the thread but, why isn't there a way to print >> macro values? (There isn't, is it?) > > No. http://bugs.freepascal.org/view.php?id=12935 > > I still think this is a good thing, mostly because this is a way to get > versions etc embedded in the program into the binary without going through > an includefile processor. > > so > > fpc -dfreebsdversion:=`uname -r` > > and then > {$i %freebsdversion%} > > According to Jonas it can also be done via the environment, and for me that > was enough back then (which is why the report is closed). But in retrospect > that is fine for commandline, but harder for IDE usage. (which often allows > to set additional cmdline options, but not specify the environment, > specially not on all targets) > ___ Thanks for the information and tips. I hadn't thought about using environment variables, maybe I'll add it to Lazarus :) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How to do conditional compilation with macros
On Sun, Sep 18, 2011 at 8:35 AM, Marco van de Voort wrote: > In our previous episode, Reinier Olislagers said: >> >> Have got FPC version 2.7.1 [2011/09/17] for i386 on Windows. >> >> What am I doing wrong? > > Not reading manuals? :-) > > http://www.freepascal.org/docs-html/prog/progse5.html#x121-1210002.2 > > so it is FPC_FULLVERSION, not FPCFULLVERSION > > from > > http://delphi.wikia.com/wiki/FreePascal_detection_and_versioning > > a typical usage: > > {$if FPC_FULLVERSION> 20204} > // means greater than 2.2.4 here > {$ifndef} > Not wanting to hijack the thread but, why isn't there a way to print macro values? (There isn't, is it?) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Multiple enumerators per class
On Thu, Sep 15, 2011 at 6:37 PM, Mattias Gaertner wrote: > Hi all, > > I found the Wiki page about the new for-in loop and found a > misinformation. It stated wrongly that it is not possible to > have multiple enumerators per class. It even gave a proposal > for a new feature that did not add anything new. > > I added an example how to add a second enumerator to a class: > > http://wiki.freepascal.org/for-in_loop#Multiple_enumerators_for_one_class > > IMO the proposal was misleading so I deleted it. I hope this is > ok. If not, I will restore it. > > > Mattias How can you use multiple enumerators? I searched it recently and only found that wiki page ;-) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Overloading the increment operator (+=)
On Mon, Sep 12, 2011 at 2:25 AM, Jürgen Hestermann wrote: > > > Flávio Etrusco schrieb: >> >> "+=" can't be efficiently implemented with two operations (since >> concatenating the operand would be unexpected to the user...). > > Why not use "inc(x,y)"? > ___ AFAICS it's not possible either. (Notice I'm talking about operating on an 'object'). What I meant is: MyStringBuffer += 'String'; Is replaced with: MyStringBuffer := MyStringBuffer + 'String'; What if is was: MyStringBuffer := OtherStringBuffer + 'String'; So concatenating the 'String' in the StringBuffer's internal buffer would be unexpected IMO (but maybe just making it safe, even though unexpected, would be ok). Also, since the assignment operator for same type can't overload, I can't make adjustments to avoid "sharing" the buffer so I'm left with using an AnsiString as buffer, or use some self-pointing canary which must be checked on every buffer operation. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Overloading the increment operator (+=)
On Sun, Sep 11, 2011 at 9:22 AM, Jonas Maebe wrote: > > On 10 Sep 2011, at 22:32, Flávio Etrusco wrote: > >> Does FPC allow overloading the += operator? If not, why? > > It is translated into "x:=x+y" at the parser level, and overload resolving > happens later. So once you overload "+" (and := if required), "+=" should > also work. > > > Jonas > Yes, I realize this. I'm revisiting the "StringBuilder" issue, and "+=" can't be efficiently implemented with two operations (since concatenating the operand would be unexpected to the user...). -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Overloading the increment operator (+=)
Hello, If write a declaration without result it complains about invalid syntax; if I add a result it says "impossible operator overload". Does FPC allow overloading the += operator? If not, why? Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Suggestions on array allocation pattern/rules of thumb?
Hello, In Lazarus I found (pseudo)some code like this: procedure DoSomething(...) var v_Results: PInteger; v_ResultCount: Integer; begin v_Result := nil; PrepareData(..., v_Results, v_ResultCount); InternalDoSomething(v_Results, v_ResultCount); end; procedure PrepareData(..., var p_Results: PInteger; var p_ResultCount: Integer) begin for (...) if (...) begin Inc(p_ResultCount); ReallocMem(p_Results, p_ResultCount); end; end; As you might guess my main gripe is about the repeated calls to ReallocMem. The real case in the LCL is far from critical, it's infrequently and the array won't ever be bigger than 10 elements, I just thought it could a good example to hear from someone knowledgeable in FPC heap-allocator about any "rules of thumb" :-) Apart from making the parameters 'out' - ;) - what would you do? 1) This is this ok. 2) Allocate a buffer with maximum size and then trim it after the loop. 3) Declare a type for the maximum size, allocate it on the heap (in DoSomething). 4) Declare a type for the maximum size, allocate it on the stack (in DoSomething). 5) Any other options? Any remarks regarding different scenarios is also appreciated. Thanks, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances
On Sat, Jul 30, 2011 at 6:07 PM, Florian Klämpfl wrote: > Am 30.07.2011 22:54, schrieb Flávio Etrusco: >>>> >>>> Repeating myself, if there isn't something like CodeTools (i.e. only >>>> with text search) is way more difficult to search for operator >>>> declarations. >>> >>> Why? Searching for operator+ is no more difficult than for function add ? >>> >> >> Blanks and linebreaks... Of course if one always use the same editor, >> that supports searching for linebreaks, and often use Regex in it, >> maybe they'll remember whether its Regex flavor uses \b or \s or \w >> for blanks :-/ Of course this is not major, just annoying, since >> you'll rarely need it. > > But the same applies to functions as well? > > nobody provents you to code like > function > > add(...) : ...; > ? > > Searching for add might not be feasible because the symbol could be used > a lot (I know about this because I'am a heavy "jump to symbol by > grep"-user :) > I would argue that the operator is in practice a little more annoying and, well, unnecessary, but you're right that they can be equally "mismanaged". Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances
>> >> Repeating myself, if there isn't something like CodeTools (i.e. only >> with text search) is way more difficult to search for operator >> declarations. > > Why? Searching for operator+ is no more difficult than for function add ? > Blanks and linebreaks... Of course if one always use the same editor, that supports searching for linebreaks, and often use Regex in it, maybe they'll remember whether its Regex flavor uses \b or \s or \w for blanks :-/ Of course this is not major, just annoying, since you'll rarely need it. But maybe if FPC forced the symbol to follow the keyword immediately... ;-) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances
>> >> And there is another advantage of using procedures/functions instead of >> overloading operators: >> You can search for the procedure to look what it actualy does. > > Not if you use function/procedure overloading. Then the situation is > exactly the same as for operators. > Repeating myself, if there isn't something like CodeTools (i.e. only with text search) is way more difficult to search for operator declarations. >> How do you find the code that overloaded an operator? > -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances
On Fri, Jul 29, 2011 at 7:31 AM, Henry Vermaak wrote: > On 29/07/11 06:39, Jürgen Hestermann wrote: >> >> >> Bernd schrieb: >> > Occasionally I hear other people mentioning operator overloading as a >> > must-have feature of any decent language but I wonder what real-world >> > problems they are actually solving with it. >> >> I think operator overloading is a pain. As you said: What is the >> advantage? For me operators should be defined by the language only > > It improves readability, making it more logical. Say for instance you are > working on Galois fields and you have to do arithmetic on the elements like > this: > > g1 + g2 / g3 > > If you don't have operator overloading, you have to do it with functions, > like this: > > gf_add(g1, gf_div(g2, g3)) > > This is not very readable, I'm sure you will agree. They have to be used > carefully, however. That's the problem, you always have to be very careful. They are easy to overlook in the code. You can circumvent type-checking. One more thing for the IDE to support (if it doesn't, you're royally screwed). At least in *Pascal strings are native types, so one less problem (and a big one in C++) to worry. >> clear. But now there is no way back. It's implemented. Pascal moves in C >> direction... > > Troll. C has no operator overloading. > > Henry Of course he meant C++. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances
On Thu, Jul 28, 2011 at 1:59 PM, Bernd wrote: > 2011/7/28 Bernd : >> I have tried making >> use of Interface and TInterfacedObject and this seems to do what I >> want: for example when witing A := A + B the + operator would return a >> new instance and the reference counting would then automatically call >> the destructor of A when it assigns the newly created number. > > I have profiled it > http://imagebin.org/165317 > > procedure Loop(a,b: IFoo); > var > I : Integer; > begin > for i := 0 to 1 do begin > //BN_mul(b.Handle, a.Handle, a.Handle, b.Context); > b := a * a; > end; > end; > > This creates and destroys an object of TFoo everytime and this in turn > will also create and free resources inside OpenSSL, its only spending > 37% of the time doing actually useful work (BN_mul). > > I think I'm not going to continue this route. I can't see any possible > way to make useful use of overloading these operators, other than > making a few lines in other places of the code look a little bit nicer > at the cost of degrading performance by a factor of 3 (for add instead > of mul its even factor 6). > > Occasionally I hear other people mentioning operator overloading as a > must-have feature of any decent language but I wonder what real-world > problems they are actually solving with it. Are other compilers better > at dealing with these problems, is there room for improvement? > > Bernd Implement += and *= operator to avoid allocating new objects? You could also/instead override TObject.NewInstance and FreeInstance to implement a pool of objects. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Partially initializing array of records
On Tue, Jul 19, 2011 at 2:44 PM, Clay Stuart wrote: > Hello Everyone: > I've got an array of records that looks something like this: > type > node = record > foo : array[1..10] of integer; > bar : array[1..10] of integer; > end > var > graph : array[1..5] of node; > begin... > > However, the arrays hold different amounts of numbers. So node[1].foo might > hold 5 numbers while node[2].foo might hold only 2. > My Question... > Is there a way to initialize these numbers somehow. It seems the compiler > won't allow me to partly fill the arrays. If I use them, it appears I have > to use them all the way. > Thank you in advance, > Clay AFAIK no. You'll have to explicitly initialize them with '0'. Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Re: Object Files
On Mon, Jul 18, 2011 at 2:07 PM, leledumbo wrote: >> Are object files platform dependent? > > No >From the rest of your post I guess you mean "yes, they are dependent"? > >> Something tells me they ARE platform independent since they have to be >> linked in. > > Pardon me? That seems unrelated. Object files are basically executables with > external symbols unresolved and no starting point, do you think executables > platform independent? > He's asking exactly this. If there was no difference in calling conventions and every access to the OS was through the RTL it could be cross-platform in this sense (since he's changing the OS but not the processor/architecture). -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Platform independent alternatives
On Thu, Jun 23, 2011 at 3:18 PM, wrote: > Hi, > > I'm porting an app from Delphi to Lazarus when I came across a couple of > functions from the windows unit. Can anyone help me finding the platform > independent alternatives? > > TerminateThread You shouldn't use it, generally speaking. > WaitForSingleObject AFAICT there's no - there can't be ;-) - equivalent. What is the object you're waiting on? > CloseHandle > > TIA, Darius > What object are you closing? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Windows test program
On Thu, Jun 23, 2011 at 12:35 PM, Carsten Bager wrote: > Hi > I have this test program. It compiles and runs (shows) under Delphi (5.0). > I can compile (and run it) it under FPC (2.4.4) but it does not show > anything. I can see it in > the Windows Job list -> Processes but not under Programmes. > Anybody have a hint. > > Regards > Carsten > The program didn't show anything but an empty window, but worked without a problem otherwise (after a commented out the .res so I could compile). Windows 7 32-bit here. FPC 2.4.4 too. -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] When the variable freed in Optimize compile
On Wed, Jun 8, 2011 at 6:17 AM, Jonas Maebe wrote: > > On 08 Jun 2011, at 10:57, Zaher Dirkey wrote: > >> Hi, I know when compile the project with optimize in Delphi the variable >> freed/allocated after the last line used. >> How can i make same in FPC, O3 not worked for me. > > FPC only reuses stack slots allocated for temporary expressions. It does not > reuse stack slots used by variables. > > > Jonas > While we are at it, is this a limitation or by design? > > What if C is string or Interface of TInterfacedObject? > It is the same logic. It's freed only at the end. I recently noticed that this is also true for ansistrings. I see this can avoid lots of errors, but also makes it very ackward to intentionally avoid copies when modifying strings in-place if they are obtained from a function... -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Suffix Trie implementation, please review
I guess you forgot the attachment? ;-) BTW, do you know the hashtrie component? http://www.softcomplete.com/hashtrie.asp Best regards, Flávio On Tue, May 24, 2011 at 1:48 PM, leledumbo wrote: > I've written a unit containing suffix trie implementation. It could be used > for: fast string existence search (could be extended with other information > if required), though takes quite a lot of spaces (O(n^2) for a string where > n is the string length, but grow slower as more strings get added), the > existence search have O(m) complexity where m is the string to search for. > This string to search for could be exact or a substring of previously added > strings. > > Please have a look and try it (a test program is included), open for > suggestions or whatever you want to say. > > > -- ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TimSort
On Fri, May 20, 2011 at 9:26 AM, Marco van de Voort wrote: > In our previous episode, michael.vancann...@wisa.be said: >> > ? >> > Is there already a TimSort implementation in fpc? >> > ? >> > http://en.wikipedia.org/wiki/Timsort >> >> Not to my knowledge. > > One reference implementation in the article (the goolge one) is > "GPL-with-classpath-exception" licensed, the other Python one seems to be > PSF. > > While the PSF doesn't seem to be particularly evil, I think the first step > would be to find a version with a more compatible license. Maybe this one? http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/TimSort.java?view=co ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inherit interface from 2 interfaces
On Fri, Apr 8, 2011 at 6:16 AM, wrote: > > > On Fri, 8 Apr 2011, Zaher Dirkey wrote: > >> 2011/4/7 Flávio Etrusco >> >>> On Wed, Apr 6, 2011 at 1:37 PM, Zaher Dirkey wrote: >>>> >>>> Can i do that? >>>> type >>>> IIntf3 = interface(IIntf11, IIntf2) >>>> >>>> end; >>>> >>>> Thanks in advance. >>>> -- >>>> Zaher Dirkey >>>> >>> >>> For Corba interfaces, yes. Not for COM interfaces. >>> http://www.freepascal.org/docs-html/ref/refse39.html >>> >>> >> I added {$INTERFACES CORBA} but same error ~Fatal: Syntax error, ")" >> expected but "," found~ in the line ~IIntf3 = interface(IIntf11, IIntf2)~ > > The whole idea of interfaces is to avoid multiple inheritance. > > So you can never inherit from more than one interface. > > Also not in CORBA interfaces. The mentioned page of the manual nowhere > states that this is possible. It just says that for CORBA interfaces, > the interface does not descend from IUnknown. > > Michael. My bad, I just answered based on the Delphi implementation. I sent the link just for the sake of "reference". Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Inherit interface from 2 interfaces
On Wed, Apr 6, 2011 at 1:37 PM, Zaher Dirkey wrote: > Can i do that? > type > IIntf3 = interface(IIntf11, IIntf2) > > end; > > Thanks in advance. > -- > Zaher Dirkey > For Corba interfaces, yes. Not for COM interfaces. http://www.freepascal.org/docs-html/ref/refse39.html -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TDOMElement and multiple attributes
> > >> someone@somewhere:~/pascal/Projects/xmldemo$ cat test.xml >> >> >> >> >> >> Looks like the order is governed by the length of the attribute name first >> and then alphabetically. >> Actually it isn't sorted by length, but it's case-sensitive. Mattias wrote: > Yes, that is what CompareDOMStrings does. > Probably for speed reasons. > Indeed, laz_xmlwrite and laz2_xmlwrite both do this, but the example is using xmlwrite.pas from fcl-xml. > This function is fixed in the code. > What do you mean? Best regards. Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] TreeView and Nonrecursion
On Wed, Sep 1, 2010 at 6:20 PM, Bihar Anwar wrote: > On 2 September 2010 3:53:34 AM, Vannus wrote: > >> i probably shouldn't open my mouth, as i don't quite understand the >> question... >> however FRED from the game Freespace let you design missions using a >> treeview. > > Just to make my question clear, for example, I can fill a TreeView control > with particular Registry keys by enumerating registry keys recursively and > put them in the TreeView control; then for performance reason, I attempt to > use a nonrecursive/iterative approach to enumerate registry keys, but how > can I fill the TreeView since a "tree" is naturally recursive? Is recursion > is the only way to achive it? > When reading from registry and populating a treeview, a recursive function is the least of your worries regarding "performance" (or memory, if you're careful). -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] regex vs synregexpr unit
http://delphi.about.com/od/toppicks/tp/delphi-regular-expressions.htm The regex unit in SynEdit is an old version of the code from regexpstudio.com (which seems to be offline) is said to be very slow for processing large sets of data, like a whole file. In SynEdit it`s used to process single lines, and in this situations it seems pretty good. Best regards, Flavio On Sun, Jun 6, 2010 at 12:32 PM, Juha Manninen wrote: > Hi > >> Speed is important to me, but reg-expr features is important as well. >> Actually, I want to include reg-expr as an alternative search mode in >> my general-purpose file search unit. > > Then the SynEdit's version of regexp should be fast enough. > SynEdit editor in Lazarus for example uses it and it's quite fast. > File I/O is the slowest part when searching from files. > > Juha > ___ > fpc-pascal maillist - fpc-pas...@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] FPC bug or brain bug ?
All TObject descendants have a VMT. The destructor is virtual, BTW. -Flávio On Thu, May 27, 2010 at 11:01 AM, Yann Bat wrote: > Hi, > > I don't understand why compilation of the program below failed in fpc > and objfpc mode. In tp and delphi mode it works as expected but in fpc > and objfpc mode the compiler complains : > > blob.pas(17,3) Error: Constants of objects containing a VMT aren't allowed > blob.pas(17,3) Fatal: Syntax error, ";" expected but "(" found > > Since my object has no virtual methods why a VMT ? > > Thanks. > > > {$mode fpc} > program Blob; > > type > TBlob = object > private > fId : LongInt; > > public > constructor Init; > function Id: LongInt; > end; > > PBlob=^TBlob; > > const > NullBlob : TBlob = (fId: 0); > > {=== TBlob ===} > constructor TBlob.Init; > begin > fId:=Random(1024) + 1; > end; > > function TBlob.Id; > begin > Id:=fId; > end; > > var > B : TBlob; > begin > B:=NullBlob; > WriteLn('B : ', B.Id); > > B.Init; > WriteLn('B : ', B.Id); > end. > ___ > fpc-pascal maillist - fpc-pas...@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Where is the best place to declare an array?
On Thu, May 6, 2010 at 7:34 PM, Jonas Maebe wrote: > > On 06 May 2010, at 23:28, Werner Van Belle wrote: > >> In 'human' (haha) terms: >> >> - global variable access: write data into 'ds+constant' >> - local variables: write data into 'ss+bp+constant'. >> >> Since the latter involves a term more I assume it is bound to take more >> time. > > That was true in the days of the 8086 (the former took 6 cycles while the > latter took 9 cycles). On the i386 and i486, both expressions were already > calculated in a single cycle; they only suffered an extra single cycle > penalty in case the address expression used an index (your example only > contains a base). On the Pentium, address expressions containing an index > were also evaluated in a single cycle. On today's deeply pipelined processors > it is extremely unlikely that there is any difference whatsoever in the > number of steps used to evaluate both address expressions (even if the time > required by the i386/i386/Pentium wasn't documented). > > If you wish to read the outdated details of the old Intel processors: > * http://www.inf.puc-rio.br/~inf1018/material/intel.txt (search for > "8088/8086 Effective Address (EA) Calculation") > * http://www.gamedev.net/reference/articles/article205.asp (search for > "Choice of Index Versus Base Register") > > Moreover, the first instruction takes up 10 bytes while the second one takes > up only 7 bytes, which means that the "global array instruction" takes up > more space in the icache (and that's something which actually /is/ very bad > from a performance point-of-view). Combined with how global variables require > indirection (as in "an extra memory load instruction") on RISC processors and > if position-independent code is used (except under some specific > circumstances on the x86-64), often slow down program startup (when the > dynamic linker has to relocate them), and often behave very badly in terms of > data locality (they are often surrounded by unrelated data, as opposed to > local variables where the surrounding data will probably also be used by the > same function), in general my bias would be much more against than in favour > of global variables from a speed perspective (and when not talking about > arrays, an additional advantage of local variables is that they often can be > kept in registers rather than in memory, which is seldom the case for global > variables). > > > Jonas___ Now that's a fantastic explanation, and I guess the OP will be satisfied :-) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] about dynamic array
On Thu, May 6, 2010 at 11:58 AM, Florian Klaempfl wrote: > José Mejuto schrieb: >> Hello FPC-Pascal, >> >> Thursday, May 6, 2010, 3:53:59 PM, you wrote: >> >> c> TList wraps TFPList, which is based internally on an array. So access >> c> is fast; insertion, deletion not. >> >> But it is faster than inserting elements in a dynamic array (unless >> reference counted ones) because it usually moves less amount of data >> (4/8 bytes per element). >> > > Why do you think so? You can also create dyn. arrays of pointers. I guess José is well aware of it, but isn't it a good thing to suggest the use of TFPList to "newbies"? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] optional parameter
2010/5/3 spir ☣ : > Hello, > > A few questions on the topic: > > * Is it possible to define an optional parameter without default value? > > * Is it at all possible for an optional *argument* not to be the last in > actual call? Eg > procedure p(a:Integer=0 ; b:Integer=0) > How can the caller pass b and not a? No and no. > * The ref states: "For dynamic arrays or other types that can be considered > as equivalent to a pointer, the only possible default value is Nil." > Does this apply to any non-atomic type? Which are the "other types that can > be considered as equivalent to a pointer"? Class, AnsiString. > Tried with a record, but cannot make it be accepted by the compiler. Needed > to change the > parameter to be a pointer to the record instead (so the default can be nil), > but this creates a > trap for the calling code. > Else, is there a common trick or workaround? > What trap? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] deprecated syntax is inconsistent.
On Thu, Apr 29, 2010 at 6:44 AM, Michael Van Canneyt wrote: > On Thu, 29 Apr 2010, Graeme Geldenhuys wrote: >> Jonas Maebe het geskryf: (...) > > Jonas tried to explain that this is not possible. > > Consider the following - what you propose - statements: > > Var > A : Integer; > deprecated : Boolean; > > The compiler cannot decide whether the 'deprecated' is a modifier or the > name of a variable. Both are possible (deprecated is NOT a keyword) and > valid. > > With the current syntax: > > Var > A : Integer deprecated; > Deprecated : Boolean; > > The compiler knows in both cases what is meant. > > The matter could be resolved by making 'deprecated' and all other modifiers > into keywords, but that would be a major backwards incompatibility. > > > Michael. But I firmly believe that the breakage would be really really minimal. FPC had made backwards incompatible changes before... Please? ;) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: Re[6]: [fpc-pascal] Published -> Public
On Fri, Apr 16, 2010 at 4:54 PM, José Mejuto wrote: > Hello FPC-Pascal, > > Friday, April 16, 2010, 9:06:45 PM, you wrote: > > FE> Published methods can be found with TObject.MethodAddress, that's how > FE> the lfm hook event handlers (and why Form event handlers are > FE> published). > > Yes, but thats for streamable objects like TForm, or any component, > but I think that that's not the case of TWS objects which are the > widgetset interface, and also all of them are "class procedure". > > Marc says in Lazarus that a "virtual class tree" is formed with such > published methods, I do not know the need of it or the mission, but if > it is OK it is OK ;) for me. > > -- > Best regards, > José Sure, I was just saying that in a different context. I found Marc's observation very weird, and I'm (still) going to check it. Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: Re[4]: [fpc-pascal] Published -> Public
On Fri, Apr 16, 2010 at 8:32 AM, José Mejuto wrote: > Hello FPC-Pascal, > > Friday, April 16, 2010, 8:42:32 AM, you wrote: > > ZD> What useful for put procedure in Publish? > > I do not know :-? I'll ask in the Lazarus list. > > -- > Best regards, > José > Published methods can be found with TObject.MethodAddress, that's how the lfm hook event handlers (and why Form event handlers are published). Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] nested procedure as parameter question
On Thu, Apr 15, 2010 at 2:51 PM, Bruce Bauman wrote: > I am porting a large amount of existing Pascal code (MetaWare) to Free > Pascal. Unfortunately, this code makes extensive use of nested > procedures, and the nested procedures often reference variables in the > enclosing scope. > > I know that I can't pass the nested routine by address to another > procedure; I get errors like the following: > > intjob4_intday.pas(400,47) Error: Incompatible type for arg no. 3: Got > "", expected " variable type of procedure(StdStr04);Register>" > > Can I get around this restriction by inlining the procedure which is > being passed the nested procedure as an argument? > > For example, let's say the A is the enclosing procedure, B is the nested > procedure, and B is being passed as a parameter to C. > > Procedure A; > Procedure B; > > Begin > C(@B); > End; > > Can I inline procedure C? Will this work? (My initial test with fpc > 2.4.0 suggests it doesn't work). > > -- Bruce I don't think this will work, but why didn't you try it? It would be very nice if the nested procedures which don't access outside vars were allowed to be used as non-local procedure... Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Poss FPC Bug.
On Mon, Apr 5, 2010 at 8:29 PM, Justin Smyth wrote: > guys i've been working on a port of an application that uses the Com > IPersist Interface , one of its procedures seems to be wrong , > > > Function GetClassId(clsid:TClsId):HResult; StdCall; > > yet i believe it should be > > Function GetClassId(out clsid:TClsId):HResult; StdCall > > i've checked the MSDN and it says it should be returning a value - > > its defined in C++ as > > HRESULT GetClassID([out] CLSID *pClassID); > > pClassID [out] > > A pointer to the location that receives the CLSID on return. The CLSID is a > globally unique identifier (GUID) that uniquely represents an object class > that defines the code that can manipulate the object's data. > > Delphian > > Ps if i change this in the code , its the FPC that needs to be re complied ? > I've fallen victim of the same 'trap' on a similar function. Arrays are passed "by reference" automatically in 'stdcall' calling convention. Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] More memory leaks and other problems: request for review of probably stupid mistake
> > If you still want to use records, before the Dispose(APResultRecord) > set the ansistring fields to '', this will garantee that the reference > is freed. > Or call Finalize() on them. Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] var parameters under 64-bit GDB?
On Thu, Mar 25, 2010 at 9:41 AM, Graeme Geldenhuys wrote: > Hi, > > I'm using FPC 2.4.1 with GDB 6.8 under Ubuntu 8.04.2 LTS on a all 64-bit > system. > > > All var parameters [even of simple types like Integer, Boolean etc.] show > up as memory addresses instead of their values when debugged. I believe > this is only an issue if 64-bit systems are used. > > What is the actual issue? Limitation of FPC's debug information, > non-Pascal support in GDB, both, other? > > Regards, > - Graeme - The same problem exists in 32-bit. Or does it show as untyped address/pointer? -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] modulo of negative dividend
2010/3/13 Martín Marqués : > I'm checking the mod binary operator, and I found out that if the > dividend is negative, it gives a negative result. AFAIK, mod gives an > integer between 0 and d-1, where d is the divisor. > > Isn't this the right behavior? > > -- > Martín Marqués This is the mathematical definition of modulus, but all programming languages implement the same behavior as the one of FPC. Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] New wiki, ftp and mailing list server planned
On Fri, Mar 12, 2010 at 11:06 PM, Felipe Monteiro de Carvalho wrote: > 2010/3/12 Flávio Etrusco : >> >From the wiki, it's more interesting to pay in Euros, right? >> Is the German PayPal only a localized version, or are they separate >> corporations and I'd have to create a different account? And is there >> a way to use the German site in English? ;) > > It is just a localized version. You can use brazilian portuguese > paypal and send the donation to: > > lazarus_donati...@freepascal.org Thanks. So simply changing the currency to Euros instead of USD will incur in the lower fees? (not to mention that the server will be bought in Germany, right?) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] New wiki, ftp and mailing list server planned
>From the wiki, it's more interesting to pay in Euros, right? Is the German PayPal only a localized version, or are they separate corporations and I'd have to create a different account? And is there a way to use the German site in English? ;) Best regards, Flávio On Fri, Mar 12, 2010 at 7:07 PM, Florian Klaempfl wrote: > As you might have noticed, the server running the wiki (lazarus and > fpc), the mailing lists (lazarus and fpc) and being ftp master (fpc and > lazarus snapshots) had some hick ups during the last months due to > hardware problems so we want to replace it by something more reliable > because this is one of the two main servers of fpc and lazarus. > > If someone is interested in supporting this effort by a donation, please > have a look at http://wiki.freepascal.org/How_to_donate_to_Lazarus > > We plan to get a HP ProLiant Server ML110 G5 (like > http://www.alternate.de/html/solrSearch/toArticle.html?articleId=379777 > sorry about the german link) which is available for 400-500 Eur in > Germany and add some more memory and another hard disk so it can run RAID-1. > ___ > fpc-pascal maillist - fpc-pas...@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-pascal > ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] floating point an FPC
On Mon, Mar 1, 2010 at 6:32 PM, ik wrote: > > http://ik.homelinux.org/ > > > On Mon, Mar 1, 2010 at 23:20, Jerry wrote: >> >> Don't compare floating points. Ever. Now you see why. > > So if I need for example to compare currency or something that is floating > point, how do I do that ? > Let me my 2cent obvious comments too: 1) Just in case you don't know, Curreny is ok in the sense that it's exact - ok, FP is exact in it's own way ;) -, but keep in mind that its precision is just 4 decimal places, so you must be aware of precision loss too. 2) You can determine what is "close enough" for your comparison and use Abs(A - B) < MarginOfError (and of course variants of that code). I vaguely remember some performance problem with Abs (in Delphi or in general? does FP have a signal bit?), so let someone expert chime in to say whether you should Abs or two comparisons intead ;-) Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] String buffer
On Tue, Feb 9, 2010 at 8:50 AM, Honza wrote: > Probably just reinventing the wheel - I was not able to quickly find a > String builder/buffer elsewhere. > > Source code for anyone possible interested is published on a blog (no > ads there, so I hope it's OK to post the link): > > http://freepascal-bits.blogspot.com/2010/02/simple-string-buffer.html > > -bflm Hello, I guess ads wouldn't be a problem anyway ;-) I find a class like this very useful (for some tasks), thanks! This has been suggested on the list a couple of times and I even intended to implement something but didn't have the need since. Some (hopefully constructive) commentaries (and then I would suggest to add to LCL or FCL): 1) It could be called really TStringBuffer; 2) The 'W' methods could be called 'Append'; 3) The GetS method could truncate the string to avoid the copy, as I think the common use will not be Append+Read+Append+Read, but Append+Append+...+Read... Best regards, Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] String types in a wider perspective
On Tue, Dec 1, 2009 at 2:28 PM, Jonas Maebe wrote: > > On 01 Dec 2009, at 18:03, Luca Olivetti wrote: > >> I always protect multithreaded sting access with a critical section. >> Do you mean it is not needed? > > The reference counting of ansistrings/... is thread safe. Accessing the > characters etc > still requires explicit synchronization if at least one writer is involved. > (I guess Jonas intended to avoid a complicate answer, but let me complicate it for you ;-) ... and the AnsiString has refcount = 1. If you access the string through a by-value parameter or assign it to a temporary variable, you're safe too. (unless, of course, some screwed code change the contents of the string in-place - e.g. with a typecast to pchar or some other pointer) -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] readonly variables
On Sun, Nov 29, 2009 at 1:11 PM, Jonas Maebe wrote: > > On 29 Nov 2009, at 16:51, Anthony Walter wrote: > >> Having said all that, Jonas, what is the actual implemented behaviour >> of FPC? Does it 0 initialize heap memory at startup or not? > > I guess you mean global data rather than heap (heap is what is handled by > getmem/freemem/..., and there are no guarantees regarding that memory). > > FPC currently initialises the global data to 0 on platforms that do not do > this by themselves. When it turns global variables into register variables, > it will also initialise such registers with 0. > >> If not, >> what is the justification for not doing so when this has been a long >> established behaviour of Delphi? > > A justification could be that it causes code bloat in case of register > variables, and that platforms which do not zero global data memory by > themselves are usually embedded devices where every operation counts (both in > terms of code size and in terms of energy usage). > > > Jonas___ FWIW, IIRC the last time this issue (global variables initialization) came up some FPC developer explained this was a platform specific behavior and shouldn't be counted on, so I thought MvC was right in this thread up to now... -Flávio ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal