Fórum Clear Objectlist #432102
07/01/2013
0
estou com o seguinte problema.
Tenho uma classe principal
TCONTAS_RECEBER = Class(TMovimentoTabelas)
Private
...
{ private declarations }
Protected
{ protected declarations }
Public
{ public declarations }
Constructor Create;
Destructor Destroy; Override;
Published
FLISTA_PARCELAS:TLISTAPARCELAS;
Property LISTA_PARCELAS:TLISTAPARCELAS Read GetLISTA_PARCELAS Write SetLISTA_PARCELAS;
End;
Dentro dela está uma lista de Parcelas de uma conta a receber
a lista é a seguinte
TLISTAPARCELAS = Class(TObjectList)
Protected
Procedure SetObject(Index:Integer; Item:TCR_ITENS);
Function GetObject(Index:Integer):TCR_ITENS;
Procedure Insert(Index:Integer; Obj:TCR_ITENS);
Public
Function Add(Obj:TCR_ITENS):Integer;
Procedure Clear; override;
Property Objects[Index:Integer]:TCR_ITENS
Read GetObject Write SetObject; Default;
Destructor Destroy; Override;
End;
O meu problema é quando eu chamo a procedure clear
lContaReceber.LISTA_PARCELAS.Clear;
Vejo que não está excluindo os objetos, pois o count ainda retorna a quantidade de objetos existentes.
Aqui está o clear
Procedure TLISTAPARCELAS.Clear;
Var
I:Integer;
oObject:TObject;
Begin
For i := (Count - 1) Downto 0 Do
Begin
oObject := TCR_ITENS(Self.Items[i]);
Self.Delete(I);
FreeAndNil(oObject);
End;
inherited Clear;
End;
Quanto eu estou debugando vejo que o Self.count fica zero.
mais quando ele sai da função clear e volta para o código lContaReceber.LISTA_PARCELAS.Count ele ainda está com os objetos lá.
Alguém sabe como solucionar isso ?
Desde já agradeço
Andre Faria
Curtir tópico
+ 0Posts
07/01/2013
Andre Faria
TCONTAS_RECEBER = Class(TMovimentoTabelas)
Private
FLISTA_PARCELAS:TLISTAPARCELAS;
{ private declarations }
Protected
{ protected declarations }
Public
{ public declarations }
Constructor Create;
Destructor Destroy; Override;
Published
Property LISTA_PARCELAS:TLISTAPARCELAS Read GetLISTA_PARCELAS Write SetLISTA_PARCELAS;
Não achei uma forma de editar;
Gostei + 0
08/01/2013
Daniel Santos
Não sei a partir de que versao do Delphi, mais tenta criar como TObjectList.Create(True) que ai ela fica responsavel pelos objetos, ou seja, matando ela ela ja limpa tudo.
Gostei + 0
08/01/2013
Andre Faria
FLISTA_PARCELAS := TLISTAPARCELAS.Create(false);
estou criando ela como false;
nesse caso teria como dar clear na lista ?
não quero destruir o objeto lista só quero limpa-lo
Gostei + 0
10/01/2013
Rodolpho Silva
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)