Board index » delphi » How to use 'non visual components'?

How to use 'non visual components'?

Hello,

I want to use the TTable in a (self made) object, and I don't want to use a
TTable I placed on my form. In my object, I can use it as Form1.TTable, but
in this manner is a form neccesery.

When I declare Table as TTable in my object, I get runtime errormessages.

Sorry for my english,

Marinus

 

Re:How to use 'non visual components'?


Re:How to use 'non visual components'?


This generates an 'access violation':

function
TSAPI.GetTableFieldRights(TableName:string;Field:string;User:string):integer
;
var Table:TTable;
    index,Rights:integer;
    SecData:TSecData;
begin
   Table.NewInstance;
   Table.DatabaseName:='TDM';
   Table.TableName:=Tablename;
end;

Marinus den Breejen <marin...@harley.nl> wrote in article
<01bd41ce$afa90500$05000...@bohr.harley.nl>...

Quote
> Hello,

> I want to use the TTable in a (self made) object, and I don't want to use
a
> TTable I placed on my form. In my object, I can use it as Form1.TTable,
but
> in this manner is a form neccesery.

> When I declare Table as TTable in my object, I get runtime errormessages.

> Sorry for my english,

> Marinus

Re:How to use 'non visual components'?


Try (top of my head, don't shoot ;-):

  Var table: TTable;
  Begin
    table := TTable.Create( Application );
    table.DatabaseName:='TDM';
    table.TableName:=Tablename;
    { set various other props }
    table.Open;
    { blah blah }
    table.Free;
  End;

JdV!!

Quote
Marinus den Breejen wrote:

> This generates an 'access violation':

> function
> TSAPI.GetTableFieldRights(TableName:string;Field:string;User:string):integer
> ;
> var Table:TTable;
>     index,Rights:integer;
>     SecData:TSecData;
> begin
>    Table.NewInstance;
>    Table.DatabaseName:='TDM';
>    Table.TableName:=Tablename;
> end;

> Marinus den Breejen <marin...@harley.nl> wrote in article
> <01bd41ce$afa90500$05000...@bohr.harley.nl>...
> > Hello,

> > I want to use the TTable in a (self made) object, and I don't want to use
> a
> > TTable I placed on my form. In my object, I can use it as Form1.TTable,
> but
> > in this manner is a form neccesery.

> > When I declare Table as TTable in my object, I get runtime errormessages.

> > Sorry for my english,

> > Marinus

--
========================================================================
Jan de Visser                          etmjdvi@_aom_.ericsson.se
M?/ETX/A/B NMAC Team SAC               (Remove underscores)
tel. +46 31 74 71890                   ECN 865 71890
                    Vette pech voor de kabouters!
========================================================================

Re:How to use 'non visual components'?


Re:How to use 'non visual components'?


  First, don't EVER name a component after it's parent type...  (ie. naming
a TTable as Table, TOpenDialog as OpenDialog (etc...)  --  Give them usuable
names (MyTable or Table1, etc...)

  Now, why in the world are you creating a TTable at run-time?  (Because you
don't want it on your form?  --  Then use a datamodule...)  --  Doing what
you're doing is (i'm sorry, no offense) stupid...  You're going to have to
programatically go through and hook up all your components, datasources,
everything...  It's a COMPLETE waste of time, when all you have to do is do
it at run-time...  Like I said, there's absolutely no reason to do this
(hell, put the left and top property at 5000, so you'll never see it...)

  However, if you're that deteremined to do it, good luck...  You're going
to need it...

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  Resistance is Futile.  You will be Assimiliated."

Quote
Marinus den Breejen wrote in message

<01bd41ce$afa90500$05000...@bohr.harley.nl>...
Quote
>Hello,

>I want to use the TTable in a (self made) object, and I don't want to use a
>TTable I placed on my form. In my object, I can use it as Form1.TTable, but
>in this manner is a form neccesery.

>When I declare Table as TTable in my object, I get runtime errormessages.

>Sorry for my english,

>Marinus

Re:How to use 'non visual components'?


Re:How to use 'non visual components'?


  It's also because of the variable...  Never name a component after it's
parent type --  This will GPF your app. faster then you can shake a stick at
it...

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  Resistance is Futile.  You will be Assimiliated."

Quote
Jan de Visser wrote in message <34F40144.11595CF6@_aom_.ericsson.se>...
>Try (top of my head, don't shoot ;-):

>  Var table: TTable;
>  Begin
>    table := TTable.Create( Application );
>    table.DatabaseName:='TDM';
>    table.TableName:=Tablename;
>    { set various other props }
>    table.Open;
>    { blah blah }
>    table.Free;
>  End;

Re:How to use 'non visual components'?


Re:How to use 'non visual components'?


No offence Jason, but I don't think it's stupid at all.  I quite often
instantiate a TTable to perform a lookup (e.g. I have a function which
instantiates a TTable to return unique keys from my Unique Key table).
TTables I use like this are never connected to any datasources or
data-aware components, so that isn't a problem.  It also means I can use
TTables in units which don't have associated DFMs (the original poster
never said he had a form...), which keeps my project simpler.  Also the
original poster didn't say which version of Delphi he was using; i.e. if
he's using Delphi 1, a datamodule isn't an option.

Also forgive me if I'm wrong, but surely "Table1" is as differently named
from TTable as "Table", from the compilers point of view?  Having said
that, I use Hungarian notation when naming components...

I don't think luck comes into it.  As a developer, I'm quite capable of
tidily doing exactly what the original poster wants.

Regards,

--
Conor
   (conor at crannburn dot com
    Remove garbage from email address to activate)

Jason Wallace <Dark...@SLSoftware.reno.nv.us> wrote in article
<6d1ik8$9s...@news.greatbasin.net>...

Quote
>   First, don't EVER name a component after it's parent type...  (ie.
naming
> a TTable as Table, TOpenDialog as OpenDialog (etc...)  --  Give them
usuable
> names (MyTable or Table1, etc...)

>   Now, why in the world are you creating a TTable at run-time?  (Because
you
> don't want it on your form?  --  Then use a datamodule...)  --  Doing
what
> you're doing is (i'm sorry, no offense) stupid...  You're going to have
to
> programatically go through and hook up all your components, datasources,
> everything...  It's a COMPLETE waste of time, when all you have to do is
do
> it at run-time...  Like I said, there's absolutely no reason to do this
> (hell, put the left and top property at 5000, so you'll never see it...)

>   However, if you're that deteremined to do it, good luck...  You're
going
> to need it...

Re:How to use 'non visual components'?


Quote
Conor Boyd wrote in message <01bd4299$222dd360$d950dfc2@conors>...

>No offence Jason, but I don't think it's stupid at all.  I quite often
>instantiate a TTable to perform a lookup (e.g. I have a function which
>instantiates a TTable to return unique keys from my Unique Key table).

  That's different...  We're talking about creating a table dynamically, and
then hooking up all the controls...  Why?  (because you don't want to look
at the TTable component on a form?  As I said, that's stupid...  It stil
uses the same resources, so you're only causing more work for yourself...)

Quote
>Also forgive me if I'm wrong, but surely "Table1" is as differently named
>from TTable as "Table", from the compilers point of view?  Having said
>that, I use Hungarian notation when naming components...

  You're correct, but he said his table was named TABLE (not Table1,
etc....)  --  That causes problems....

Quote
>I don't think luck comes into it.  As a developer, I'm quite capable of
>tidily doing exactly what the original poster wants.

  Wishing someone good luck has nothing to do with programming....  It's
what's known as 'I think you're wasting your time, but hey...  Good luck'.

Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  Resistance is Futile.  You will be Assimiliated."

Re:How to use 'non visual components'?


Hi Jason,

Jason Wallace <Dark...@SLSoftware.reno.nv.us> wrote in article
<6d59kp$ot...@news.greatbasin.net>...

Quote

>   That's different...  We're talking about creating a table dynamically,
and
> then hooking up all the controls...  Why?  (because you don't want to
look
> at the TTable component on a form?  As I said, that's stupid...  It stil
> uses the same resources, so you're only causing more work for

yourself...)

The original poster said:

Quote
> I want to use the TTable in a (self made) object, and I don't want to use
a
> TTable I placed on my form. In my object, I can use it as Form1.TTable,
but
> in this manner is a form neccesery.

I'm afraid I don't see that he was talking about using forms and hooking
controls up at all.  Maybe that's just my interpretation of his English,
but I _think_ that he wanted to know how to cleanly instantiate a TTable
object without a form, which is what a few people have told him how to do,
perfectly validly.

Cheers,

--
Conor
   (conor at crannburn dot com
    Remove garbage from email address to activate)

Other Threads