Hello. I still do not understand if it is possible to "advertise" myself.there is the Announcement 3rd party group which is for this purpose.
I made a small library that implements something kinde a smart pointers. A simple record that provides automatic removal of temporary objects when the function ends.Yes there is a difference between delphi and FPC on how it handles unassigned interface variables, while delphi waits until the exit of the current procedure to clean up the stack and decrease the reference counter, fpc will decrease it the moment its not used any more and release it immediately. I haven't seen your library yet but if its interface based then it will not work.
Instead of writing something like:
SomeObject1 := nil; SomeObject2 := nil; SomeObject3 := nil; try SomeObject1 := TSomeObject1.Create; SomeObject2 := TSomeObject2.Create; SomeObject3 := TSomeObject3.Create; <...> finally SomeObject3.Free; SomeObject2.Free; SomeObject1.Free; end;
you can write like:
uses AutoScope,<...>; <...> procedure SomeProc; var Scoped: TScoped; <...> begin SomeObject1 := Scoped[TSomeObject1.Create] as TSomeObject1; SomeObject2 := Scoped[TSomeObject2.Create] as TSomeObject2; SomeObject3 := Scoped[TSomeObject3.Create] as TSomeObject3; <...> end;
I've heard fears that the compiler can delete a variable before it runs out of scope, just when it's no longer used. Although I could not find such behavior for the records.
https://github.com/pda0/AutoScope (https://github.com/pda0/AutoScope)
this code will not work in current FPC:
var List: TStringList; begin List := Auto(TStringList.Create).Instance; // Do stuff with List... // No need to free anything. // Will automatically free contained object when interface goes out of scope. ie. at end of procedure/method. // Copes with exceptions - no need for try finally end;
I already showed it works some time ago, Maciej... Ok, adapted example...: 8-) O:-)
I agree. I am following your efforts as you now.I already showed it works some time ago, Maciej... Ok, adapted example...: 8-) O:-)the new switch SCOPED_INTERFACE_DESTROY would be not bad.
and at least to be able to "mark" a type as for auto initialization / finalization when exiting a scoopWell, you can read my example code as doing just that: mark- by using the double declaration - .
yes i know ... ARC i good but the bookkeeping can be broken very easy...In the case of what Maciej is trying to achieve: no, it can't.
i read the whole communication of maciej with some of the core dev few months ago ... but i has left with the impression that there is some kind of resistentce ...Well, I read that too... Point is that devs are protectors of the language, almost all of them with a scientific qualification, and demand the highest standards (much higher than a commercial company demands).
this code will not work in current FPC:
var List: TStringList; begin List := Auto(TStringList.Create).Instance; // Do stuff with List... // No need to free anything. // Will automatically free contained object when interface goes out of scope. ie. at end of procedure/method. // Copes with exceptions - no need for try finally end;
https://bugs.freepascal.org/view.php?id=26602
https://bugs.freepascal.org/view.php?id=30409
...
(I hope Maciej and devs agree that this is, just about, a proper summary)
nooo im completely on maciej side ... just wondering about the resistance...thanks :). Some resistance is sometimes good. It help to reflect (new ideas and roads) and help to keep humility, which is important in this kind of development. IMO a little lower resistance would be better
Why? because I just showed you it is possible already (with some quirks) and in the near future even easier?
*Sigh*. When I said, "It's a good job I don't use this anymore!" I meant "it's a good job I don't use the code based on my IcaAutoFree/TcaAutoFree classes anymore".Thats' ok. I so overheated in this discussion I simply *know* you had to sigh after re-reading my own comments.,
No problem!Apart from a slight edit in your remark:
Can you clarify what you wrote earlier. As I understand it Maciej is working on an Auto mechanism which will be ready ina few months.[this is undefined. Time has no limits But will this feature be limited to Delphi mode? And on a more general level what are the advantages and disadvantages of Delphi mode vs Objfpc mode. I have always used Objfpc mode because that's the default, and it seems to work fine for me. Would I gain any advantage by using Delphi mode?
this is a concept that is amazing.... and not seen elsewhere on sourcecode level.+1 ;)
Why? because I just showed you it is possible already (with some quirks) and in the near future even easier?
I already showed it works some time ago, Maciej... Ok, adapted example...: 8-) O:-)Using Lazarus 1.8.0 RC3
it fails with a couple of error messages which each say:you need to use latest FPC trunk. Lazarus is shipped with latest stable version of FPC.
caauto.pas(27,48) Error: Impossible to overload assignment for equal types
Any ideas? Is this a typo? Should just one of those Implicit lines be in there?