Como saber se um objeto ja esta criado?!

Delphi

12/01/2004

Oi,

Alguem pode me ajudar, em um while eu crio uma tabela temporaria, e quando acontece a repeticao da um erro pq tenta criar o objeto novamente.

Como eu faço para saber se este objeto esta criado?!

Ahhh o objeto é um TTable


Obrigado

[rock][it]


Rock.it

Rock.it

Curtidas 0

Respostas

Motta

Motta

12/01/2004

Tests for a nil (unassigned) pointer or procedural variable.

Unit

System

Category

miscellaneous routines

function Assigned(var P): Boolean;

Description

Use Assigned to determine whether the pointer or procedure referenced by P is nil. P must be a variable reference of a pointer or procedural type. Assigned(P) corresponds to the test P<> nil for a pointer variable, and @P <> nil for a procedural variable.

Assigned returns False if P is nil, True otherwise.

Note:Assigned can´t detect a dangling pointer--that is, one that isn´t nil but no longer points to valid data. For example, in the code example for Assigned, Assigned won´t detect the fact that P isn´t valid.

var P: Pointer;

begin
P := nil;
if Assigned (P) then Writeln (´You won´´t see this´);
GetMem(P, 1024);{P valid}
FreeMem(P, 1024);{P no longer valid and still not nil}
if Assigned (P) then Writeln (´You´´ll see this´);
end;


----
asim

if Assigned (table1) then
...


GOSTEI 0
Denis

Denis

12/01/2004

Outra forma....

Como o seu componente é um table, ele está associado a um arquivo. Então pode testar se o arquivo existe.

Por exemplo

if FileExists(´temporario.db´)=False then
....... // processa sua rotina
else
....... // tabela já associada a um arquivo.


GOSTEI 0
Rock.it

Rock.it

12/01/2004

:lol:

Conssgui fazer, os dois jeitos deram certo!

Muito obrigado pela ajuda!

8) [rock][it]


GOSTEI 0
POSTAR