* tagged types
@ 2002-05-30 15:30 Sami Evangelista
2002-05-30 19:11 ` Stephen Leake
0 siblings, 1 reply; 5+ messages in thread
From: Sami Evangelista @ 2002-05-30 15:30 UTC (permalink / raw)
i have declared an abstract type with two derived types like this
type father is null record;
type son1 is new father with record
son1_field : integer;
end record;
type son2 is new father with record
son2_field : boolean;
end record;
type access_son1 is access son1;
type access_son2 is access son2;
then i introduced a list of these elements and a procedure to add an
element to the list like this:
type access_father_class is access all father'class;
type list;
type access_list is access list;
type list is record
element : access_father_class;
next : access_list;
end record;
procedure add(The_list : in out access_list;
The_Element : access_father_class) is
begin
if The_list = null then
The_list := new list;
The_list.element := The_Element;
The_list.next := null;
else
add(The_list.next, The_element);
end if;
end
until there no problem. but how is it possible to add a son1 object to a
list. I have tried this:
my_object : access_son1 := new son1;
my_object.son1.field := 0;
my_list : access_list;
...
add(my_list, my_object);
and it gives me the following error message:
expected type "access_father"
found type "access_son"
Thanks for any help
Sami Evangelista
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: tagged types
2002-05-30 15:30 tagged types Sami Evangelista
@ 2002-05-30 19:11 ` Stephen Leake
2002-05-31 13:13 ` Stephen Leake
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2002-05-30 19:11 UTC (permalink / raw)
Sami Evangelista <sami.evangelista@wanadoo.fr> writes:
> i have declared an abstract type with two derived types like this
> <snip code>
It really is much easier for us to help if you post _compilable_ code.
What you posted is close, but it is missing some crucial stuff; the
leading "procedure My_Test is", etc. Also post the _entire_, _exact_
compiler error message.
If you make the effort to post a _compilable_ test, this accomplishes
three things:
1) You may find the error. Often the process of simplifying and
explaining the problem reveals the error. This is a good technique; I
use it often!
2) You make it very clear what your problem is, so you will get a more
focussed and useful reply.
3) Someone here (like me) is more likely to help.
Please repost a compilable example.
--
-- Stephe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: tagged types
2002-05-30 19:11 ` Stephen Leake
@ 2002-05-31 13:13 ` Stephen Leake
0 siblings, 0 replies; 5+ messages in thread
From: Stephen Leake @ 2002-05-31 13:13 UTC (permalink / raw)
Stephen Leake <stephen.a.leake.1@gsfc.nasa.gov> writes:
> 3) Someone here (like me) is more likely to help.
I'd like to explain this point a little. What I do when I see some
code, an error message, and a request for an explanation, is to copy
the code to a working directory, and tell GNAT to compile it. If I get
the same error message, I start messing with the code to see if I can
fix the error. Then I post the resulting code, with an explanation.
If I don't get the same error message on the first try, I look at the
code to see how much work it will be to get to that point. On a good
day, I'm willing to spend about ten minutes on this, especially if it
looks like I might learn something about Ada in the process (yes, I'm
still learning Ada; that's why I read this newsgroup :). On a bad day,
I give up immediately.
Robert's recent posts about how to best help students have tilted me
more towards giving up quickly :). I figure students should learn to
post clear programs first.
At one point, there was a FAQ or policy statement for students that
got posted periodically here; any idea what happened to that?
--
-- Stephe
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tagged Types
@ 2004-09-12 19:29 Patrice Freydiere
0 siblings, 0 replies; 5+ messages in thread
From: Patrice Freydiere @ 2004-09-12 19:29 UTC (permalink / raw)
> --- Patrice Freydiere <frett27@free.fr> wrote:
> > Jeff, I pointed out the problem ..
> > i was converting a stream_element_array in a string,
> > using the
> > stream_element_array bounds ... the array was
> > starting at 0. So at runtime,
> > an index out of bounds was raised because strings
> > starting to 0 are not
> > allowed...
> >
> > i can't get a stream_element_array formal
> > description to check if zero base
> > array is valid ??
>
> I don't understand what you mean by this. Why can you
> not get the formal description for this. You are using
> GNAT? it is in a-stream.ads
>
> Yes it is legal to start at 0 (or even negative
> values).
>
> Can you post (either here or comp.lang.ada) just the
> snippet of code from the declare block that you are
> talking about or is it too proprietary.
>
>
Here is the involve code :
begin
Ais.Log.Log("Image retreived - " &
Image.Get_Name(Im.all));
if Im=null then
Ais.Log.Log("null address ");
end if;
declare
Ba : Ada.Streams.Stream_Element_Array
:= Ais.image.Create_Thumbnail(ic);
begin
declare
S : String( 1 .. Natural(Ba'Length) );
--&&&&&&&&&&&&& when i used a 0 based string, it hang with a (null): Bad
address
-- &&&&&&&&&&&&&& with a 1 based string, OK
-- &&&&&&&&&&&&&& with using Get_Content for retrieving the
Stream_Element_Array, it 's OK ?????
begin
for J in Ba'Range loop
S(Integer(J-Ba'first)+S'first) :=
Character'Val(Ada.Streams.Stream_Element'pos(Ba(J)));
null;
end loop;
As(I) :=
Client.Base64_Data(To_String(AIS.Image.Get_Name(Im.all)),
Aws.Translator.Base64_Encode(
S ));
end;
tell me if you wanna have more code,
or you can get the entier code from imgsvr.org cvs repository
Cheers,
Patrice
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tagged Types
@ 2004-09-13 4:08 David C. Hoos
0 siblings, 0 replies; 5+ messages in thread
From: David C. Hoos @ 2004-09-13 4:08 UTC (permalink / raw)
To: comp.lang.ada
Zero-based strings are _not_ legal, because the declaration
of String allows only _Positive_ array indices.
Other array types can be declared allowing other
types for the array indices -- in fact, any
_discrete_ type can be so used.
"Patrice Freydiere" <frett27@free.fr> wrote in message
news:pan.2004.09.12.19.29.12.644532@free.fr...
>> --- Patrice Freydiere <frett27@free.fr> wrote:
>> > Jeff, I pointed out the problem ..
>> > i was converting a stream_element_array in a string,
>> > using the
>> > stream_element_array bounds ... the array was
>> > starting at 0. So at runtime,
>> > an index out of bounds was raised because strings
>> > starting to 0 are not
>> > allowed...
>> >
>> > i can't get a stream_element_array formal
>> > description to check if zero base
>> > array is valid ??
>>
>> I don't understand what you mean by this. Why can you
>> not get the formal description for this. You are using
>> GNAT? it is in a-stream.ads
>>
>> Yes it is legal to start at 0 (or even negative
>> values).
>>
>> Can you post (either here or comp.lang.ada) just the
>> snippet of code from the declare block that you are
>> talking about or is it too proprietary.
>>
>>
>
> Here is the involve code :
>
> begin
> Ais.Log.Log("Image retreived - " &
> Image.Get_Name(Im.all));
> if Im=null then
> Ais.Log.Log("null address ");
> end if;
> declare
> Ba : Ada.Streams.Stream_Element_Array
> := Ais.image.Create_Thumbnail(ic);
> begin
> declare
> S : String( 1 .. Natural(Ba'Length) );
> --&&&&&&&&&&&&& when i used a 0 based string, it hang with a (null): Bad
> address
> -- &&&&&&&&&&&&&& with a 1 based string, OK
> -- &&&&&&&&&&&&&& with using Get_Content for retrieving the
> Stream_Element_Array, it 's OK ?????
> begin
> for J in Ba'Range loop
> S(Integer(J-Ba'first)+S'first) :=
>
> Character'Val(Ada.Streams.Stream_Element'pos(Ba(J)));
> null;
> end loop;
> As(I) :=
>
> Client.Base64_Data(To_String(AIS.Image.Get_Name(Im.all)),
>
> Aws.Translator.Base64_Encode(
> S ));
> end;
>
>
> tell me if you wanna have more code,
> or you can get the entier code from imgsvr.org cvs repository
>
> Cheers,
> Patrice
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-09-13 4:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-05-30 15:30 tagged types Sami Evangelista
2002-05-30 19:11 ` Stephen Leake
2002-05-31 13:13 ` Stephen Leake
-- strict thread matches above, loose matches on Subject: below --
2004-09-12 19:29 Tagged Types Patrice Freydiere
2004-09-13 4:08 David C. Hoos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox