1

I have a form with a public variable of some type of function pointer, like this:

{...}
interface
  type TExternalFunction = function(var x : TAnotherCustomType): smallint;

{...}
var
  MyExternalFunction : TExternalFunction; 

{...}
implementation

function CreateThisForm():smalint;
begin
  if (Assigned(MyExternalFunction)) then
  begin
    // do something
  end;  
end; 

Do you see any possible problems?

Do I have to explicitly initialize the public function pointer to nil? A Co-Worker suggested initializing the function pointer to nil in the Initialization part of the form, does this make sense?

Thanks in advance

skylla
  • 464
  • 3
  • 7
  • 17
  • [Are delphi variables initialized with a value by default?](http://stackoverflow.com/questions/132725/are-delphi-variables-initialized-with-a-value-by-default) – bummi Oct 13 '14 at 05:38

1 Answers1

3

If you don't initialize a global variable, it will be initialized with 0 (or nil): http://docwiki.embarcadero.com/RADStudio/XE7/en/Variables

So I don't see a problem with that code. But you could run into trouble if MyExternalFunction points to function in a dll and you unload the dll later without setting MyExternalFunction back to nil.

Sebastian Z
  • 4,520
  • 1
  • 15
  • 30