Delphi 程序启动报错 "A call to an OS function failed."

如题,遇到了Delphi程序启动时就报错,错误提示为:"A call to an OS function failed.",跟踪代码分析发现这个错误是在程序初始化启动时执行到Application.Run;这里发生的,一时无头绪,后经多番调查,找到了原因——程序主窗体中重载了WndProc过程,而其中写漏了inherited;这一句!记录下来给自己做个备忘,也提顺便醒其他童鞋们注意这点。

procedure TForm1.WndProc(var Message: TMessage);
begin
  inherited;
  { do sth. }
end;


 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的例子,演示如何在 Delphi 中调用 Python 编写的 DLL 中的自定义函数: 首先,我们需要有一个 Python 脚本,其中包含我们想要在 Delphi 中调用的自定义函数。例如,我们可以创建一个名为 `my_module.py` 的文件,其中包含以下代码: ```python def add_numbers(a, b): return a + b ``` 接下来,我们需要使用 Python 的 `ctypes` 模块将该脚本转换为 DLL。我们可以在 Python 中使用以下代码完成: ```python from ctypes import * # Load the Python DLL python_dll = CDLL("python37.dll") # Load our Python module my_module = python_dll.PyImport_ImportModule("my_module") # Get a reference to our function add_numbers_func = python_dll.PyObject_GetAttrString(my_module, "add_numbers") # Define the argument types for our function add_numbers_func.argtypes = [c_int, c_int] # Define the return type for our function add_numbers_func.restype = c_int # Export our function as a DLL add_numbers_dll = add_numbers_func._as_parameter_ ``` 现在我们已经将 Python 脚本转换为 DLL,并且我们有了对自定义函数的引用。接下来,我们可以在 Delphi 代码中使用以下代码来调用该函数: ```delphi type TAddNumbersFunc = function(a, b: Integer): Integer; stdcall; var PythonDLL: THandle; AddNumbersFunc: TAddNumbersFunc; ResultValue: Integer; begin // Load the Python DLL PythonDLL := LoadLibrary('my_module.dll'); if PythonDLL = 0 then raise Exception.Create('Failed to load Python DLL'); try // Get a reference to our function @AddNumbersFunc := GetProcAddress(PythonDLL, 'add_numbers'); if not Assigned(AddNumbersFunc) then raise Exception.Create('Failed to get function address'); // Call our function ResultValue := AddNumbersFunc(1, 2); ShowMessageFmt('Result: %d', [ResultValue]); finally FreeLibrary(PythonDLL); end; end; ``` 这个例子演示了如何在 Delphi 中调用 Python 编写的 DLL 中的自定义函数。需要注意的是,我们在 Delphi 中使用的函数名必须与 Python 中使用的函数名相同。此外,我们还需要正确设置参数类型和返回类型,以便 Delphi 可以正确地调用 Python 函数。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值