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.
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.
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.
ReplyDeleteIf 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.
ReplyDeleteDavid 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