Bug 121197 - Macro: run from Basic editor but error after running from document
Summary: Macro: run from Basic editor but error after running from document
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: x86-64 (AMD64) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-06 10:56 UTC by Kamil Landa
Modified: 2018-11-06 14:13 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
error thisComponent as optional input parameter (15.09 KB, application/vnd.oasis.opendocument.text)
2018-11-06 10:56 UTC, Kamil Landa
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kamil Landa 2018-11-06 10:56:03 UTC
Created attachment 146349 [details]
error thisComponent as optional input parameter

If oDoc (thisComponent) is optional input parameter for the function, then macro runs good only from Basic Editor and not from Writer.
Example is in the attachment.
Comment 1 Oliver Brinzing 2018-11-06 12:14:50 UTC
if you connect a form control with a basic method, 
you will receive an ActionEvent as parameter.

to make it work, change your macro, e.g.:

Sub macroBAD(oEvt)
 oModel = oEvt.Source.Model
 oDoc = oModel.getParent.getParent.getParent
 msgbox oModel.Name
 msgbox oDoc.drawpage.getforms().getbyname("Form").getByName("buttonBAD").name
End Sub
Comment 2 Kamil Landa 2018-11-06 14:13:09 UTC
Now I also discover it isn't bug :-). Now I'm testing in macro if oDoc IS thisComponent


Sub macroBAD(optional oDoc as object) 'after click on button the atribute oDoc is com.sun.star.awt.ActionEvent
	if IsMissing(oDoc) OR (NOT (oDoc IS thisComponent)) then oDoc=thisComponent 'correct
	msgbox oDoc.drawpage.getforms().getbyname("Form").getByName("buttonBAD").name 'error after run from document
End Sub