Azzera filtri
Azzera filtri

What is the difference between using set/invoke and dot notation?

2 visualizzazioni (ultimi 30 giorni)
I've had to work with an Excel automation server a few times and I'm confused about the difference between using set or invoke and using dot notation.
for example the following two lines appear to function identically:
Workbook = Excel.Workbooks.Open(fileName);
Workbook = invoke(Excel.Workbooks, 'open', fileName);
Same with these two lines as well:
Sheets.Item('TestSheet').Rows(1).font.bold = 1;
set(Sheets.Item('TestSheet').Rows(1).font,'bold', 1)
What is difference. Why would I use one method over the other?

Risposte (1)

Daniel Shub
Daniel Shub il 2 Ott 2012
The processing is slightly different with the two methods, but in general, they tend to produce the same result.
Workbook = invoke(Excel.Workbooks, 'open', fileName);
Determines the class of Excel.Workbooks and then calls the invoke method of that class and passes it Excel.Workbooks, 'open', and fileName.
Workbook = Excel.Workbooks.Open(fileName);
Determines the class of Excel.Workbooks and then calls the subsref method of that class and passes it all sort of information. The subsref method then usually will call invoke(Excel.Workbooks, 'open', fileName).
If the class is using the built-in subsref function, the two behave nearly identically. The overhead of the built-in subsref is small. If the class has an overloaded subsref, you can get all sorts of odd behavior. Further, in my experience, the overhead of an overloaded subsref method is quite large.
  2 Commenti
Image Analyst
Image Analyst il 2 Ott 2012
I'd been wondering that myself. So it kind of sounds like the direct way of calling is simpler and preferable to the invoke way. If there's any advantage to using invoke(), please let us know.
Daniel Shub
Daniel Shub il 2 Ott 2012
I probably should have added in the answer that I am not sure if activeX objects behave like other MATLAB objects. For standard OOP I think the direct call is better (e.g., invoke). If there is an overloaded SUBSREF method the direct call will skip the call to |subsref which can/might save time. That said, if my class needs an overloaded SUBSREF, I tend to try and run away.

Accedi per commentare.

Categorie

Scopri di più su Timetables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by