1. Coloque False na variável:

TReg = record
private
FInicializado: Boolean = False; / *******************
FData: array of string;
function GetCount: Integer;
function SetCount(const Value: Integer);
public
property Count: Integer read GetCount write SetCount;
property Data[Index: Integer] read GetData write SetData;
end;

===================================================


Guionardo Furlan escreveu:
>
> Buenas pessoal, postei esta mesma dúvida no newsgroup da u-br.
>
> No D2007, tenho um record similar a este.
>
> TReg = record
> private
> FInicializado: Boolean;
> FData: array of string;
> function GetCount: Integer;
> function SetCount(const Value: Integer);
> public
> property Count: Integer read GetCount write SetCount;
> property Data[Index: Integer] read GetData write SetData;
> end;
>
> function TReg.GetCount: Integer;
> begin
> if not FInicializado then
> begin
> SetLength(FData,0);
> FInicializado:=True;
> end;
> Result:=Length(FData);
> end;
>
> procedure TReg.SetCount(const Value: Integer);
> begin
> if Value in [0..255] then
> SetLength(FData,Value);
> end;
>
> function TReg.GetData(const Index: Integer): string;
> begin
> if (Index>=0) and (Index<Count) then
> Result:=FData[Index]
> else
> Result:='';
> end;
>
> procedure TReg.SetData(const Index: Integer; Value: string);
> begin
> if (Index>=0) and (Index<Count) then
> FData[Index]:=Value;
> end;
>
> Agora às dúvidas:
>
> 1. Quando eu defino uma variável com o tipo TReg, o campo FInicializado
> Booleano é *sempre* criado como False?
>
> 2. Após vários processos em que o tamanho da array de strings FData é
> modificado, pode ocorrer vazamento de memória?
>
> Num sistema, criei um record similar a este, e depois disso, começaram a
> aparecer mensagens do FastMM falando sobre vazamento de memória com tipos
> string, que não estou conseguindo identificar.
>
> No NG, recebi dicas para utilizar classes ao invés de records, mas foi 
> o que
> me pareceu mais econômico, já que as variáveis record serão acessadas
> localmente, dentro de outras classes.
>
> -- 
> Timeo hominem unius libri
> Cogito ergo sum - Carpe diem
>
> []s
> Guionardo Furlan
> http://guionardo.blogspot.com <http://guionardo.blogspot.com>
>
> [As partes desta mensagem que não continham texto foram removidas]
>
>  

Responder a