Buoy questions

Timezone is getting an offset. I need to make an initiator that takes seconds.

Is there any good way to cast Int8 (or any kind of int) to Integer.

So DateTime.New puts up error if I feed the smaller Ints to it.

Only way I have found to cast them is to Integer them first assign them to bigger integer

var m as Int8 = 10
var i as Integer = m

But other ways CType or Integer(m) will not work. So if feeding a function like DateTime new then I would need to create temporary variables to cast them.

Thanks

Björn

For now assignment is the right way

CType and the other casting forms don’t do what you thin they will at this time

CType is more like dynamic reinterpret cast in C++

Problem is the following is compile error:


Sub MyMethod(p as Integer)
     
End Sub

Sub Main()
   var x as Int8 = 12

   MyMethod(x)
End Sub

And the only way to solve it is:

Sub MyMethod(p as Integer)

End Sub

Sub Main()
var x as Int8 = 12
var tmp as Integer = x

MyMethod(tmp)
End Sub

yes
I did say ASSIGN it
not just pass it to a method with a different declared type

Report this in issues and I’m sure it will get addressed

sub doit(x as integer)
    print x
end sub

sub main()
    dim x as int8 = 5
    doit(x)
end sub

I just did this here and it compiles and runs fine. check v0.27.1

27.1 still gives me this:

/Users/Shared/Git/Buoy/Word/Test/Component.bui:1288:0: error: datetime.new argument 1 must be Integer, got Int16
/Users/Shared/Git/Buoy/Word/Test/Component.bui:1288:0: error: datetime.new argument 2 must be Integer, got Int8
/Users/Shared/Git/Buoy/Word/Test/Component.bui:1288:0: error: datetime.new argument 3 must be Integer, got Int8
/Users/Shared/Git/Buoy/Word/Test/Component.bui:1288:0: error: datetime.new argument 4 must be Integer, got Int8
/Users/Shared/Git/Buoy/Word/Test/Component.bui:1288:0: error: datetime.new argument 5 must be Integer, got Int8
/Users/Shared/Git/Buoy/Word/Test/Component.bui:1288:0: error: datetime.new argument 6 must be Integer, got Int8

Can you put that in over at

I’d like to see how the new triage agent handles that.

I did not quite get it if there is difference when passing strings down into Declare if using String or CString.

The difference is clear if using it in return value.

Since I not been sure then I kept the down functions as String but really only on the principle “because it seems to work”. But its maybe better to ask and be sure.

So this is basically how I have it now, CString when getting value, String when sending down.

Declare Function WordStylePart_GetFontName Lib "Word" Alias "WordStylePart_GetFontName" (instance as Ptr) as CString

Declare Sub WordStylePart_SetFontName Lib "Word" Alias "WordStylePart_SetFontName" (instance as Ptr, value as String)

Thanks

Björn

If your C code expects a null terminated string, you should be using CString.

I been battling this here all night:

I have not made bug report yet. The file is very large and I may have done just as little as typo earlier tonight. Its first time where the compiler gives me no clues for where the issue may be.

codegen: unknown type in llvmType()
codegen: LLVM IR verification failed:
Both operands to FCmp instruction are not of the same type!
%1 = fcmp oeq { i8, ptr } %value, { i8, i64 } zeroinitializer

Edit → Finally found it, and have reported the bug.

Yeah, we can do better

Am I doing something wrong here or am I pushing limits of the Generics ?

Private Function CopyIntoArray of T(arrayPtr as Ptr) as Array Of T
    Declare Function WordArrayCount Lib "Word" (instance as Ptr) as Integer
    Declare Function WordArrayElementAt Lib "Word" (instance as Ptr, index as Integer) as Ptr

    var res as Array Of T = []

    if p <> nil Then
        var count = WordArrayCount(p)

        for i = 0 to count - 1
            var item = WordArrayElementAt(p, i)

            if item <> nil then
                res.Append(new T(item))
            end if
        next

        Word_UnRefObject(p)
    end if

    return res
End function

Called by:

var x as Array Of ParagraphStyle = CopyIntoArray of ParagraphStyle(p)

It compiles with having just the generic function. But as soon as I attempt to call it I get this here:

/Users/Shared/Git/Buoy Components/Word/Test/Component.bui:1821:0: error: undefined function 'CopyIntoArray$ParagraphStyle'
/Users/Shared/Git/Buoy Components/Word/Test/Component.bui:1821:0: error: cannot assign Unknown to Array variable 'x'

Its my first attempt to test the generics so I of course might be doing something wrong and or pushing the limits of what should be possible.

Actually I am surprised the Generic compiles as p there should be arrayPtr else p is undefined hmmmmmmmmm

But fixing that changed nothing.

I actually can put any nonsense into the Generic method and it will still compile. Like full line of xxxxxxxxxxx.

Ok so hmmm

The method is just completely ignored if putting it on class…

I got it to be “seen” by making it a global function (where I then had to take the declares out of it also).

Declare Function WordArrayCount Lib "Word" (instance as Ptr) as Integer
Declare Function WordArrayElementAt Lib "Word" (instance as Ptr, index as Integer) as Ptr

Private Function CopyIntoArray of T(arrayPtr as Ptr) as Array Of T

    var res as Array Of T = []

    if arrayPtr <> nil Then
        var count = WordArrayCount(arrayPtr)

        for i = 0 to count - 1
            var item = WordArrayElementAt(arrayPtr, i)

            if item <> nil then
                //res.Append(new T(item))
            end if
        next

        Word_UnRefObject(arrayPtr)
    end if

    return res
End function

This made it callable.

The out commented line there I was probably pushing the limits, that part is not possible

res.Append(new T(item))

One more attempt here, where the idea was to see if factory pattern would work by using delegate.

But there are 2 bugs or at least got ya’s in that.

  1. Address Of does not work on class Shared function. It has to be global function. (Sort of a bug maybe on this one ?)
  2. You cannot cast to T in the generic. (which makes factory solution not work of course).
Declare Function WordArrayCount Lib "Word" (instance as Ptr) as Integer
Declare Function WordArrayElementAt Lib "Word" (instance as Ptr, index as Integer) as Ptr

Delegate Function ObjectFactoryDelegate(p as Ptr) as Object

// This would have made sense maybe as shared method on 
// ParagraphStyle class but AddressOf will not work
// on class shared method.
Function CreateParagraphStyle(p as Ptr) as Object
     return new ParagraphStyle(p)
End Function

Private Function CopyIntoArray of T(arrayPtr as Ptr, factory as ObjectFactoryDelegate) as Array Of T

    var res as Array Of T = []

    if arrayPtr <> nil Then
        var count = WordArrayCount(arrayPtr)

        for i = 0 to count - 1
            var item = WordArrayElementAt(arrayPtr, i)

            if item <> nil then
                res.Append(CType(factory(item), T)) // This line will not work since casting not possible.
            end if
        next

        Word_UnRefObject(arrayPtr)
    end if

    return res
End function

At present, the numeric TextField acts no differently than a textual TextField. It even allows non-numeric text to be entered into it. Perhaps it should be a subclass of TextField, with a Value field for the number to be treated directly as a Double, as well as a Validate event.

Please file a bug report on the releases GitHub site.

Is it only possible to handle button events by Sub Classing every single button ?

I hope there is supposed to be better way to hook events to them as subclassing every control just to wire up events is a bit counter intuitive.

it’s coming. I’m working on being able to write the handles right into the instances inside the window, just like “the other guys”.

FWIW, Buoy does synthesize methods to use with Handle, like:

Handle button_01_pressed()

End Handle

The problem is that they were a stopgap when the language was very new and they’re going to disappear before we reach 1.0. What we’re aiming for is like this:

Window myWindow

  Button myButton

    Handle Pressed()
      // code goes here
    End Handle

  End Button

  Label myLabel

  End Label
End Window