[gtkada] Clist and Chars_ptr_array

Preben Randhol randhol at pvv.org
Wed Nov 14 22:40:07 CET 2001


Hi I wondered if somebody please could look at the code below.

I'm a bit uncertain how one should use the Chars_ptr_array in Clist to
prevent memory leaks. Is this a correct way of doing it (see code
below)? When I leave the window with the Clist I call Clear on the
Clist. To make the list of word in the Clist I call a procedure I have
that gets the words from my linked list and puts the into the
String_Array defined below. As soon as it is appended I free the
String_Array. Is this correct?

   procedure Get_List is
      W            : Wordgroup_type;
      Row          : Gint;
   begin
      Goto_First (Lists.Main_WordList);

      Freeze (Gui_List.List_Clist);
      for I in 1...Get_Size (Lists.Main_WordList) loop
         W := Get_Element (Lists.Main_WordList);
         declare
            String_Array : Gtkada.Types.Chars_Ptr_Array := 
               Wordgroups.Get_Word (W) + Wordgroups.Get_Explanation (W);
         begin
            Row := Append (Gui_List.List_Clist, String_Array);
            Set_Cell_Style (Gui_List.List_Clist, Row, 0,
                              Window_Gui.Get_Word_Style);
            Set_Cell_Style (Gui_List.List_Clist, Row, 1,
                              Window_Gui.Get_Explanation_Style);
            Free (String_Array);
            -- Is it correct to do the free here after appending it to
            -- the list? 
         end;
         Goto_Next (Lists.Main_WordList);
      end loop;
      Thaw (Gui_List.List_Clist);
   end Get_List;

Thanks in advance!

Preben
-- 
«Don't use C;  In my opinion,  C is a library programming language
 not an app programming language.»  - Owen Taylor (GTK+ developer)

Use Ada 95, a free language. More info at http://www.adapower.com/




More information about the gtkada mailing list