Board index » off-topic » How do you create a local ttable object

How do you create a local ttable object


2003-07-16 11:43:01 PM
off-topic6
Hi I am trying to create a local ttable a runtime and can't figure out what
to uses as AOwner in the method.
I have tried self and that didn't work. Below is a example of the code.
I want to be able to create and then free the table object
Is there an example code that show how to do this
Also to clear the index for this tabel do I use
TblOLDDB.indexdef.clear; to do this
Procedure newtable;
var
tblOLDDB : TxTable;
begin
tblOLDDB := tblolddb1.Create(???????);
tblOLDDB.free;
end;
Also to clear the index for this tabel do I use
TblOLDDB.indexdef.clear; to do this
 
 

Re:How do you create a local ttable object

In article < XXXX@XXXXX.COM >, steve < XXXX@XXXXX.COM >
writes
Quote
Hi I am trying to create a local ttable a runtime and can't figure out what
to uses as AOwner in the method.

I have tried self and that didn't work. Below is a example of the code.

I want to be able to create and then free the table object

Is there an example code that show how to do this

Also to clear the index for this tabel do I use

TblOLDDB.indexdef.clear; to do this



Procedure newtable;

var

tblOLDDB : TxTable;

begin

tblOLDDB := tblolddb1.Create(???????);

tblOLDDB.free;

end;

Also to clear the index for this tabel do I use

TblOLDDB.indexdef.clear; to do this


I would use TblOLDDB.Create(Application);
and make sure you free it after use :-
TblOLDDB.Free;
HTH
--
andy
 

Re:How do you create a local ttable object

A TxTable is really a TTable. I defined TxTable to be of type TTable so that
in the future I could change it if I went to a different database.
I tried "self" but it didn't work, BUT I will try it again per your example
to see if I am mistaken.
Thanks
Steve
What is a TxTable? It is not a Borland supplied component. Assuming
Quote
that what you really want is a TTable:

var
ATable: TTable;
begin
ATable := TTable.Create(Self);
try
...do whatever...
finally
ATable.Free;
end;

Note that the constructor (the Create method) is a method of the
class, not the instance.

ATable.IndexDefs.Clear;

will clear the IndexDefs collection. Note that this has no effect on
the database table. It just empties the IndexDefs collection of the
TTable component.


--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
"Bill Todd" < XXXX@XXXXX.COM >wrote in message
Quote
What is a TxTable? It is not a Borland supplied component. Assuming
that what you really want is a TTable:

var
ATable: TTable;
begin
ATable := TTable.Create(Self);
try
...do whatever...
finally
ATable.Free;
end;

Note that the constructor (the Create method) is a method of the
class, not the instance.

ATable.IndexDefs.Clear;

will clear the IndexDefs collection. Note that this has no effect on
the database table. It just empties the IndexDefs collection of the
TTable component.


--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
 

{smallsort}

Re:How do you create a local ttable object

To add to what Bill said, you don't need to pass an object in to AOwner.
For example,
aTable:= TTable.Create( nil);
is also valid. All you do when you pass in an object for AOwner is make
AOwner the owner of the TTable when you're creating. Then, when AOwner gets
freed, it will automatically free everything that it owns (including your
TTable), so you don't have to free your TTable manually yourself. I am
under the impression that if you pass in 'nil' for AOwner, then you must
explicitly free the TTable. But, if you pass in an actual object to AOwner
(like 'Self') then you should NOT explicitly free the TTable, because when
AOwner gets freed it's going to try to free TTable which you have already
gotten rid of, and I _think_ this can cause problems.
So the correct code (I think) is either:
aTable:= TTable.Create( nil);
try
{do some stuff}
finally
aTable.Free;
end;
OR
aTable:= TTable.Create( Self);
{do some stuff}
{aTable will be freed automatically when Self is freed}
In the above, Self is likely the DataModule in whose code you are creating
the TTable. I usually prefer to use the former approach (Create( nil))
because I can get rid of stuff as soon as I no longer need it.
"steve" < XXXX@XXXXX.COM >wrote in message
Quote
A TxTable is really a TTable. I defined TxTable to be of type TTable so
that
in the future I could change it if I went to a different database.

I tried "self" but it didn't work, BUT I will try it again per your
example
to see if I am mistaken.

Thanks

Steve

What is a TxTable? It is not a Borland supplied component. Assuming
>that what you really want is a TTable:
>
>var
>ATable: TTable;
>begin
>ATable := TTable.Create(Self);
>try
>...do whatever...
>finally
>ATable.Free;
>end;
>
>Note that the constructor (the Create method) is a method of the
>class, not the instance.
>
>ATable.IndexDefs.Clear;
>
>will clear the IndexDefs collection. Note that this has no effect on
>the database table. It just empties the IndexDefs collection of the
>TTable component.
>
>
>--
>Bill (TeamB)
>(TeamB cannot respond to questions received via email)
"Bill Todd" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...
>What is a TxTable? It is not a Borland supplied component. Assuming
>that what you really want is a TTable:
>
>var
>ATable: TTable;
>begin
>ATable := TTable.Create(Self);
>try
>...do whatever...
>finally
>ATable.Free;
>end;
>
>Note that the constructor (the Create method) is a method of the
>class, not the instance.
>
>ATable.IndexDefs.Clear;
>
>will clear the IndexDefs collection. Note that this has no effect on
>the database table. It just empties the IndexDefs collection of the
>TTable component.
>
>
>--
>Bill (TeamB)
>(TeamB cannot respond to questions received via email)