views:

211

answers:

2

Hello,

It's possible to create a type idenitifier for example:

type PByte = ^Byte;

Is it possible to do the following:

function a:shortint;
begin
  Exit(8);
end;

type b = a;

so you can call "b" and "a". Is it possible?

I'm asking,because I'd like to replace "Exit" with "return" so I can call this:

return(5);// for example
+6  A: 

It seems to me you are confusing function types and definitions. You can create type for methods and functions, and you use them every day in Delphi, such as TNotifyEvent, which is the type of methods that is called on most operations with user controls. Such types allow you to define functions corresponding with a certain header (i.e. expected parameters and return value).

A whole different issue is function pointers - a pointer to a specific instance of a function, so that you can "call" the pointer and it will invoke the function. The pointer may be of a function of a certain type (as described above), but the two issues have practically nothing to do with one another.

A third totally unrelated thing is a call-stack of functions. The Exit, as mentioned by Tobias, is a reserved compiler directive and not a function per se.

To conclude, for all practical purposes what you want to achieve is not right and is not possible. You may be able to "cheat" Delphi into accepting something like that, but it would just be wrong IMHO.

Roee Adler
+1  A: 

You should use at least Delphi 2009. There is new Exit(Result) construct.

If you prefer stick with the old Delphi's version, you should check this out. There is no ready functionality for Exit(Result), but it is very easy to implement by using plugins.

Alexander
He's already demonstrating the new syntax for `Exit`. That's not what it's asking for. He's asking for a way to no longer call it `Exit`.
Rob Kennedy
Indeed, I've missed this. But even in this case he can use the DLangExtensions.
Alexander