Board index » delphi » Is a Form-less App possible ?

Is a Form-less App possible ?

I've been trying to write an application with no Form (for cgi).
I was able to create a program that would run with no form,
calling procedures and so forth, but I could not create a
TQuery object since I had nothing to assign as the owner,
it would not let me use Self or even Application.  In fact,
when I removed the Forms unit from the uses clause, I couldn't
reference the application at all.

Is there a way to do this?

Regards,
Chris...
cmene...@metronet.com

 

Re:Is a Form-less App possible ?


In article <31520762.2...@metronet.com>, cmene...@metronet.com
says...

Quote

>I've been trying to write an application with no Form (for cgi).
>I was able to create a program that would run with no form,
>calling procedures and so forth, but I could not create a
>TQuery object since I had nothing to assign as the owner,
>it would not let me use Self or even Application.  In fact,
>when I removed the Forms unit from the uses clause, I couldn't
>reference the application at all.

>Is there a way to do this?

As far as I know, the answer is no.  The only conceivable, ugly,
horrible, never-to-be-done idea I have is to cut the application
component and all it's dependants (easier said than done, maybe)
out of the the forms unit and make a special 'form-less'
application unit.  Include this and create an application object
with it.  Just possibly, you could use this to pass to NON-VISUAL
components.  As you probably know, visual components need a window
handle to hang off of, so you have to pass a form or something
equivalent to them; tapplication won't cut it.  

Sheesh though, for all that work, I would just learn how to
program the BDE and make direct calls to it, since it's not part
of the VCL.  I don't think this is as hard as it sounds (I know
someone who is doing it for exactly the same reason that you want
a form-less tquery).  This method would presumably be
'thread-safe' also, giving you some flexibility there also.  And,
I bet it's pretty darn fast (which is the whole point after all).

This whole discussion is highly speculative on my part, but I
thought I'd throw my two cents in.  Don't blame me if none of this
works like you want it to!  Best regards and good luck,

Steve Midgley
--
---
st...@abomb.com
Your dogma just pee'd on my karma

Re:Is a Form-less App possible ?


Quote
Chris Menegay wrote:

> I've been trying to write an application with no Form (for cgi).
> I was able to create a program that would run with no form,
> calling procedures and so forth, but I could not create a
> TQuery object since I had nothing to assign as the owner,
> it would not let me use Self or even Application.  In fact,
> when I removed the Forms unit from the uses clause, I couldn't
> reference the application at all.

> Is there a way to do this?

> Regards,
> Chris...
> cmene...@metronet.com

Perhaps you could create a form and not show it. We tried doing that
for a while. Most of my team has found that we don't need queries
however. Another thing you could try is to pass nil as the parameter.
You are creating it dynamically, right?
We are creating lots of TTable objects.
Sorry I can't add more, code is at the office.

Re:Is a Form-less App possible ?


Quote
St...@abomb.com (Steve Midgley) wrote:
>In article <31520762.2...@metronet.com>, cmene...@metronet.com
>says...

>>I've been trying to write an application with no Form (for cgi).
>>I was able to create a program that would run with no form,
>>calling procedures and so forth, but I could not create a
>>TQuery object since I had nothing to assign as the owner,
>>it would not let me use Self or even Application.  In fact,
>>when I removed the Forms unit from the uses clause, I couldn't
>>reference the application at all.

>>Is there a way to do this?

Can't you just use the Project source (i.e., the dpr file) and put
your code in between the begin and the end?  I think I did something
like this once:

Get rid of the Application.Run & Application.FormCreate.  Then put in
whatever you want:

var
  MyQuery: TQuery;

begin
  MyQuery := TQuery.Create(nil);
  try
    with MyQuery do
    begin
      SQL.Add('Select * from MyTable');
      Open;
    end;
  finally
    MyQuery.Free;
  end;
end;  

I haven't actually tested all this out to see if I'm forgetting how I
did it in the past, or if I made a mistake above.  Also, by including
the correct stuff in the Uses clause in the Project source, you can do
stuff like:

MyQuery := TQuery.Create(Session);

Althought I don't know if there are any other repercussions from using
Session like this.

Ken

Re:Is a Form-less App possible ?


On Thu, 21 Mar 1996 19:50:26 -0600, Chris Menegay <cmene...@metronet.com>
wrote:

Quote
> I've been trying to write an application with no Form (for cgi).
> I was able to create a program that would run with no form,
> calling procedures and so forth, but I could not create a
> TQuery object since I had nothing to assign as the owner,
> it would not let me use Self or even Application.  In fact,
> when I removed the Forms unit from the uses clause, I couldn't
> reference the application at all.

> Is there a way to do this?

Chris,

You bet!  First, select File|New Project and choose "CRT Application"
from the Browse Gallery dialog.  This will provide you with a project
that is still a Windows program, but WriteLn, ReadLn will be allowed
in a Window but work like they did in DOS.  If you wish, you can remove
the WinCrt unit from the uses statement (if no user input/output is
required, but is nice for debugging).

I've done this before just to see how small an app can be and I've
been able to create a simple EXE (it just beeps) that is only 3200
bytes or so in size!  Try to do that in C++ these days!

BTW, these "formless" apps are still Windows applications, so they
can still call the Windows API routines.  You'll just need to add
WinProcs, WinTypes to your uses clause.  You'll probably also want
to add SysUtils and any other unit you find yourself needing.

I just love Delphi's flexibility...

Cheers
Brad Choate <cho...@cswnet.com> | http://www.cswnet.com/~choate
You should have asked that question on the #delphi IRC channel!
Have a Coke and a :)

Re:Is a Form-less App possible ?


Quote
Chris Menegay <cmene...@metronet.com> wrote:

> I've been trying to write an application with no Form (for cgi).
> I was able to create a program that would run with no form,
> calling procedures and so forth, but I could not create a
> TQuery object since I had nothing to assign as the owner,
> it would not let me use Self or even Application.  In fact,
> when I removed the Forms unit from the uses clause, I couldn't
> reference the application at all.

We use TTables that are created with nil as the owner:
  TempT := TTable.Create(nil);
I presume you can do the same thing with TQuery;
That seems to work all right. You just have to explicitly free it at the
end.

I've written programs with WinCRT - a bit like DOS standard input and
output - that don't include the Forms unti. They produce much smaller
EXEs too.

=== Mark Patterson

Other Threads