Archive for April, 2006

April 30th 2006

Contracts

Well, with only 2.5 months left until I get married, I’m looking for some small contract jobs to help fund my honeymoon/misc. wedding expenses (travel, hotel, …). I saw Ian had a post looking for a contract, so I’m stealing his idea. However, I hopefully won’t be infringing his business — he’s looking for something a bit bigger. I’m looking for those 1 or 2 day jobs — a custom plugin or class for your project, or a small project that you just don’t have time for. Or, help optimizing a particularly slow portion of code. Anything that you wish you could do, but either lack the knowledge, experience, or time.

I do have a couple of things lined up, but I should be done with both of them this week. So, if you’re wanting something done, shoot me a line at jon@nilobject.com

Have a great weekend, and I promise to post something informative in the next couple days :)

5 Comments »

April 27th 2006

Fixed: Those strange bugs

Well, that was a fun morning. And I mean that — it’s incredibly fun to solve such a convoluted problem. It started off as a, “I can’t view arrays in the debugger. I need to go fix that.” It turned out to be a pretty recent change to the way parameters are passed on PowerPC. It’s funny how the entire IDE worked great except for being able to view arrays in the debugger. I’m glad this never made it out to the betas list (a good testament to how using REALbasic 2006 every day here at the office is good for you guys too), because I would have had to write a release note that went something like:

[Afx] [PPC] Compiler: No longer yields unpredictable
            results after calling a function that takes
            a byref parameter that is a property on an
            object that is also being passed to the
            function (including "self").

It’s often harder to write a release note that explains the problem the user sees when it actually is a very simple fix under the hood that causes some interesting results. Unfortunately, compiler fixes are often quite like that. :)

Comments Off

April 27th 2006

Those strange bugs

Well, I came in this morning to work on some Cocoa stuff, but found that something else was broken, preventing me from viewing array properties in the debugger. So, I dive in.

After about 10 minutes, I’ve narrowed it down to where it’s failing, but for the life of me, I haven’t figured it out yet. It’s one of those, “Huh?” situations:

If address = mAddress Then
// Do some stuff with the array
End If

So, I figured, “The address coming back must be messed up for some reason. I wonder what it is.” Upon viewing both values, they showed the same number in the debugger: 26402988. Well, since I was narrowing down a problem with the debugger, I better not trust it. Changed the code to:

If address = mAddress Then
// Do some stuff with the array
Else
System.DebugLog Str( address ) + " <> " + Str( mAddress )
End If

Debug it again, and sure enough this was printed to my console:

26402988 <> 26402988

Yep, it’s going to be a fun day figuring this one out… :)

4 Comments »

April 25th 2006

BaA: StringShape

Disclaimer: All items shown in this category may or may not be the way described or pictured in the released version.

This one took me a bit by surprise. The one on the left is 5.5, and the one on the right is the Cocoa version. Notice how much more crisp the rotated text is. I can’t quite explain this one — the old Graphics code is a bit hard to read through. All I can say is that I welcome our new CoreGraphics overlords ;)

7 Comments »

April 24th 2006

BaA: Vector Graphics

Disclaimer: All items shown in this category may or may not be the way described or pictured in the released version.

I added a new category for Cocoa-related posts. There won’t be much information until after the release ships. However, I figure I can get your mouth watering by posting a series before and after posts :)

In the picture, the left pane is REALbasic 5.5. The right pane is an internal build using the Cocoa platform layer. In 5.5 and prior, non-axis aligned elements were drawn using cross-platform code, which would yield a bit more jaggy results, because items like Ovals and Curves had to be split up into segments. CoreGraphics will do that work for us, and so I just let it do that.

5 Comments »

April 10th 2006

Type-Select Listbox

I wrote this class a year ago at home in hopes of adding it to the REALbasic IDE, then forgot about it until this morning. Have you ever wanted a listbox in your program to support Type-selection like in the Finder or Windows Explorer? Well, just use this class. It behaves the way each platform should, and does it in an efficient manner.

Class TypeSelectListbox
Inherits Listbox
// Constants
Private Const TypeSelectTimeout = 30

// Properties
Private Dim mLastTypeTime As Integer
Private Dim mTypeBuffer As String
Private Dim mCachedRows() As String
Private Dim mCachedRowIndices() As Integer
Private Dim mDidEncounterNonRepeatedChar As Boolean
Dim TypeSelectColumn As Integer

// New events
Event KeyDown(key As String) As Boolean

// Event implementations
Function KeyDown(key As String) As Boolean Handles Event
// We want to call through to the next implementation of the KeyDown event, so that they can handle
// the key first. We're sort of the last-resort.
If Not KeyDown(key) Then
If asc(Key) > 31 And asc(key) < 127 And Not (Keyboard.OptionKey Or Keyboard.AltKey Or _
Keyboard.ControlKey Or Keyboard.CommandKey) Then

// It's ascii, we should try to do a typeahead
If mLastTypeTime + TypeSelectTimeout > Ticks Then
mTypeBuffer = mTypeBuffer + key
mLastTypeTime = Ticks
Else
mTypeBuffer = key
mLastTypeTime = Ticks
Redim mCachedRows(-1)
Redim mCachedRowIndices(-1)
mDidEncounterNonRepeatedChar = False
End If
Dim slen As Integer = Len( mTypeBuffer )

#If TargetWin32 Or TargetLinux
// On Windows and Linux, we must check to see if the first row has the same letter as the
// key. If so, we will cycle to the next row with the same key combination. Else
// we will find the first row that contains the typeahead.
Dim found As Boolean
If me.ListIndex >= 0 And Left( me.Cell( me.ListIndex, TypeSelectColumn ), 1 ) = Key And Not mDidEncounterNonRepeatedChar Then
// Start at the current selection, and move forward. If we can't find another one starting with this
// key, go back to the start, and try again.
For i As Integer = me.ListIndex + 1 To me.ListCount - 1
If Left( me.Cell( i, TypeSelectColumn ), 1 ) = key Then
me.ListIndex = i
found = True
Exit
End If
Next
If Not found Then
For i As Integer = 0 To me.ListIndex
If Left( me.Cell( i, TypeSelectColumn ), 1 ) = key Then
me.ListIndex = i
found = True
Exit
End If
Next
End If
Return True
Else
mDidEncounterNonRepeatedChar = True
// Loop over the rows finding the first instance of mTypeBuffer
For i As Integer = 0 To me.ListCount - 1
If Left( me.Cell( i, TypeSelectColumn ), slen ) = mTypeBuffer Then
me.ListIndex = i
found = True
Exit
End If
Next
End If
If Not found Then beep
Return True
#Else
// On the Mac, the behavior is different. We will always need a complete list of items in
// the listbox. We will always find the first instance of an item that has this prefix.
// First, check to see if we have the correct number of rows still.
If ubound(mCachedRows) <> me.ListCount - 1 Then
// Fill up the array
For i As Integer = 0 To me.ListCount - 1
// Do an insertion sort. I switched to a binary lookup mechanism because
// doing an insertion sort on this list because when we had more than 1,000 rows
// the delay was obvious. However, with this code, it's not even noticable when
// using 18,000 rows.
Dim cell As String = me.Cell(i, TypeSelectColumn)
Dim didInsert As Boolean
Dim l,h As Integer
Dim j As Integer
l = 0
h = ubound(mCachedRows)
j = h \ 2
While l <= h
If cell < mCachedRows(j) Then
// It's less than this one, we can set the ceiling
h = j - 1
ElseIf cell > mCachedRows(j) Then
// It's bigger than this one, we can set this as the floor
l = j + 1
Else
// Equal! Yippe!
Exit
End If
j = (h - l) \ 2 + l
Wend

mCachedRows.Insert j, cell
mCachedRowIndices.Insert j,i
Next
End If

// Now, do a binary search for something that starts with mTypeBuffer.
For i As Integer = 0 To ubound(mCachedRows)
If Left( mCachedRows(i), slen ) = mTypeBuffer Then
// This is it.
me.ListIndex = mCachedRowIndices(i)
Exit
ElseIf Left( mCachedRows(i), slen ) > mTypeBuffer Then
// This is the next one... if we couldn't find an exact one before this,
// then we need to select this one
me.ListIndex = mCachedRowIndices(i)
Exit
End If
Next
#EndIf

Return True
End If
End If

// If we didn't handle it, we need to reset these variables.
mDidEncounterNonRepeatedChar = False
mTypeBuffer = key
mLastTypeTime = Ticks
Redim mCachedRows(-1)
Redim mCachedRowIndices(-1)
End Function
End Class


Download this project

Enjoy!

6 Comments »

April 10th 2006

Finding a project item in 2006

One interesting feature users may not know about REALbasic 2005/2006 is that when you open an item for the first time, it will be selected in the project list for you.

I’ve been doing this without noticing, but when I want to select an item that is buried deep in folders, I simply type in the location field the project item’s name, then press return. I then switch back to the project list and change its super/interfaces there.

It’s a bit hidden, but can save a few minutes of locating an item, or having to sort through search results.

2 Comments »

April 9th 2006

Where’s the updates?

As many of you probably have noticed, there hasn’t been an update here in quite a while. Why? Well, I’ve been going through a lot recently.

I closed on my new house on March 27, and moved in that afternoon. Cocoa has been loving it, and it has a huge backyard that he and I have been playing in. It doesn’t have grass yet, but I worked a bit on preparing the soil yesterday, and will hopefully seed it maybe even as soon as this evening. The house is a big improvement on my apartment, and I am appreciating how much bigger it feels — it is 50% bigger in terms of square footage, but it also adds a third bedroom, so I wasn’t anticipating me feeling that it was too much bigger. I was wrong, it feels huge :)

On top of that, my uncle and I started a business selling software to elementary principals and last weekend was the National Association of Elementary School Principals in San Antonio, which I drove to and from Friday, Saturday, Sunday, and Monday. It was a worthwhile endeavor, and we’ve gotten some great feedback I’m working on incorporating in the short-term.

And of course, I’ve been busy working on REALbasic 2006 release 2, which if you count the 90 days you’ll realize must be coming soon.

So, with all of this, I’ve been increasingly busy. This weekend has been pretty relaxing though — aside from touching up my first article for RBLibrary, I’ve played some video games, watched a few movies, and caught up on some sleep I missed the last couple weeks.

The game I’ve played the most is Lego Star Wars — I highly recommend this game. It’s not a hard game, but it sure is fun.

Anyways, I’m testing out posting from MarsEdit also. I despise writing a post from within Camino, and figure that doing this might increase the frequency of posting. I don’t know how many times I’ve closed the browser window on accident and lost the post I was writing. At least here, it’ll ask me if I want to save first :)

Everyone have a great week.

1 Comment »