Effacer les filtres
Effacer les filtres

Call activex methods in guide

4 vues (au cours des 30 derniers jours)
Przemyslaw Gontar
Przemyslaw Gontar le 10 Oct 2018
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 commentaires
Guillaume
Guillaume le 10 Oct 2018
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.
Przemyslaw Gontar
Przemyslaw Gontar le 11 Oct 2018
I solved problem. I used handles.activex1.StartCtrl in xxx_CreateFcn function instead xxx_OpeningFcn. Now it's worked.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 10 Oct 2018
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by