Unit StringList create and destroy [SOLVED] lazarus / 21-General ---------------------------------------------------------------------- Pe3s · 2024-11-27 21:58 Hello forum members, how can I create an object in a separate unit module so as not to create and delete it in Form Create and Destroy. I want it to be created and destroyed in the unit module. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FImages := TStringList.Create; ---------------------------------------------------------------------- ackarwow · 2024-11-27 22:03 Hi @Pe3s For example in this way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit TestUnit; {$mode ObjFPC}{$H+} interface uses  Classes, SysUtils; var  FImages: TStrings; implementation initialization FImages:=TStringList. Create; finalization if Assigned(FImages) then  FreeAndNil(FImages); end. ---------------------------------------------------------------------- Pe3s · 2024-11-27 22:07 @ackarwow Hello, I wonder if using constructor and destructor will also be good ? ---------------------------------------------------------------------- cdbc · 2024-11-27 22:07 Hi Another example:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode ObjFPC}{$H+} interface uses  Classes, SysUtils; function GetImageList: TStringList; implementationvar  FImages: TStringList = nil; function GetImageList: TStringList;begin  if not Assigned(FImages) then FImages:= TStringList.Create;;  Result:= FImages;end; finalization  FImages.Free; end.   Regards Benny ---------------------------------------------------------------------- ackarwow · 2024-11-27 22:14 Quote from: Pe3s on November 27, 2024, 11:07:08 pm@ackarwow Hello, I wonder if using constructor and destructor will also be good ? Yes, you can use constuctor and destructor directly, although in case of destructor I prefer use it indirectly (via MyStrings.Free or FreeAndNil(MyStrings)). ---------------------------------------------------------------------- Pe3s · 2024-11-28 08:03 Thank you