4 ms·
One important aspect (since the topic is the language) is there is nothing special about components in Delphi and Lazarus - they are just built on the language'
by badsectoracula 2y ago
One important aspect (since the topic is the language) is there is nothing special about components in Delphi and Lazarus - they are just built on the language's RTTI features.
In Free Pascal (and Delphi) all classes have a "metaclass" (a class that describes the class) and can be used in conjunction with the RTTI to obtain information about an object at runtime - including its actual class, exposed properties and any optional metadata (like attributes in FP).
This functionality is used by Delphi/Lazarus to serialize and deserialize objects on disk (the form files you mention are such serialized objects but you can serialize other types of objects and in Lazarus -perhaps Delphi too- you can use several file formats) as well as implement the object inspector.
In a way Delphi/Lazarus work kinda like how game engines like Unreal work in that you are working with "live" instances of objects, using generic object inspectors and saving them on disk is done by serializing them (though obviously it is the opposite since Delphi predates most game engines using this approach :-P).
The important aspect with all the above isn't so much the form/component serialization but the language features that make it possible in the first place: metaclasses and RTTI that provides enough information to instantiate and describe objects and classes at runtime.
My own game engine[0] is written in Free Pascal and Lazarus and uses the exact same language features to provide object serialization, property editing and some other stuff (like object diffing that is used for many undo/redo operations). Instead of TComponent/TPersistent (the types Delphi/FCL provide for serialization), it has its own base types that use a more compact file format, optional compressed streams (e.g. for texture data) and external references (for shared assets stored in separate files), but still relies on the same base functionality provided by the language/compiler.
[0] https://i.imgur.com/fypn318.jpg https://i.imgur.com/fypn318.jpg
- pkphilip 2y agoCool! what is the name of your game engine? For some reason the imgur links are banned here in India and so not able to see it.
- HexDecOctBin 2y agoWhat ISP are you using? I am able to open the link on Airtel broadband and both Airtel and Jio cellular.
- badsectoracula 1y agoSorry, i just saw the message. The name is Little Immersive Engine though i do not have it available anywhere publicly. If you can watch YouTube you can see it in action here[0]. FWIW a retro engine[1] i made for an MSDOS game jam a few years ago uses the same functionality, though it relies more on the existing functionality for the editor side instead of Little Immersive Engine which uses its own property editing controls and "root" object for serialization. Actually Little Immersive Engine is based on the retro engine's code (with a bunch of enhancements of course) but the serialization code is very similar (though without the ability to have external assets)[2]. [0] https://www.youtube.com/watch?v=cQEDAtmGRII https://www.youtube.com/watch?v=cQEDAtmGRII [1] https://codeberg.org/badsector/PetraEngine https://codeberg.org/badsector/PetraEngine [2] https://codeberg.org/badsector/PetraEngine/src/commit/14ca1696227984d17dad676ff621e24aa3c3c9dc/Engine/Serial.pas#L555 https://codeberg.org/badsector/PetraEngine/src/commit/14ca16...