views:

103

answers:

3

I am creating a Delphi service. Is there any way to use controls derived from TWinControl within services? Ultimately the control and any controls I place on it will be saved to a bitmap. But anything I try I get "control has no parent window" error.

I have successfully created a TBitMap and can accomplish the same functionality. But having all the functionality built into the VCL would greatly simplify the task.

+1  A: 

I don't think Windows Services are provided a desktop service. If that is the case (no desktop), then you won't be able to do anything that requires a window handle in a service.

TBitmap works there because it uses bitmap handles and memory DCs. No window handles required.

dthorpe
+2  A: 

Your program complains that the control has no parent window, so give it one. Create a form and put your controls there. Forms can be top-level windows, so they don't need to have parents. The form will serve as the parent window for the rest of your controls.

They still won't be visible, but they will at least exist.

Rob Kennedy
This did in fact work. Ultimately I will be converting the panel and its contents to a jpeg. As I commented above, the reason I thought about this route is because I am more versed working with VCL components. But is this safe in a TWebModule environment? I do know for me to achieve my goal I have to call the form.show method. Perhaps ultimately I will end up just writing to a bitmap object.
M Schenkel
Form.Show is fine. But the form still won't be visible because services are given a separate desktop to run on. No human will ever see a service's UI.
Rob Kennedy
Thanks Rob. If you don't mind replying, is this "bad programming"? As I said, I am trying to take advantage of what the VCL has to offer, even though everything will be converted to jpeg and never seen in its native form.
M Schenkel
As I see it, any time a program makes a picture of a UI, it's probably a bit of a hack. But I don't know your program. Do what you have to do.
Rob Kennedy
A: 

because of delphi service application can not use twincontrol(forms unit) i always using windows service wrapper. the best wrapper now i know nssm. it is a open source application and runs your application in system account privileges in service mode. it can control your application exit code and log it.

sabri.arslan
Delphi service applications *can and do* use the Forms unit. The SvcMgr unit even uses it directly.
Rob Kennedy