Well, i understand it too, but i think that .text section (no matter what languaje is used) should the developer's choice if rw or r.
No, because more often then not the OS itself wants to have sections containing code to be read only (especially if some security checks are enabled).
Yes, but we are talking about debugging things and tool specific. Production code will be rip off this. And this is formal case of use and it's supported by linkers (but i haven't got it ). But it's a BAD idea to do read-only sections of .text (see above, we agree) as read-write even on debug (it can conceal other errors of protected access).
Yes, but i dislike it a lot. It won't be portable between OSes. And if this could be avoided by system calls... should not be avoided by user compilation/linker option as a preferred choice?
Then use conditional compilation. I've done the same for the thunk generation code for TVirtualInterface in unit Rtti (see here). If you're working on such a low level you simply can't work around doing OS-specific things.
i will see, but it's same problem with differente aproach. It would ok for all OSes support, not OS-specific. I think it's bad idea.
Well, here i disagree with you. It's a nonsense that one can do (and free pascal documents it) how to make a memory manager (quite lower level) by redirecting all, but doesn't allow for a higher level to redirect Tobject having the middle-level structures to do it easily in methods (like afterconstruction and beforeconstruction that are really suited for it)
Because the memory manager is something that was also provided by TP and Delphi. Especially the later used it to allow common memory use across library boundaries.
So if delphi and TP would give the TObject facility, will be doing it?. I think it's not the only way for doing things.
And if even these structures were to be read-only, not using a method for TObject to pass him a Procedure for being called for TObject (like a method TObject.SetAfterCreationProcedure (MyProcedure)). TObject.AfterCreation is like abstract method. It can be never executable for user (it's empty), only for a descendant class who overrides it. So all TClass=class definitions (without anything) or Tclass = class (TObject) would do nothing (and empty call if not optimiced by compiler) and a lot of code that could be using this great potential debug facility is simply evaporated. I can't agree with that.
Even it's worse. AfterCreation is triggered by compiler, not dev. So i cannot accept "The way of doing pascal things" as a dogma. I think it has potential beneficts if redirected by a developer who knows. And it can be done and it can be done even in pascal way (as explained in the example) for only this method accept redirection.
It is simply not the desired functionality to be able to modify TObject's behavior in such a way. You had the example of setting a function variable so that AfterConstruction calls it, but what if two different units want to do that? One could solve this of courrse by either saying that such a function needs to call the previously set function or that there'll be a list of function variables, but what if the behavior of these functions is mutually exclusive? And even if one says that this function variable is write-once then this would leave the problem that the order of unit initialization is not necessarily guaranteed and thus adding or removing a unrelated unit might lead to a complete different behavior of the complete class hierarchy.
So, no, there is no desire to change this.
I agree, but same reasoning could be made for a memory manager. If two units "race" for a memory manager, will crash. So i don't like that one argument is used for one thing, but not for others.
And also, i agree with this, but should be programmer's choice. A compiler cannot prevent all bad coding. It's like if i have a hammer with a plastic head for not making damage in my fingers. Give me a complete hammer, and i will take my gloves and do the job better.
Then there are the more (philosophical) questions: If FPC would allow dinamically redirects (like C++) or not.
Please highlight where C++ does have dynamic redirects.
An example:https://www.usenix.org/legacy/publications/library/proceedings/usenix98/full_papers/hjalmtysson/hjalmtysson.pdf
there are differente ways to to similar things in C++. And there is literature in c++ for dynamic changes. But it shouldn't be the pascal way. Class in pascal inherits from TObject, not from scratch. And debugging from TObject has sense by how its classes implemented in pascal, but the same thing has not the same sense and utility in C++
here is such a feature in Delphi that is not yet implemented in FPC: TVirtualMethodInterceptor
However it is rather high level (if you look at this example you might notice what I mean) and also it only replaces the VMT of an instance instead of adjusting the VMT of the whole class type. Though once we implement this as well we could in theory expose the low level functionality as well and make it possible to adjust the VMT of a class type instead of an instance.
YES! this is the common ground i'm talking. It's a middle-level, full OSs support and could be expanded to class type as a TOOL, not as a way of doing things... And yes, it can do break havoc, but these are for very specific questions.
When i was reading this i wanted to give (to PascalDragon) a big hug full of kisses. Really thanks for all the responses for a (perhaps) too enthusiasthic dev

. This is the behaviour i think will be ok and not all the "tricks" and "patching ideas". It could be done or not by fpc devs, but i won't code hijacks unless Really Really Needed.
The bottom line is that if you want the ability of making unrestricted modifications to low-level classes which are immediately accessible to the entire system you should be using Smalltalk.
No, i'm talking of doing limited access from dev's view on code by restricted means Like TVirtualMethodInterceptor. I do not like to expose the read only memory in production. And even is a bad idea to expose it in this case.
It's, by far the best strategy:
1.- Being higher level
2.- Valid for all OSes.
3.- Cleaner syntax.
4.- Narrow access.
5.- Protected memory
6.- Changes in internal VMT would be supported by changes on the method, no FPC compiler version hell
But this can't be done by developers, because is on compiler ground and his internals and only for FPC devs.
@ToAll: I have learned a lot with this thread. Many thanks..!!
