A Bit of RB Trivia: The Answer

April 4th, 2008 by Joe Ranieri

So, the question I asked last time was this:
Name a situation when the global App object is nil (while executing user code).

The two answers that were submitted and correct are:

  • Charles Yeomans pointed out that properties in modules are destructed after the global App object has been set to nil. Example project.
  • Ben Johnson went the other way around and noticed that the global App object is nil in your Application subclass’ constructor. Example project.

However, neither of these were the answer I was looking for. What happens is that REALbasic does a bit of initialization before setting the global App object. Part of that initialization is setting up the menubar, which entails creating the MenuItems. If you have a subclass of MenuItem in that menubar, REALbasic invokes your constructor, and at that point, the global App object is nil. Example project.

Congratulations to Charles and Ben, both of which will be receiving a free license to CalendarKit.


A Bit of RB Trivia

March 31st, 2008 by Joe Ranieri

There’s a free license to CalendarKit 2 to the first person who can answer this question:

Name a situation when the global App object is nil (while executing user code).

* Offer not applicable to Norman Palardy or past or present REAL Software employees.

Update: We have posted the answers.


Demangling C++ Names

March 26th, 2008 by Joe Ranieri

RuntimeException.stack is one of the most useful things to be added to REALbasic. However, we can make it a bit better by demangling any C++ function names that might be in the stack trace.

Function CPPDemangle(name as string) As string
  //! Demangles a C++ function name. Returns an empty string on failure.
  //! Only works on Mac OS X.
 
  #if targetMacOS
      declare function __cxa_demangle lib "/usr/lib/libstdc++.6.dylib" ( name as CString, _
      outBuffer as ptr, outLength as ptr, byref outState as integer ) as CString
    declare sub free lib "System" ( value as CString )
    const kStateSuccess = 0
 
    dim state as integer
    dim demangledString as CString = __cxa_demangle( name, nil, nil, state )
 
    if state = kStateSuccess then
      // create our RB string, then free the string demangle gave us
      dim result as string = demangledString
      free( demangledString )
 
      return result
    end if
  #endif
End Function

Then you can apply this function to the exception’s stack like so:

Function GetErrorStack(err as RuntimeException) As string()
  //! Gets the stack trace for our exception. This differs from
 //! RuntimeException.stack in that it demangles C++ names.
 
  // this can crash in some cases, giving us a completely useless crash log
  // <rb-feedback://keeqghwg>, hopefully this will be fixed someday...
  dim stack() as string = err.stack
  dim cleanedStack() as string
 
  // the order of RB's "for each" isn't defined <rb-feedback://hdcdbgfi>, so we have
  // to use a normal loop
  for i as integer = 0 to stack.ubound
    dim name as string = stack( i )
    dim demangledName as string = cppDemangle( name )
 
    if demangledName <> "" then
      cleanedStack.append( demangledName )
    else
      cleanedStack.append( name )
    end if
  next
 
  return cleanedStack
End Function

So, instead of seeing “__ZN14RuntimeListbox7GetTextE15getTextSelectorll” in an exception trace, you will see “RuntimeListbox::GetText(getTextSelector, long, long)“. Much, much easier on the eyes. :)


Another CKFrameworks Teaser

March 9th, 2008 by Joe Ranieri

I spent a bit of time this weekend working on CKFrameworks, so I figured I’d give another teaser. This time I’ll show off the CFType support…

// load our bundle
dim myFile as FolderItem = desktopFolder.child( "test.ape" )
dim bundle as CFTypeRef = CKFrameworks.CFBundleCreate( myFile )
 
// do some random stuff with it
bundle.loadExecutable()
msgbox( bundle.identifier )

Or perhaps you want to get time zone information:

dim timezone as CFTypeRef = CKFrameworks.CFTimeZoneCreateWithName( "EST", true )
msgbox( timezone.name )

As you can see, this is all pure magic. I’m hoping to have an alpha to show at REAL World, so be there or miss out.


REAL World 2008 Agenda Calendar

March 8th, 2008 by Jonathan Johnson

In addition to Norman’s REAL World 2008 Track Calendar, I’ve created an iCal file for the conference agenda itself, excluding the session blocks. Combining his calendars with mine, you can now have the entire REAL World 2008 schedule in iCal. More importantly, it allows me to have everything on my iPhone :)

Subscribe

Download

Also, anyone who’s interested in meeting up with me and discussing any of our products, seek me out on Tuesday night, Wednesday, or Thursday. I’m also giving a talk on Team Development at 1:00 on Wednesday, so be sure to come if that sort of thing interests you.


An RB feature you didn’t know about

February 5th, 2008 by Joe Ranieri

Some of you might know that REALbasic will highlight URLs in comments and allow you to click them. But, how many of you knew that has a special “rb-feedback” url type to make linking to feedback reports even easier?

// working around rb-feedback://miokjjuu

Neat eh?


Window.FloaterProcess Fix for Mac OS X

February 1st, 2008 by Jonathan Johnson

Recently on the NUG, a question came up about making Window.FloaterProcess work correctly on Mac OS X. This property is designed to make it easy to have one of your global floating windows show up only “inside” of another application. After a lack of volunteers, I coded up a generic drop-in fix.

Module FloaterProcessFix
  Private Const kEventAppFrontSwitched = 7
  Private Const kEventClassApplication = 'appl'
 
  Protected Sub CheckOpenWindows()
    declare function GetFrontProcess lib "Carbon" (psn as Ptr) as Integer
    dim psn as new MemoryBlock(8)
    dim err as Integer = GetFrontProcess(psn)
    if err = 0 then
      declare function GetProcessInformation lib "Carbon" (psn as Ptr, _
        info as Ptr) as Integer
      dim info as new MemoryBlock(60)
      err = GetProcessInformation(psn, info)
      if err = 0 then
        dim p as Ptr = info
        dim type as String = p.OSType(20)
        HideShowFloaters(type)
      end if
    end if
  End Sub
 
  Protected Sub Install()
    declare function NewEventHandlerUPP lib "Carbon" (handler as Ptr) _
      as Integer
    declare function InstallEventHandler lib "Carbon" (target as Integer, _
      handler as Integer, itemCount as Integer, typeList as Ptr, _
      userData as Integer, outRef as Integer) as Integer
    declare function GetApplicationEventTarget lib "Carbon" () as Integer
 
    dim handler as Integer = _
      NewEventHandlerUPP(addressOf CarbonEventHandler)
    dim eventTypes as new MemoryBlock(8)
    eventTypes.Int32Value(0) = kEventClassApplication
    eventTypes.Int32Value(4) = kEventAppFrontSwitched
    dim err as Integer
    err = InstallEventHandler(GetApplicationEventTarget, _
      handler, 1, eventTypes, 0, 0)
 
    CheckOpenWindows
  End Sub
 
  Private Function CarbonEventHandler(inHandlerCallRef as Integer, _
      inEvent as Integer, inUserData as Integer) As Integer
    CheckOpenWindows
    return 0
  End Function
 
  Private Sub HideShowFloaters(frontAppCode as String)
    for i as integer = 0 to WindowCount - 1
      if strcomp(Window(i).FloaterProcess, frontAppCode, 0) = 0 then
        Window(i).Show
      elseif Window(i).FloaterProcess <> "" then
        Window(i).Hide
      end if
    next
  End Sub
End Module

How does the code work? There is a Carbon event that fires each time a new application is activated. By installing this handler, we can then find out what the creator code of the frontmost app is, loop over our windows, and hide/show them appropriately. Because Carbon events are fired only when the event happens, the CPU usage is nearly 0, and you can once again use FloaterProcess on OS X.

You can download a full example here.


TextKit a2 Available

January 29th, 2008 by Jonathan Johnson

We’ve made alpha 2 of TextKit available which includes several features and fixes that you’ve requested.

We’re excited to see how much interest there is in this product. Please let us know if there’s anything you would love to see this field do by either commenting here or filing a new ticket.

Visit the product page to download and learn more about TextKit.

Thanks everyone!


TextKit Released as Public Beta

January 24th, 2008 by Jonathan Johnson

If you remember back to our teasers, we previewed a new product code-named ESTO. We’ve since named the product TextKit, and we’re pleased to announce that we are previewing it in a public beta.

TextKit is a REALbasic plugin that provides a rendering engine for styled text as well as a corresponding EditField-like control that works on Mac OS X, Windows, and Linux. Unlike most other engines, this engine is written specifically for REALbasic and is extremely extendable.

TextKit provides two classes to help with displaying and editing text: TKTextRenderer and TKTextField. Unlike REALbasic’s built-in classes, TKTextRenderer can be used to manipulate and draw text offscreen. TKTextField provides an easy way to edit and display text and objects on a window.

During this public beta, we are extending our customers a special offer: If you buy TextKit today, we’ll extend your license by twelve months from the day that we release TextKit 1.0. It’s our way of showing our gratitude for helping us improve the product.

More information about TextKit can be found at http://alacatialabs.com/products/textkit/. We look forward to hearing everyone’s feedback.


Holiday Teaser 3: Revenge of the Teaser

December 20th, 2007 by Joe Ranieri

In one alpha of REALbasic 2006r1, a feature made a brief appearance but was pulled from the next build — and hasn’t been seen since. We might have something to bridge the gap…

Edit:

You were all right — we are working on a Cocoa bridge and framework!