Local class definitions lazarus / 62-General ---------------------------------------------------------------------- simone · 2019-10-04 10:35 As far as I know, local class definitions are not allowed, i.e. classes must be defined globally, whereas other local type definitions are possible. For a project where I'm working (a component based software engineering tool), this feature could be useful. So I ask if this possibility will be implemented in the future. Thanks in advance. ---------------------------------------------------------------------- Thaddy · 2019-10-04 10:41 local class definitions? What is not allowed is this:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Test;type   TMyClass = class;beginend;If that is what you mean? But class definitions local to another class are allowed. In many cases you can substitute a class with an -advanced - record. This is allowed: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure Test;type   TMyClass = record;beginend;As well as classes that are local to an implementation section. Which may well be just what you need if I understand the pattern you describe correctly.. ---------------------------------------------------------------------- simone · 2019-10-04 11:38 Thanks Thaddy. You understood perfectly my question. Advanced records is an option that I had not considered. They could be a good substitute of classes in my scenario. Your suggestion is very useful for me. ---------------------------------------------------------------------- marcov · 2019-10-04 11:41 (The reason is probably that a class type generates certain symbols. Allowing the same name to be allocated as local in various places would then make symbols clash or need extra mangling in options, makes this different from other types) ---------------------------------------------------------------------- PascalDragon · 2019-10-05 10:00 Quote from: simone on October 04, 2019, 12:35:33 pmSo I ask if this possibility will be implemented in the future.Class declarations local to a routine won't be allowed. Same for advanced records that are not allowed there either. If you want something private then you have the whole implementation section to do as you please. ---------------------------------------------------------------------- simone · 2019-10-05 10:39 Thanks for all the given suggestions. I know that Object Pascal allows information hiding and specifically encapsulation in many ways. My question arised from my very specific context and it has been inspired by the fact that in a program module it is possibile to declare and define class even if here there are not interface and implementation sections (required only in unit modules). ---------------------------------------------------------------------- PascalDragon · 2019-10-07 07:32 You can think of the program or library module as consisting only of an implementation section. If you need to hide something from other code, then put it in a separate unit (should lead to cleaner code anyway, as code that is related to each other can then be in one unit (or multiple related ones)).