Today's Code Rant:

Today's Code Rant:

procedure TMyEdit.DoEnter;
var
    SE: TScriptEngine;

begin
    if not Assigned(SE) then
        SE := GetScriptEngine;
    if Assigned(SE) then
        if FOnEnterScript <> '' then
            SE.RunScript(Self, FOnEnterScript);
end;

Repeat through half a dozen different events.  Now either I'm severely misunderstanding when variables are guaranteed to be initialized (not in this instance), or we're really lucky that this hasn't caused anyone problems yet, or /nobody/ is using this feature.

Comments

  1. Unless TScriptEngine is a misnommer and is actually an interface (which is likely unless you snipped out some code, otherwise you would be leaking memory as well), then you must have been lucky.

    ReplyDelete
  2. If that 'get' call is retrieving the reference from a container where the lifetime is managed it would not necessarily leak. But that first test looks useless at best.

    ReplyDelete
  3. David Knaack has it right. It's returning an already created instance (singleton), so that part's not leaking. Assuming the call even gets made, of course.

    ReplyDelete

Post a Comment