Posts tagged ‘Dark Corners’

The case of the one-thread race condition

You know what’s even worse than a race condition between two threads in your code?

A race condition in one thread in your code, because there are good solutions and debugging techniques for tracking down multi-threading conflicts, but they don’t work when there’s only one thread involved.

That’s right.  I just spent the last few hours tracking down what turned out to be a reentrancy problem. Continue reading ‘The case of the one-thread race condition’ »

The next RTTI bottleneck

A few years back, when I posted an analysis of how TValue is very slow, it prompted a lot of response from the community.  Various people ran their own benchmarks, and started working on building or optimizing their own meta-value types.  Some people are even still working on that today.  But one of the most interesting things was Robert Love’s response.  He looked at the TValue code and found a way that it could be optimized for the common case to speed things up. Continue reading ‘The next RTTI bottleneck’ »

Adding boolean support to Firebird+DBX

Firebird is a great database, but it’s got one really irritating drawback: no native support for the boolean type.  The standard solution to this issue is to create a BOOLEAN domain as a special restricted version of a smallint, and then make your database driver output the correct type.

The first part is easy.  The second, not so much, if you want to use DBExpress.  This really should be handled internally as a special case inside the DBX driver.  Unfortunately neither Embarcadero nor Chau Chee Yang, maker of the alternative dbExpress Firebird driver, has released the source to their drivers, neither driver handles the BOOLEAN domain, and neither driver has any sort of callback/event handler that you can set up to intercept and modify the schema of a query result.  But I’m not gonna let a little thing like that stop me! Continue reading ‘Adding boolean support to Firebird+DBX’ »

Beware using anonymous methods in loops

Quick, what’s the output of this simple routine?
Continue reading ‘Beware using anonymous methods in loops’ »

TStringList updating pitfalls

What’s wrong with this code?

[code lang="Delphi"]
procedure TMyCustomChecklistPopupControl.ClosePopup;
var
  i: integer;
begin
  inherited ClosePopup;
  FInternalItemStringList.Clear;
  for i := 0 to Self.CheckedCount - 1 do
    FInternalItemStringList.Add(Self.CheckedItems[i].Name);
end;
[/code]

Continue reading ‘TStringList updating pitfalls’ »

Little things Delphi gets right

For those who haven’t seen it yet, due to popular demand, the StackOverflow people created a new site called programmers.stackexchange.com, a site for the more subjective questions that StackOverflow isn’t really designed for.  Someone recently set up a poll: What’s your favorite programming language. You can probably guess what my answer was. Continue reading ‘Little things Delphi gets right’ »

Inheritance baggage

A couple posts ago, I mentioned that I’ve been working with code generation lately.  This is for a part of the TURBU project.  An RPG relies pretty heavily on scripting, and RPG Maker, the system I created TURBU to replace, has a fairly extensive, if limited, scripting system.  The limitations were one of the things that made me say “I could do better than this,” in fact:  No functions, no local variables, callable procedures exist but parameters don’t, so any “passing” has to be done in global variables, only two data types: integer and boolean, no event handlers, minimal looping support, etc.

Continue reading ‘Inheritance baggage’ »

Adding non-data fields to a client dataset

A lot of the UI design for the TURBU editor is based on data-aware controls bound to client datasets.  I was trying to build a new form this morning that required me to filter one of the datasets.  Problem is, that would break other things that expected it not to be filtered.  Well, that’s not such a big problem, because TClientDataset has an awesome method called CloneCursor that lets you set up a second client dataset that shares the first one’s data store, but with independent view settings.  So I used a cloned dataset, and immediately got an exception when I tried to run.  The control I was using couldn’t find the field.

Continue reading ‘Adding non-data fields to a client dataset’ »

How to break the D2010 compiler

I really loved when Delphi 2009 came out, how it fixed so many ugly problems in the Delphi IDE.  The stability issues and memory leaks that plagued D2006 and D2007 were greatly reduced.  And it just got better in D2010.

The tradeoff, though, seems to have been compiler stability.  Trying to do anything with Generics in D2009 before Update 3 came out was a nightmare, and even after, (and even in D2010,) there were still plenty of dark corners where you can end up with an Internal Compiler Error or linker error on something that, syntactically speaking at least, is perfectly cromulent Object Pascal.

Continue reading ‘How to break the D2010 compiler’ »