Python for Delphi builds a bridge between Delphi and the powerful scripting language python, which is very convenient to use. It enables Delphi's gorgeous interface to work with Python's powerful, concise, and stable background logic processing capabilities, it makes the application module clear, the interface is beautiful, and the complex logic in the background is no longer complicated, greatly improving the development efficiency. Some problems that are easy to ignore occur during usage are summarized as follows.
Version
Python for Delphi supports Python 2.3, and the latest and most stable python is 2.4. When using python for Delphi, the system prompts that the python23.dll cannot be found. Follow these steps:
Set the tpythonengine attribute. Set dllname to python24.dll and regversion to 2.4. The most important thing is that uselastknownversion is set to false. Otherwise, dllname and regversion do not work.
Onpathinitialization
Onpathinitialization is an event called when tpythonengine sets the python path, but sometimes it is not called. Why?
When tpythonengine is initialized, it first finds whether there is any corresponding path setting information in the registry. If yes, it reads the information directly from the Registry without executing onpathinitialization. For example, tpythonengine's regversion is 2.4, it goes to the Registry to check whether there is [HKEY_LOCAL_MACHINE/software/Python/pythoncore/2.4/pythonpath]. If there is direct reading, it does not call onpathinitialization, in onpathinitialization, you can set the python library path through the program. After the setting is successful, it will be written to the Registry.
Distribution
1. Install the entire standard Python module and library, that is, the lib directory.
2. Install Python standard modules in the entire DLLs directory selectively.
3. Install python24.dll to the system directory, such as C:/winnt/system32.
4. In the self-written Delphi Program, use the onpathinitialization event of tpythonengine to set the path of LIB and DLLs, and add the directory of the Self-compiled module to the path.
Note: Each path must be separated by a semicolon (';').