comp.lang.ada
 help / color / mirror / Atom feed
From: xavier.serrand@free.fr (Xavier Serrand)
Subject: Re: pointers and genericity
Date: 16 Feb 2005 01:27:22 -0800
Date: 2005-02-16T01:27:22-08:00	[thread overview]
Message-ID: <344d0fee.0502160127.432c8614@posting.google.com> (raw)
In-Reply-To: 17cfosskqxdi0$.1ux9v3kndb9kr$.dlg@40tude.net

You are right... trouble comes from that

package body Test_Gen_Pk_User  is

   function Min (A, B : in Natural) return Natural is
   begin
      if (A < B) then
         return A;
      else
         return B;
      end if;
   end;
   procedure Proc_Suiv (E : in out Pk_DS.T_Record; 
                        S : out string) is
   begin
      S := (others => ' ');
   end;

   procedure Assign (U : in out T_User; 
                     S : in string; E : in T_Element;
                     Proc_Next, Proc_Prev : in Pk_DS.T_Proc_Browse) is
   begin
      U.Nom(1..Min(U.Nom'Last, S'Last)) := S(1..Min(U.Nom'Last,
S'Last));
      U.Rec.Data := E;
      U.Rec.Prev := Proc_Prev;
      if not Pk_DS."=" (Proc_Prev, null) then
         U.Rec.Next := Proc_Next;
      else
         -- ***********************
         -- and now some trouble !!
         -- ***********************
         U.Rec.Next := Proc_Suiv'access;
      end if;
   end;
End Test_Gen_Pk_User ;

==============Error messages for source file:
test/test_gen_pk_user.adb
    30.          U.Rec.Next := Proc_Suiv'access;
                               |
        >>> access type must not be outside generic body



-- and the correct packages

generic
  type T_Elem is private;
  Null_Elem : in T_Elem;
package Test_Gen_Pk_DataSource is
   type T_Record;
   type T_proc_Browse is access procedure (E : in out T_Record; 
                                           S : out string);
   type T_Record is record
      Data : T_Elem;
      Next : T_Proc_Browse;
      Prev : T_Proc_Browse;
   end record;
end Test_Gen_Pk_DataSource ;

with Test_Gen_Pk_DataSource;
generic
  type T_Element is private;
  Null_Element : in T_Element;
  with package Pk_DS is new Test_Gen_Pk_DataSource (T_Elem =>
T_Element,
                                                    Null_Elem =>
Null_Element);
package Test_Gen_Pk_User is
   type T_User is record
      Nom : string (1..33) := (others => ' ');
      Rec : Pk_DS.T_Record := (Data => Null_Element, 
                               Next => null, Prev => null);
   end record;
   procedure Assign (U : in out T_User; 
                     S : in string; E : in T_Element;
                     Proc_Next, Proc_Prev : in Pk_DS.T_proc_Browse);
end Test_Gen_Pk_User;


with Test_Gen_Pk_DataSource;
with Test_Gen_Pk_User; 

procedure Test_Gen_Prg_User is
   package Pack_DS is new Test_Gen_Pk_DataSource (T_Elem => Character,
                                                  Null_Elem => ' ');


   package Pack_US is new Test_Gen_Pk_User (T_Element => Character,
                                            Null_Element => ' ',
                                            Pk_DS => Pack_DS);
   procedure Proc_Suivant (E : in out Pack_DS.T_Record; 
                           S : out string) is
   begin
      S := (1 => E.Data, others => ' ');
      E.Data := Character'Val (Character'Pos(E.Data)+1);
   end;
begin
   declare
      U : Pack_US.T_User;
   begin
      Pack_US.Assign (U, "joe", 'a', null, null);
   end;
end;

In fact i would like to make scrollable data sources controlled by
event handlers (basic package) and some uses like arborescent menus,
data visualisation...



  reply	other threads:[~2005-02-16  9:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-02-15 12:10 pointers and genericity Xavier Serrand
2005-02-15 13:12 ` Dmitry A. Kazakov
2005-02-16  9:27   ` Xavier Serrand [this message]
2005-02-16  9:35     ` Martin Dowie
2005-02-16  9:53     ` Egil H. H�vik
2005-02-16 15:00     ` Robert A Duff
2005-02-17 22:50       ` Xavier Serrand
2005-02-17 23:11       ` Randy Brukardt
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox