필터 지우기
필터 지우기

Call activex methods in guide

조회 수: 4 (최근 30일)
Przemyslaw Gontar
Przemyslaw Gontar 2018년 10월 10일
댓글: Przemyslaw Gontar 2018년 10월 11일
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
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.
Przemyslaw Gontar
Przemyslaw Gontar 2018년 10월 11일
I solved problem. I used handles.activex1.StartCtrl in xxx_CreateFcn function instead xxx_OpeningFcn. Now it's worked.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
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.

카테고리

Help CenterFile Exchange에서 ActiveX에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by