Re: Delphi 5 server app as a dll without forms



"gforce" <gloeppky@xxxxxxxxx> wrote in message
news:86a94694-f73e-4a52-b180-e9ca9fad4825@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[...]
If you don't mind I ask another question about this. I've read all
over and it seems that you are indicating the same thing that I've
read which is the method used for the OnEvent needs to be in a class.
Is there anyway around this? Since I'm working outside of a form I
don't have a parent object. I just have a procedure. This kind of
gets back to needing a form, it seems that everything is tailored
around forms and to get things to work without a form tends to require
working around the default environment. Of course, having a form in a
dll environment is also complicated, since than you have to manually
instantiate it.

You don't need a _form_, you need a _class_. But you can get away with
not instantiating it, since class methods work as event handlers. It's
not really kosher, but in D6 it works for me.

And if you know what you're doing, you don't even need a class, just a
procedure with the right signature, and then you tell the compiler that
you know what you're doing and to treat it as a method. Add a Self
parameter, use the register calling convention, and cast away. There is
an example in some code I published once, in
http://www.kittensandcats.net/maarten/consoletictactoe.dpr,
look carefully what is done with GameEnd.


The person hiring me to do this loves Delphi Pascal because of it's
form approach to programming and suggest that I just have an invisible
form but he hasn't made a dll with Delphi Pascal. To me it seems like
the wrong approach.

It is. The whole Forms-designers-RAD thing works well for many programs
but the moment comes when you have to go beyond it and _program_ for a
living.


I've tried putting everything into a class however, you can't export a
class. It seems that I'm going to have to put all my objects that I
want to use OnEvent methods for are going to have to be in a class and
than I will have to expose a few procedures to export. Is that the
right track?

Classes are very much language- and even compiler-bound, and DLLs
generally have a simple C-style interface that just will not do. One
usually 'flattens' any classes used internally, into class factories
and procedures with explicit Self parameters. Some information (and
type safety) is lost along the way.

Events existed before OO, though. Procedure pointers work just like
method pointers and it is quite possible to build 'events' using them
without involving classes. They are then usually called callbacks, but
the principle is exactly the same: you give someone a pointer to code,
and at the right moment, they call through it.


Thanks for all the great help by the way.

We aim to please. Take cover.

Groetjes,
Maarten Wiltink


.