Ask Your Question
0

Is there are value for a null object in LoBasic?

asked 2018-03-01 17:24:33 +0200

ptoye gravatar image

I want to write a function which returns either an object if it can, or a null object if it can't. The AOO wiki seems to be silent on the subject - the language definition waxes lyrical about how object-oriented it is, but does not even mention objects. Other pages tell me how to create objects, but nothing about the null object.

Can this be done? It should be simple, and is in properly OO languages which have the concept built-in.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2018-03-01 22:38:54 +0200

Ratslinger gravatar image

Hello @ptoye,

Here is a simple example:

Sub MyRoutine
    oRectangle = TryCreateObject(3)
    if  ISNULL(oRectangle) then
        msgbox "Null"
    else
        msgbox "Not Null"
    end if
End Sub

Function TryCreateObject(number)
    Dim oRectangle as Object
    If number > 6 then
        oRectangle = createObject("com.sun.star.awt.Rectangle")
    EndIf
    TryCreateObject = oRectangle
End Function
edit flag offensive delete link more

Comments

Thanks I've not tried this yet, but it looks as if it should work. Presumably the Dim statement creates a null object. Shame about the lack of documentation.

I was trying something like

Function TryCreateObject(number)
   If number > 6 then
    TryCreateObject= createObject("com.sun.star.awt.Rectangle")
  Else
    TryCreateObject = What do I put here???
  EndIf   
End Function
ptoye gravatar imageptoye ( 2018-03-02 10:36:02 +0200 )edit

"What do I put here???"

Nothing :)

Seriously, TryCreateObject = Nothing

librebel gravatar imagelibrebel ( 2018-03-15 17:14:59 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-03-01 17:24:33 +0200

Seen: 47 times

Last updated: Mar 01 '18