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)