TMyList = specialize TFPGObjectList<TMyClass>;
You see, I think specialize is a spare keyword. Just like this is enough:
var MyArr = new ArrayList<String>();
Pascal rule - declare first, then use. So at least you have to have
type
TMyList = TFPGObjectList<TMyClass>;
var
MyArr : TMyList;
"specialize" can be omitted in Delphi syntax mode.
That really reminds me of 1979's article of "Why pascal is not my favorite language".
One of the reasons - you've to declare a type, prior to passing as a function/pascal argument.
Ok. In Pascal one has to introduce exactly 1 type declaration.
But in C one might want to retype the type declaration every time they pass it as an argument?!
This is how C-like languages code becomes more "wordier" than Pascal.
Historical note: in original C there was no custom type definition. So it was a language requirement to type out the whole declaration again.
Do you see C# also use upper camel case like Delphi? If it's C it should be underscore case. If it's Java it should be lower camel case. C# also has very similar classes and API.
1) Library structure has nothing to do with a language.
Check out this Swift/Objective-C class
NSApplicaiton.
You see methods there: Init(), run(), stop(), terminate().
What conclusion can we make out of that?
Object Pascal invented in 1980s was designed after Swift language invented in 2014!
Why?! methods are named similar!
2) CamelCase or lowercase or UPPERCASE, Pascal doesn't really care. It's case insensitive.
You might want to inspect some FCL packages. LOTS of them are pure lowercase...
I hate to call the Create constructor directly.
a := MyClass.Create('Pascal');
Why don't it just be like this:
you forgot the
new, keyword in front of MyClass to be C compatible.
I'd hate to explain the difference between C++ and Pascal constructors, because I hate to go deeper, stating that C++ classes can reside on stack, while Pascal are heap only... and then virtual methods and virtual constructors...
Instead, I can suggest you to supply an allocation function for each of the class you want to use.
function MyClass(const p: string): TMyClass;
begin
Result:=TMyClass.Create(p);
end;
That's it. With that function you can create classes in the manner you like.
Having to manually Free object is obviously inconvenient, because sometime we forget to Free it and it will leak memory.
That's why the Garbage Collection got so popular idea among PM.
Protect a project from a poor engineer. Poor Engineer = cheaper development.
As a matter of fact, RTL provides a sort of a mechanism for automatic release of hierarchical objects.
But all of them should be TComponent descendant