Per liberare le risorse prima della chiusura puoi usare:
ObjStr.Clear; // rimuove tutte le righe
ObjStr.Free;
Il "Clear" non è strettamente necessario, ma male non fa :)
L'errore 219 è però legato a tutt'altro. Dalla guida di freepascal:
219 Invalid typecast
Thrown when an invalid typecast is attempted on a class using the as operator. This error is also thrown when an object or class is typecast to an invalid class or object and a virtual method of that class or object is called. This last error is only detected if the -CR compiler option is used.
Avevo questo problema da mesi.
Stamattina ho fatto un tentativo e sembra che adesso sia tutto ok.
Ecco com'è adesso la procedura:
procedure PulisciLista(var WrkLista:TStringList; TipoPulizia:TTipoPulizia);
var IdxPuli:Integer;
begin
if Assigned(WrkLista) then begin
for IdxPuli:=0 to WrkLista.Count - 1 do begin
//bonmar//try
//L'istruzione qui sotto l'ho aggiunta per evitare di avere un
//RunError(219) quando lanciavo il programma dall'IDE
if (WrkLista.Objects[IdxPuli] is TObject) then begin
if Assigned(WrkLista.Objects[IdxPuli] as TObject) then begin
WrkLista.Objects[IdxPuli].Free;
end;
end;
//bonmar//except
//bonmar// //Se l'oggetto è stato aggiunto tramite l'istruzione "TObject(Pointer(",
//bonmar// //senza creare il tipo, questa istruzione dava un errore
//bonmar//end;
//In ogni caso inizializzo il puntatore
WrkLista.Objects[IdxPuli]:=Nil;
end;
case TipoPulizia of
tpClear:WrkLista.Clear;
tpFree:FreeAndNil(WrkLista);
tpSoloOggetti:IdxPuli:=IdxPuli; //Se devo solo pulire gli oggetti non devo fare più niente
end;
end;
end;
Ciao, Mario