Feature that allows passing parameters when creating delphivcl objects #85
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Visual Error Messages
The components of "delphivcl" have a restriction on binding new symbols at runtime and their subsequent reading. For example, the following code snippet displays an error message on the application's interface:
Initially, this problem could be addressed by modifying the library not to raise the "AttributeError" exception when binding or reading an unknown symbol, as shown below:
However, the absence of a symbol in an object should not result in a visual error message, as it provides no useful information to the end user and is also not internationalized.
A suggestion would be to reduce or completely eliminate the visual messages generated by "delphivcl," opting instead to notify the developer through the raising of exceptions.
A viable alternative would be to allow the developer to choose whether to display such messages during development, using an appropriate flag.
When examining the Pascal code of the "WrapDelphi.pas" unit, we can observe the following snippet:
In this snippet, it is checked whether a symbol is present, and if its name is not found, an exception is thrown. This logic is repeated at least 12 times in the "WrapDelphi.pas" unit.
Additionally, error messages are defined as constants in the unit:
ATTRIBUTE DEFINITION DURING CREATION
By default, creating an object in the
delphivcl
environment does not allow the definition of properties during instantiation.Properties can be defined using dot notation (
obj.Caption
) or, less elegantly, through theSetProps()
function.When a new object is instantiated in Python, the
__init__(self, *args, **kwargs):
method is called, allowing parameter passing.Below, a simplified solution is presented that allows the definition of properties during object creation and enables the association and reading of new symbols in objects from the
delphivcl
library.Now, the three objects listed in
comps
can define properties during instantiation and are also capable of associating and reading symbols.It is recommended to execute the entire code at the end of the delphivcl library import, in the
__init__.py
file.