Main Content

COM Event Handlers

Use registerevent to register server events. Use events to list all the events a COM object recognizes.

Arguments Passed to Event Handlers

When a registered event is triggered, MATLAB® passes information from the event to its handler function, as shown in the following table.

Arguments Passed by MATLAB Functions

Arg. No.ContentsFormat

1

Object name

MATLAB COM class

2

Event ID

double

3

Start of Event Argument List

As passed by the control

end-2

End of Event Argument List (Argument N)

As passed by the control

end-1

Event Structure

structure

end

Event Name

char array

When writing an event handler function, use the Event Name argument to identify the source of the event. Get the arguments passed by the control from the Event Argument List (arguments 3 through end-2). All event handlers must accept a variable number of arguments:

function event (varargin)
if (strcmp(varargin{end}, 'MouseDown'))  % Check the event name
    x_pos = varargin{5};              % Read 5th Event Argument
    y_pos = varargin{6};              % Read 6th Event Argument
end

Note

The values passed vary with the particular event and control being used.

Event Structure

The Event Structure argument passed by MATLAB contains the fields shown in the following table.

Fields of the Event Structure

Field NameDescriptionFormat

Type

Event Name

char array

Source

Control Name

MATLAB COM class

EventID

Event Identifier

double

Event Arg Name 1

Event Arg Value 1

As passed by the control

Event Arg Name 2

Event Arg Value 2

As passed by the control

etc.

Event Arg N

As passed by the control

See Also

|

Related Topics