Call activex methods in guide
6 次查看(过去 30 天)
显示 更早的评论
Hello, I want call ActiveX method in GUIDE. So in programmatically way, working example is:
clear; close all; clc;
global h; % make h a global variable so it can be used outside the main
% function. Useful when you do event handling and sequential move
%%Create Matlab Figure Container
fpos = get(0,'DefaultFigurePosition'); % figure default position
fpos(3) = 650; % figure window size;Width
fpos(4) = 450; % Height
f = figure('Position', fpos,...
'Menu','None',...
'Name','APT GUI');
%%Create ActiveX Controller
h = actxcontrol('MGMOTOR.MGMotorCtrl.1',[20 20 600 400 ], f);
%%Initialize
% Start Control
h.StartCtrl;
Now I want to do this (StartCtrl method) in callback in GUIDE. I tried this:
invoke(handles.activex1,'StartCtrl');
Also this:
handles.activex1.StartCtrl
And result is error:
Dot indexing is not supported for variables of this type.
Do you know what I'm doing wrong?
4 个评论
Guillaume
2018-10-10
The main problem is that I don't know what it's called.
You do know what it's called: you gave it the (very poor) name h. And since it's global (not recommended!) you can access it from any other function (and modify it in all sort of bad way, particularly with such a generic name).
The proper way of passing h to a callback is using the handle structure which GUIDE creates, not with global variable. So it seems you're using an hybrid of two different methods (global and handle). As Walter says, if you're using handles, you need to store your h in handles. We see no evidence of that.
For that matter, we see no evidence of you using GUIDE. The activeX control should be created in GUIDE's figure OpeningFcn not in a separate script (where of course, you can't access GUIDE's handle).
So really, we need confirmation on whether you're using GUIDE and if so, what's your GUIDE code to create the control.
回答(1 个)
Jan
2018-10-10
Use the debugger to find out, what handles is.
dbstop if error
Run the code again until Matlab stops. Then check, what type handles is. It should be a struct, but if dot indexing is not supported, I guess that you have overwritten it by accident.
Prefer to store the handle h in the handles struct, which is shared in all callbacks. This is much safer than using global variables.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 ActiveX 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!