Jump to content

Search the Community

Showing results for tags 'data'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 1 result

  1. PawelPepe

    How to free TListView Objects (String)

    Hi, I got a problem with TListView and Data. It seems that I got memory leaks, because Data pointers are not released (if I understand it well). Let me show you what I do: Here is a simple TListView (LV_Data). I add few items to the list (Report Style) into 3 Columns. var i : Integer; ListItem : TListItem; PObject : PChar; for i := 0 to 3 do begin // Caption ListItem := AList.Items.Add; ListItem.Caption := 'My Caption' + '_' + Inttostr(i+1); // Language Name ListItem.SubItems.Add('Language' + '_' + Inttostr(i+1)); // User Name ListItem.SubItems.Add('User Name' + '_' + Inttostr(i+1)); // User Data Path PObject := StrAlloc(250); StrPCopy(PObject, 'PATH_TO_USER_DIRECTORY' + '_' + Inttostr(i+1)); ListItem.Data := PObject; end; As you can see, I also add "hidden" data (in this example a path to directory, as string). I can use it in program, without displaying it to user in listview. I can read it in simple way (for examle, in ListView OnClick event:) var sPath : string; if (LV_Data.Items.Count > 0) AND (LV_Data.ItemIndex <> -1) then begin sPath := StrPas(PChar(LV_Data.Items[LV_Data.ItemIndex].Data)); end; Everything works very nice... but, when I close program, I see there are some memory leaks. --------------------------- Unexpected Memory Leak --------------------------- An unexpected memory leak has occurred. The unexpected small block leaks are: 473 - 520 bytes: Unknown x 3 --------------------------- OK --------------------------- As far as I know, I have to free those List View Data bymyself. How to do this? procedure TMainFrm.LV_DataDeletion(Sender: TObject; Item: TListItem); begin if Item.Data <> nil then begin FreeMem(Item.Data); Item.Data := nil; end; end; Above code not working (why!?), got Invalid Pointer Operation. Could you please tell me how to free this data to avoid memory leak? Thank you in advance, -Pawel
×