控制外部程序中的输入项,卡在了TDateTimePicker这个控件

比特灵 2017-12-14 06:33:02
对一个外部程序改变输入项中的值,然后触发提交按钮,对文本框、下拉框都可以正常赋值,但是TDateTimePicker控件不行,找不到办法。
以下代码不起作用:

time1 := TDateTimePicker(FindControl(nDateTime[1]));
if time1 <> nil then
time1.DateTime := strtodatetime('2017-11-11');


从网上抄来一个自定义获得实例对象的方法也不行:

function FindControlEx(Handle: hWnd): TWinControl;
var
OwningProcess: DWORD;
ControlAtomString: string;
RM_GetObjectInstance: Cardinal;
begin
result := nil;
if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0)
and (OwningProcess = GetCurrentProcessId)
then
begin
ControlAtomString := Format('ControlOfs%.8X%.8X',
[GetModuleHandle(nil), GetWindowThreadProcessID(Handle, OwningProcess)]);
if GlobalFindAtom(pchar(ControlAtomString)) <> 0 then
begin
result := Pointer(GetProp(Handle,
MakeIntAtom(GlobalFindAtom(pchar(ControlAtomString)))))
end
else
begin
RM_GetObjectInstance := RegisterWindowMessage(pchar(ControlAtomString));
result := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
end;
end;
end;


求指点...
...全文
381 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
比特灵 2017-12-21
  • 打赏
  • 举报
回复
引用 3 楼 a295281315 的回复:

time1 := TDateTimePicker(FindControl(nDateTime[1]));
if time1 <> nil then 
    time1.DateTime := strtodatetime('2017-11-11 12:12:12');
试下是否可以 ?
不可以,都是这个错误:access violation at 0x0053c1b3
秋天之落叶 2017-12-20
  • 打赏
  • 举报
回复
time1.Date属性试一试行不行?date和datetime有区别的。
Mr Dang 2017-12-18
  • 打赏
  • 举报
回复

time1 := TDateTimePicker(FindControl(nDateTime[1]));
if time1 <> nil then 
    time1.DateTime := strtodatetime('2017-11-11 12:12:12');
试下是否可以 ?
秋天之落叶 2017-12-18
  • 打赏
  • 举报
回复
“外部程序改变输入项中的值”可不可以改为 使用接口传输和接收数据,再显示,再提交?
比特灵 2017-12-18
  • 打赏
  • 举报
回复
找到变通的解决办法: 模拟点击输入的位置,例如点击年,然后模拟键盘输入2016即可,此方法无法获得自己输入的内容是否正确,就是仍然无法获得该控件的内容。 出错关键字: access violation at 希望给相同问题的朋友留个思路。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧