summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2010-05-21 11:42:22 +0200
committerIvo Hinkelmann <ihi@openoffice.org>2010-05-21 11:42:22 +0200
commit32dc9f4dd82254d4c350fcfcb0b6bb37f5947d1f (patch)
tree8fe3725cd281ca5f59498d98122f6ece9f293523
parent5cd38c30cf4c138d9173d4e59edb01461b655c6e (diff)
parenteb98cdb38c2779efc5384fa7ba1bf3cb29be2c4c (diff)
CWS-TOOLING: integrate CWS ab75
-rw-r--r--basic/inc/basic/sberrors.hxx3
-rwxr-xr-x[-rw-r--r--]basic/prj/build.lst2
-rw-r--r--basic/source/classes/errobject.cxx225
-rw-r--r--basic/source/classes/makefile.mk18
-rwxr-xr-xbasic/source/classes/sb.cxx20
-rw-r--r--basic/source/classes/sb.src4
-rw-r--r--basic/source/inc/errobject.hxx52
-rw-r--r--basic/source/inc/runtime.hxx5
-rw-r--r--basic/source/runtime/methods.cxx28
-rw-r--r--basic/source/runtime/props.cxx18
-rwxr-xr-x[-rw-r--r--]basic/source/runtime/runtime.cxx74
-rw-r--r--basic/source/runtime/stdobj.cxx2
-rw-r--r--basic/source/runtime/step0.cxx11
-rw-r--r--basic/source/runtime/step1.cxx4
-rw-r--r--basic/source/uno/scriptcont.cxx2
15 files changed, 449 insertions, 19 deletions
diff --git a/basic/inc/basic/sberrors.hxx b/basic/inc/basic/sberrors.hxx
index 250eac5b5c..92866fd81a 100644
--- a/basic/inc/basic/sberrors.hxx
+++ b/basic/inc/basic/sberrors.hxx
@@ -287,6 +287,8 @@ typedef ULONG SbError;
#define ERRCODE_BASIC_LOOP_NOT_INIT ((LAST_SBX_ERROR_ID+109UL) | ERRCODE_AREA_SBX | \
ERRCODE_CLASS_COMPILER) // For loop not initialized
+#define ERRCODE_BASIC_COMPAT ((LAST_SBX_ERROR_ID+103UL)| ERRCODE_AREA_SBX | ERRCODE_CLASS_RUNTIME)
+
// Map old codes to new codes
#define SbERR_SYNTAX ERRCODE_BASIC_SYNTAX
#define SbERR_NO_GOSUB ERRCODE_BASIC_NO_GOSUB
@@ -410,6 +412,7 @@ typedef ULONG SbError;
#define SbERR_PROG_TOO_LARGE ERRCODE_BASIC_PROG_TOO_LARGE
#define SbERR_NO_STRINGS_ARRAYS ERRCODE_BASIC_NO_STRINGS_ARRAYS
#define SbERR_BASIC_EXCEPTION ERRCODE_BASIC_EXCEPTION
+#define SbERR_BASIC_COMPAT ERRCODE_BASIC_COMPAT
#define SbERR_BASIC_ARRAY_FIX ERRCODE_BASIC_ARRAY_FIX
#define SbERR_BASIC_STRING_OVERFLOW ERRCODE_BASIC_STRING_OVERFLOW
#define SbERR_BASIC_EXPR_TOO_COMPLEX ERRCODE_BASIC_EXPR_TOO_COMPLEX
diff --git a/basic/prj/build.lst b/basic/prj/build.lst
index 994901580c..2cd1d3dc04 100644..100755
--- a/basic/prj/build.lst
+++ b/basic/prj/build.lst
@@ -1,4 +1,4 @@
-sb basic : l10n offuh svtools xmlscript framework NULL
+sb basic : l10n offuh oovbaapi svtools xmlscript framework NULL
sb basic usr1 - all sb_mkout NULL
sb basic\inc nmake - all sb_inc NULL
sb basic\source\app nmake - all sb_app sb_class sb_inc NULL
diff --git a/basic/source/classes/errobject.cxx b/basic/source/classes/errobject.cxx
new file mode 100644
index 0000000000..4f661faeaf
--- /dev/null
+++ b/basic/source/classes/errobject.cxx
@@ -0,0 +1,225 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_basic.hxx"
+#include "errobject.hxx"
+
+#include <cppuhelper/implbase2.hxx>
+#include <com/sun/star/script/XDefaultProperty.hpp>
+#include "sbintern.hxx"
+#include "runtime.hxx"
+
+using namespace ::com::sun::star;
+using namespace ::ooo;
+
+typedef ::cppu::WeakImplHelper2< vba::XErrObject, script::XDefaultProperty > ErrObjectImpl_BASE;
+
+class ErrObject : public ErrObjectImpl_BASE
+{
+ rtl::OUString m_sHelpFile;
+ rtl::OUString m_sSource;
+ rtl::OUString m_sDescription;
+ sal_Int32 m_nNumber;
+ sal_Int32 m_nHelpContext;
+
+public:
+ ErrObject();
+ ~ErrObject();
+ // Attributes
+ virtual ::sal_Int32 SAL_CALL getNumber() throw (uno::RuntimeException);
+ virtual void SAL_CALL setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException);
+ virtual ::sal_Int32 SAL_CALL getHelpContext() throw (uno::RuntimeException);
+ virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getHelpFile() throw (uno::RuntimeException);
+ virtual void SAL_CALL setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getDescription() throw (uno::RuntimeException);
+ virtual void SAL_CALL setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException);
+ virtual ::rtl::OUString SAL_CALL getSource() throw (uno::RuntimeException);
+ virtual void SAL_CALL setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException);
+
+ // Methods
+ virtual void SAL_CALL Clear( ) throw (uno::RuntimeException);
+ virtual void SAL_CALL Raise( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException);
+ // XDefaultProperty
+ virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (uno::RuntimeException);
+
+ // Helper method
+ void setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description,
+ const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException);
+};
+
+
+ErrObject::~ErrObject()
+{
+}
+
+ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0)
+{
+}
+
+sal_Int32 SAL_CALL
+ErrObject::getNumber() throw (uno::RuntimeException)
+{
+ return m_nNumber;
+}
+
+void SAL_CALL
+ErrObject::setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException)
+{
+ pINST->setErrorVB( _number, String() );
+ ::rtl::OUString _description = pINST->GetErrorMsg();
+ setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() );
+}
+
+::sal_Int32 SAL_CALL
+ErrObject::getHelpContext() throw (uno::RuntimeException)
+{
+ return m_nHelpContext;
+}
+void SAL_CALL
+ErrObject::setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException)
+{
+ m_nHelpContext = _helpcontext;
+}
+
+::rtl::OUString SAL_CALL
+ErrObject::getHelpFile() throw (uno::RuntimeException)
+{
+ return m_sHelpFile;
+}
+
+void SAL_CALL
+ErrObject::setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException)
+{
+ m_sHelpFile = _helpfile;
+}
+
+::rtl::OUString SAL_CALL
+ErrObject::getDescription() throw (uno::RuntimeException)
+{
+ return m_sDescription;
+}
+
+void SAL_CALL
+ErrObject::setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException)
+{
+ m_sDescription = _description;
+}
+
+::rtl::OUString SAL_CALL
+ErrObject::getSource() throw (uno::RuntimeException)
+{
+ return m_sSource;
+}
+
+void SAL_CALL
+ErrObject::setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException)
+{
+ m_sSource = _source;
+}
+
+// Methods
+void SAL_CALL
+ErrObject::Clear( ) throw (uno::RuntimeException)
+{
+ m_sHelpFile = rtl::OUString();
+ m_sSource = m_sHelpFile;
+ m_sDescription = m_sSource;
+ m_nNumber = 0;
+ m_nHelpContext = 0;
+}
+
+void SAL_CALL
+ErrObject::Raise( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException)
+{
+ setData( Number, Source, Description, HelpFile, HelpContext );
+ if ( m_nNumber )
+ pINST->ErrorVB( m_nNumber, m_sDescription );
+}
+
+// XDefaultProperty
+::rtl::OUString SAL_CALL
+ErrObject::getDefaultPropertyName( ) throw (uno::RuntimeException)
+{
+ static rtl::OUString sDfltPropName( RTL_CONSTASCII_USTRINGPARAM("Number") );
+ return sDfltPropName;
+}
+
+void ErrObject::setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext )
+ throw (uno::RuntimeException)
+{
+ if ( !Number.hasValue() )
+ throw uno::RuntimeException( rtl::OUString::createFromAscii("Missing Required Paramater"), uno::Reference< uno::XInterface >() );
+ Number >>= m_nNumber;
+ Description >>= m_sDescription;
+ Source >>= m_sSource;
+ HelpFile >>= m_sHelpFile;
+ HelpContext >>= m_nHelpContext;
+}
+
+// SbxErrObject
+SbxErrObject::SbxErrObject( const String& rName, const Any& rUnoObj )
+ : SbUnoObject( rName, rUnoObj )
+ , m_pErrObject( NULL )
+{
+ OSL_TRACE("SbxErrObject::SbxErrObject ctor");
+ rUnoObj >>= m_xErr;
+ if ( m_xErr.is() )
+ {
+ SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ;
+ m_pErrObject = static_cast< ErrObject* >( m_xErr.get() );
+ }
+}
+
+SbxErrObject::~SbxErrObject()
+{
+ OSL_TRACE("SbxErrObject::~SbxErrObject dtor");
+}
+
+uno::Reference< vba::XErrObject >
+SbxErrObject::getUnoErrObject()
+{
+ SbxVariable* pVar = getErrObject();
+ SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( pVar );
+ return pGlobErr->m_xErr;
+}
+
+SbxVariableRef
+SbxErrObject::getErrObject()
+{
+ static SbxVariableRef pGlobErr = new SbxErrObject( String( RTL_CONSTASCII_USTRINGPARAM("Err")), uno::makeAny( uno::Reference< vba::XErrObject >( new ErrObject() ) ) );
+ return pGlobErr;
+}
+
+void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number, const ::rtl::OUString& _description )
+ throw (uno::RuntimeException)
+{
+ if( m_pErrObject != NULL )
+ m_pErrObject->setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() );
+}
+
diff --git a/basic/source/classes/makefile.mk b/basic/source/classes/makefile.mk
index eb5486f02a..e00ed4674c 100644
--- a/basic/source/classes/makefile.mk
+++ b/basic/source/classes/makefile.mk
@@ -37,18 +37,28 @@ ENABLE_EXCEPTIONS=TRUE
.INCLUDE : settings.mk
+ALLTAR .SEQUENTIAL : \
+ $(MISC)$/$(TARGET).don \
+ $(MISC)$/$(TARGET).slo
+
+$(MISC)$/$(TARGET).don : $(SOLARBINDIR)$/oovbaapi.rdb
+ +$(CPPUMAKER) -O$(OUT)$/inc -BUCR $(SOLARBINDIR)$/oovbaapi.rdb -X$(SOLARBINDIR)$/types.rdb && echo > $@
+ echo $@
+
+$(MISC)$/$(TARGET).slo : $(SLOTARGET)
+ echo $@
+
# --- Allgemein -----------------------------------------------------------
-COMMON_SLOFILES= \
+SLOFILES= \
$(SLO)$/sb.obj \
$(SLO)$/sbxmod.obj \
$(SLO)$/image.obj \
$(SLO)$/sbintern.obj \
$(SLO)$/sbunoobj.obj \
$(SLO)$/propacc.obj \
- $(SLO)$/disas.obj
-
-SLOFILES= $(COMMON_SLOFILES) \
+ $(SLO)$/disas.obj \
+ $(SLO)$/errobject.obj \
$(SLO)$/eventatt.obj
OBJFILES= \
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index e4b4942d94..e4b0f14ea1 100755
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -55,6 +55,7 @@
#include <basrid.hxx>
#include <vos/mutex.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include "errobject.hxx"
// #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE )
@@ -238,6 +239,7 @@ const SFX_VB_ErrorItem __FAR_DATA SFX_VB_ErrorTab[] =
{ 1004, SbERR_METHOD_FAILED },
{ 1005, SbERR_SETPROP_FAILED },
{ 1006, SbERR_GETPROP_FAILED },
+ { 1007, SbERR_BASIC_COMPAT },
{ 0xFFFF, 0xFFFFFFFFL } // End mark
};
@@ -1352,6 +1354,7 @@ void StarBASIC::MakeErrorText( SbError nId, const String& aMsg )
}
else
GetSbData()->aErrMsg = String::EmptyString();
+
}
BOOL StarBASIC::CError
@@ -1408,7 +1411,22 @@ BOOL StarBASIC::RTError( SbError code, const String& rMsg, USHORT l, USHORT c1,
// Umsetzung des Codes fuer String-Transport in SFX-Error
if( rMsg.Len() )
- code = (ULONG)*new StringErrorInfo( code, String(rMsg) );
+ {
+ // very confusing, even though MakeErrorText sets up the error text
+ // seems that this is not used ( if rMsg already has content )
+ // In the case of VBA MakeErrorText also formats the error to be alittle more
+ // like vba ( adds an error number etc )
+ if ( SbiRuntime::isVBAEnabled() && ( code == SbERR_BASIC_COMPAT ) )
+ {
+ String aTmp = '\'';
+ aTmp += String::CreateFromInt32( SbxErrObject::getUnoErrObject()->getNumber() );
+ aTmp += String( RTL_CONSTASCII_USTRINGPARAM("\'\n") );
+ aTmp += GetSbData()->aErrMsg.Len() ? GetSbData()->aErrMsg : rMsg;
+ code = (ULONG)*new StringErrorInfo( code, aTmp );
+ }
+ else
+ code = (ULONG)*new StringErrorInfo( code, String(rMsg) );
+ }
SetErrorData( code, l, c1, c2 );
if( GetSbData()->aErrHdl.IsSet() )
diff --git a/basic/source/classes/sb.src b/basic/source/classes/sb.src
index b80133553b..632148acc0 100644
--- a/basic/source/classes/sb.src
+++ b/basic/source/classes/sb.src
@@ -588,6 +588,10 @@ Resource RID_BASIC_START
{
Text [ en-US ] = "For loop not initialized." ;
};
+ String ERRCODE_BASIC_COMPAT & ERRCODE_RES_MASK
+ {
+ Text [ en-US ] = "$(ARG1)" ;
+ };
};
// Hinweis: IDS_SBERR_TERMINATED = IDS_SBERR_START+2000.
String IDS_SBERR_TERMINATED
diff --git a/basic/source/inc/errobject.hxx b/basic/source/inc/errobject.hxx
new file mode 100644
index 0000000000..39e6e319ca
--- /dev/null
+++ b/basic/source/inc/errobject.hxx
@@ -0,0 +1,52 @@
+/*************************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+************************************************************************/
+
+#ifndef ERROBJECT_HXX
+#define ERROBJECT_HXX
+#include "sbunoobj.hxx"
+#include <ooo/vba/XErrObject.hpp>
+
+
+class SbxErrObject : public SbUnoObject
+{
+ class ErrObject* m_pErrObject;
+ com::sun::star::uno::Reference< ooo::vba::XErrObject > m_xErr;
+
+ SbxErrObject( const String& aName_, const com::sun::star::uno::Any& aUnoObj_ );
+ ~SbxErrObject();
+
+ class ErrObject* getImplErrObject( void )
+ { return m_pErrObject; }
+
+public:
+ static SbxVariableRef getErrObject();
+ static com::sun::star::uno::Reference< ooo::vba::XErrObject > getUnoErrObject();
+
+ void setNumberAndDescription( ::sal_Int32 _number, const ::rtl::OUString& _description )
+ throw (com::sun::star::uno::RuntimeException);
+};
+#endif
diff --git a/basic/source/inc/runtime.hxx b/basic/source/inc/runtime.hxx
index 71997dae2f..c96a66dfa1 100644
--- a/basic/source/inc/runtime.hxx
+++ b/basic/source/inc/runtime.hxx
@@ -219,6 +219,8 @@ public:
void Error( SbError ); // trappable Error
void Error( SbError, const String& rMsg ); // trappable Error mit Message
+ void ErrorVB( sal_Int32 nVBNumber, const String& rMsg );
+ void setErrorVB( sal_Int32 nVBNumber, const String& rMsg );
void FatalError( SbError ); // non-trappable Error
void FatalError( SbError, const String& ); // non-trappable Error
void Abort(); // Abbruch mit aktuellem Fehlercode
@@ -441,10 +443,11 @@ public:
SbiRuntime( SbModule*, SbMethod*, UINT32 );
~SbiRuntime();
- void Error( SbError ); // Fehler setzen, falls != 0
+ void Error( SbError, bool bVBATranslationAlreadyDone = false ); // Fehler setzen, falls != 0
void Error( SbError, const String& ); // Fehler setzen, falls != 0
void FatalError( SbError ); // Fehlerbehandlung=Standard, Fehler setzen
void FatalError( SbError, const String& ); // Fehlerbehandlung=Standard, Fehler setzen
+ static sal_Int32 translateErrorToVba( SbError nError, String& rMsg );
void DumpPCode();
BOOL Step(); // Einzelschritt (ein Opcode)
void Stop() { bRun = FALSE; }
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index c32abbd1c3..1159067b19 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -61,6 +61,7 @@
#else
#include <osl/file.hxx>
#endif
+#include "errobject.hxx"
#ifdef _USE_UNO
#include <comphelper/processfactory.hxx>
@@ -256,6 +257,7 @@ RTLFUNC(Error)
{
String aErrorMsg;
SbError nErr = 0L;
+ INT32 nCode = 0;
if( rPar.Count() == 1 )
{
nErr = StarBASIC::GetErrBasic();
@@ -263,14 +265,34 @@ RTLFUNC(Error)
}
else
{
- INT32 nCode = rPar.Get( 1 )->GetLong();
+ nCode = rPar.Get( 1 )->GetLong();
if( nCode > 65535L )
StarBASIC::Error( SbERR_CONVERSION );
else
nErr = StarBASIC::GetSfxFromVBError( (USHORT)nCode );
}
- pBasic->MakeErrorText( nErr, aErrorMsg );
- rPar.Get( 0 )->PutString( pBasic->GetErrorText() );
+
+ bool bVBA = SbiRuntime::isVBAEnabled();
+ String tmpErrMsg;
+ if( bVBA && aErrorMsg.Len() > 0 )
+ {
+ tmpErrMsg = aErrorMsg;
+ }
+ else
+ {
+ pBasic->MakeErrorText( nErr, aErrorMsg );
+ tmpErrMsg = pBasic->GetErrorText();
+ }
+ // If this rtlfunc 'Error' passed a errcode the same as the active Err Objects's
+ // current err then return the description for the error message if it is set
+ // ( complicated isn't it ? )
+ if ( bVBA && rPar.Count() > 1 )
+ {
+ com::sun::star::uno::Reference< ooo::vba::XErrObject > xErrObj( SbxErrObject::getUnoErrObject() );
+ if ( xErrObj.is() && xErrObj->getNumber() == nCode && xErrObj->getDescription().getLength() )
+ tmpErrMsg = xErrObj->getDescription();
+ }
+ rPar.Get( 0 )->PutString( tmpErrMsg );
}
}
diff --git a/basic/source/runtime/props.cxx b/basic/source/runtime/props.cxx
index fad64d68c0..5a215bb40d 100644
--- a/basic/source/runtime/props.cxx
+++ b/basic/source/runtime/props.cxx
@@ -31,6 +31,7 @@
#include "runtime.hxx"
#include "stdobj.hxx"
#include "rtlproto.hxx"
+#include "errobject.hxx"
// Properties und Methoden legen beim Get (bWrite = FALSE) den Returnwert
@@ -50,14 +51,21 @@ RTLFUNC(Err)
(void)pBasic;
(void)bWrite;
- if( bWrite )
+ if( SbiRuntime::isVBAEnabled() )
{
- INT32 nVal = rPar.Get( 0 )->GetLong();
- if( nVal <= 65535L )
- StarBASIC::Error( StarBASIC::GetSfxFromVBError( (USHORT) nVal ) );
+ rPar.Get( 0 )->PutObject( SbxErrObject::getErrObject() );
}
else
- rPar.Get( 0 )->PutLong( StarBASIC::GetVBErrorCode( StarBASIC::GetErrBasic() ) );
+ {
+ if( bWrite )
+ {
+ INT32 nVal = rPar.Get( 0 )->GetLong();
+ if( nVal <= 65535L )
+ StarBASIC::Error( StarBASIC::GetSfxFromVBError( (USHORT) nVal ) );
+ }
+ else
+ rPar.Get( 0 )->PutLong( StarBASIC::GetVBErrorCode( StarBASIC::GetErrBasic() ) );
+ }
}
RTLFUNC(False)
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index d0751547eb..25b1b7994d 100644..100755
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -43,6 +43,9 @@
#include <comphelper/processfactory.hxx>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include "sbunoobj.hxx"
+#include "errobject.hxx"
+
+using namespace ::com::sun::star;
bool SbiRuntime::isVBAEnabled()
{
@@ -422,6 +425,35 @@ void SbiInstance::Error( SbError n, const String& rMsg )
}
}
+void SbiInstance::ErrorVB( sal_Int32 nVBNumber, const String& rMsg )
+{
+ if( !bWatchMode )
+ {
+ SbError n = StarBASIC::GetSfxFromVBError( static_cast< USHORT >( nVBNumber ) );
+ if ( !n )
+ n = nVBNumber; // force orig number, probably should have a specific table of vb ( localized ) errors
+
+ aErrorMsg = rMsg;
+ SbiRuntime::translateErrorToVba( n, aErrorMsg );
+
+ bool bVBATranslationAlreadyDone = true;
+ pRun->Error( SbERR_BASIC_COMPAT, bVBATranslationAlreadyDone );
+ }
+}
+
+void SbiInstance::setErrorVB( sal_Int32 nVBNumber, const String& rMsg )
+{
+ SbError n = StarBASIC::GetSfxFromVBError( static_cast< USHORT >( nVBNumber ) );
+ if( !n )
+ n = nVBNumber; // force orig number, probably should have a specific table of vb ( localized ) errors
+
+ aErrorMsg = rMsg;
+ SbiRuntime::translateErrorToVba( n, aErrorMsg );
+
+ nErr = n;
+}
+
+
void SbiInstance::FatalError( SbError n )
{
pRun->FatalError( n );
@@ -791,10 +823,24 @@ BOOL SbiRuntime::Step()
return bRun;
}
-void SbiRuntime::Error( SbError n )
+void SbiRuntime::Error( SbError n, bool bVBATranslationAlreadyDone )
{
if( n )
+ {
nError = n;
+ if( isVBAEnabled() && !bVBATranslationAlreadyDone )
+ {
+ String aMsg = pInst->GetErrorMsg();
+ sal_Int32 nVBAErrorNumber = translateErrorToVba( nError, aMsg );
+ SbxVariable* pSbxErrObjVar = SbxErrObject::getErrObject();
+ SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( pSbxErrObjVar );
+ if( pGlobErr != NULL )
+ pGlobErr->setNumberAndDescription( nVBAErrorNumber, aMsg );
+
+ pInst->aErrorMsg = aMsg;
+ nError = SbERR_BASIC_COMPAT;
+ }
+ }
}
void SbiRuntime::Error( SbError _errCode, const String& _details )
@@ -826,6 +872,32 @@ void SbiRuntime::FatalError( SbError _errCode, const String& _details )
Error( _errCode, _details );
}
+sal_Int32 SbiRuntime::translateErrorToVba( SbError nError, String& rMsg )
+{
+ // If a message is defined use that ( in preference to
+ // the defined one for the error ) NB #TODO
+ // if there is an error defined it more than likely
+ // is not the one you want ( some are the same though )
+ // we really need a new vba compatible error list
+ if ( !rMsg.Len() )
+ {
+ // TEST, has to be vb here always
+#ifdef DBG_UTIL
+ SbError nTmp = StarBASIC::GetSfxFromVBError( nError );
+ DBG_ASSERT( nTmp, "No VB error!" );
+#endif
+
+ StarBASIC::MakeErrorText( nError, rMsg );
+ rMsg = StarBASIC::GetErrorText();
+ if ( !rMsg.Len() ) // no message for err no, need localized resource here
+ rMsg = String( RTL_CONSTASCII_USTRINGPARAM("Internal Object Error:") );
+ }
+ // no num? most likely then it *is* really a vba err
+ USHORT nVBErrorCode = StarBASIC::GetVBErrorCode( nError );
+ sal_Int32 nVBAErrorNumber = ( nVBErrorCode == 0 ) ? nError : nVBErrorCode;
+ return nVBAErrorNumber;
+}
+
//////////////////////////////////////////////////////////////////////////
//
// Parameter, Locals, Caller
diff --git a/basic/source/runtime/stdobj.cxx b/basic/source/runtime/stdobj.cxx
index 5d3573de09..c9baf952ed 100644
--- a/basic/source/runtime/stdobj.cxx
+++ b/basic/source/runtime/stdobj.cxx
@@ -230,7 +230,7 @@ static Methods aMethods[] = {
{ "EOF", SbxBOOL, 1 | _FUNCTION, RTLNAME(EOF),0 },
{ "Channel", SbxINTEGER, 0,NULL,0 },
{ "Erl", SbxLONG, _ROPROP, RTLNAME( Erl ),0 },
-{ "Err", SbxLONG, _RWPROP, RTLNAME( Err ),0 },
+{ "Err", SbxVARIANT, _RWPROP, RTLNAME( Err ),0 },
{ "Error", SbxSTRING, 1 | _FUNCTION, RTLNAME( Error ),0 },
{ "code", SbxLONG, 0,NULL,0 },
{ "Exp", SbxDOUBLE, 1 | _FUNCTION, RTLNAME(Exp),0 },
diff --git a/basic/source/runtime/step0.cxx b/basic/source/runtime/step0.cxx
index 83b610eef1..96a3e80a84 100644
--- a/basic/source/runtime/step0.cxx
+++ b/basic/source/runtime/step0.cxx
@@ -30,6 +30,7 @@
#include <vcl/msgbox.hxx>
#include <tools/fsys.hxx>
+#include "errobject.hxx"
#include "runtime.hxx"
#include "sbintern.hxx"
#include "iosys.hxx"
@@ -1116,6 +1117,7 @@ void SbiRuntime::StepSTDERROR()
pInst->nErr = 0L;
pInst->nErl = 0;
nError = 0L;
+ SbxErrObject::getUnoErrObject()->Clear();
}
void SbiRuntime::StepNOERROR()
@@ -1124,6 +1126,7 @@ void SbiRuntime::StepNOERROR()
pInst->nErr = 0L;
pInst->nErl = 0;
nError = 0L;
+ SbxErrObject::getUnoErrObject()->Clear();
bError = FALSE;
}
@@ -1132,6 +1135,9 @@ void SbiRuntime::StepNOERROR()
void SbiRuntime::StepLEAVE()
{
bRun = FALSE;
+ // If VBA and we are leaving an ErrorHandler then clear the error ( it's been processed )
+ if ( bInError && pError )
+ SbxErrObject::getUnoErrObject()->Clear();
}
void SbiRuntime::StepCHANNEL() // TOS = Kanalnummer
@@ -1265,6 +1271,9 @@ void SbiRuntime::StepERROR()
SbxVariableRef refCode = PopVar();
USHORT n = refCode->GetUShort();
SbError error = StarBASIC::GetSfxFromVBError( n );
- Error( error );
+ if ( bVBAEnabled )
+ pInst->Error( error );
+ else
+ Error( error );
}
diff --git a/basic/source/runtime/step1.cxx b/basic/source/runtime/step1.cxx
index 3fe4d4542d..3295c7388e 100644
--- a/basic/source/runtime/step1.cxx
+++ b/basic/source/runtime/step1.cxx
@@ -35,6 +35,7 @@
#include "iosys.hxx"
#include "image.hxx"
#include "sbunoobj.hxx"
+#include "errobject.hxx"
bool checkUnoObjectType( SbUnoObject* refVal,
const String& aClass );
@@ -360,6 +361,7 @@ void SbiRuntime::StepERRHDL( UINT32 nOp1 )
pInst->nErr = 0;
pInst->nErl = 0;
nError = 0;
+ SbxErrObject::getUnoErrObject()->Clear();
}
// Resume nach Fehlern (+0=statement, 1=next or Label)
@@ -380,6 +382,8 @@ void SbiRuntime::StepRESUME( UINT32 nOp1 )
}
else
pCode = pErrStmnt;
+ if ( pError ) // current in error handler ( and got a Resume Next statment )
+ SbxErrObject::getUnoErrObject()->Clear();
if( nOp1 > 1 )
StepJUMP( nOp1 );
diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index 89e9f6cc85..c5f2fa7469 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -942,7 +942,7 @@ sal_Bool SfxScriptLibraryContainer::implLoadPasswordLibrary
try {
xElementRootStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
aElementPath,
- embed::ElementModes::READWRITE );
+ embed::ElementModes::READ );
} catch( uno::Exception& )
{
// TODO: error handling