Am I doing this right?
I am populating the objects in a TStringlist with records which I create during populating.
I have set the TStringList.OwnsObjects to true. However when I close down the application I get an access violation. Below is an extract of my code.
type
PUsageData = ^TUsageData;
TUsageData = record
DeclaredIn: String;
LineNumber: Integer;
TotalUsage: Integer;
end;
...
var VarUsages: TStringList; // object contains a TUsageData record
procedure BuildUsageList;
var idx, idy, n,m: Integer;
sl: TStringList;
s,t: String;
rec: PUsageData;
begin
VarUsages.Clear;
sl:= TStringList.Create;
s := '';
// First make a list and create a record for each variable declared in program
for idx := 0 to IncludeList.Count -1 do begin
GetSource(IncludeList[idx], sl);
for idy := 0 to sl.Count -1 do begin
t := '';
t := CodeAnalyser.GetItems(sl[idy], caVariables);
if t > '' then begin
system.New(Rec);
rec.DeclaredIn := IncludeList[idx];
rec.LineNumber := idy;
rec.TotalUsage := 0;
VarUsages.AddObject(t, TObject(rec));
end;
end;
end;
end;
...
initialization
VarUsages := TStringList.Create;
VarUsages.OwnsObjects := true;
finalization
VarUsages.Free;
end.
I am using Delphi 10.1.
I am also wondering what happens when I clear the StringList. Does it dispose the Objects?