oops? 
Author Message
 oops?

Hullo all!

I'm wondering how Turbo Pascal implements object oriented
techniques.  I'm aware of its object type, but it seems like the
keywords constructor and destructor don't do what I expect.  for
one thing, constructors don't initialize my instances  - which is
very strange.  Also, the virtual keyword doesn't do what I expect
it to do either.  Does Turbo Pascal use these keywords in another
way or something?

I'm trying to learn its object oriented constructs through the help
system (not very helpful at all) and the example programs for TP 6
& 7.  I know that my questions can be easily answered by a manual
or a book, but I don't have any.  My computer account doesn't seem
to have online manuals either.

Any replies are welcome

BTW, what's the inherited keyword all about?  I tried to use private
and public also, but they don't work!

--
The morning is bright and full of life here on this part of the earth.
What about yours?



Wed, 18 Jun 1902 08:00:00 GMT  
 oops?

Quote:

> Hullo all!
> I'm wondering how Turbo Pascal implements object oriented
> techniques.  I'm aware of its object type, but it seems like the
> keywords constructor and destructor don't do what I expect.  for
> one thing, constructors don't initialize my instances  - which is

the keywords themselves are not supposed to do so, they indicate
that _your_ code that follows them will initialize an instance
or kill one

Quote:
> very strange.  Also, the virtual keyword doesn't do what I expect
> it to do either.  Does Turbo Pascal use these keywords in another
> way or something?

sorry, someone else will have to help you here since I haven't figured
out the difference between 'virtual' and 'nomal' myself... :-(

Quote:
> I'm trying to learn its object oriented constructs through the help
> system (not very helpful at all) and the example programs for TP 6
> & 7.  I know that my questions can be easily answered by a manual
> or a book, but I don't have any.  My computer account doesn't seem
> to have online manuals either.
> Any replies are welcome
> BTW, what's the inherited keyword all about?  I tried to use private
> and public also, but they don't work!

procedure myobject.someproc;
begin
inherited someproc;
 ^^^^^^^^^^^^^^^^   calls the someproc method of the Object you derived
'myobject' of

[...]
end;

Quote:
> --
> The morning is bright and full of life here on this part of the earth.
> What about yours?

the night is dark and the lab i work in has no windows  (not even MS-Win..
;-)
--



Wed, 18 Jun 1902 08:00:00 GMT  
 oops?

|>
|> I'm wondering how Turbo Pascal implements object oriented
|> techniques.  I'm aware of its object type, but it seems like the
|> keywords constructor and destructor don't do what I expect.  

Just how exactly do they _not_ function as the way you expect?

|> for one thing, constructors don't initialize my instances  - which is
|> very strange.  Also, the virtual keyword doesn't do what I expect
|> it to do either.  Does Turbo Pascal use these keywords in another
|> way or something?

The constructor, destructor, and any virtual functions works fine with me.

|> I'm trying to learn its object oriented constructs through the help
|> system (not very helpful at all) and the example programs for TP 6
|> & 7.  I know that my questions can be easily answered by a manual
|> or a book, but I don't have any.  My computer account doesn't seem
|> to have online manuals either.
|>
|> Any replies are welcome
|>
|> BTW, what's the inherited keyword all about?  I tried to use private
|> and public also, but they don't work!

I'll let the others answer the other parts of your question.  But as regards
to using the private and public part, just how exactly do you use them?
If you're expecting to limit the access to some variables and/or methods using
the private keyword, that's applied to user's access to the object or
other objects using it as a base class.  But while you're inside that object
(i.e. on methods of that object), you will be able to access all its variables
and/or methods whether they are public of private (not considering those which
it inherits).

I don't know if I'm clear about what I said, but if you have particular problems,
you might like to post the code so we could dissect them a little...

YO!

--
Erwin D. Paguio
http://rh.iist.unu.edu/~ep/ydeeps.html
Pascal and ASM Enthusiast



Wed, 18 Jun 1902 08:00:00 GMT  
 oops?

: > very strange.  Also, the virtual keyword doesn't do what I expect
: > it to do either.  Does Turbo Pascal use these keywords in another
: > way or something?

: sorry, someone else will have to help you here since I haven't figured
: out the difference between 'virtual' and 'nomal' myself... :-(

I give it a try. :-)

To better explain let's look at some code:

type
 TObj1 = object(TObject)  <-- Make a descendent of TObject,
                              which does very little. Some memory allocactions
                              I think at the most.... ??? :-/
           w : word;
           construtor Init(N : word);
           destrucotr Done;
           procedure AProc; virtual;
           procedure BProc;
         end;

 TObj2 = object(TObj1);
           Procedure AProc;
           Procedure BProc;
         end;

Procedure TObj1.AProc;
 begin;
   writeln(w);
 end;

Procedure TObj1.BProc;
 begin;
   writeln(55);
 end;

Procedure TObj2.AProc;
 begin;
   inherited AProc;  <-- Calls TObj1.AProc.
   writeln(w+6);
 end;

Procedure TObj2.BProc;
 begin;
   writeln(77);
 end;

var
 Obj1 : TObj1;
 Obj2 : TObj2;

begin;
  Obj1.Init(5);
  Obj2.Init(10);
  Obj1.AProc
  Obj1.BProc
  Obj2.AProc
  Obj2.BProc
end.

This will be the output (I think, have no chance to test it now... :(
I'm sitting at a Sparc running X under Solaris :) ).

5
55
10
16
77

Ok some explanations:
 First, the inherited does so that you calls the parent-objects procedure
(see Obj2.AProc which puts out 10 and 16 (=10+6)).
 Second, a virtual method makes it possible to use "inherited". I.e. it is
possible to overrun the procedure (or method if we should speek OOP).
 A non-virtual metod cannot be overrun. I.e. a inherited-keyword will result
in a error (compiler-).

Hope this helps a bit. Try to get your hand son the manuals, check with
the systemadm. They might have it in thier room/place.
 If not, ask again if somethink unclear.... :-)

/Jonas, OOP-guru-wannabe.
+------------------------------------------------------------------------+
| Who? Me?: Jonas Steverud                         | If All is One,      |

| Home....: http://www.dtek.chalmers.se/%7Ed4jonas |                     |
+------------------------------------------------------------------------+



Wed, 18 Jun 1902 08:00:00 GMT  
 oops?

Quote:
> type
>  TObj1 = object(TObject)  <-- Make a descendent of TObject,
>                               which does very little. Some memor allocactions
>                               I think at the most.... ??? :-/

Umm, no.  What it does is allows all of the elements (variables, and
methods) defined in TObject to now become part of TObj1.. so if the
declaration "x,y,z: integer" appeared in the TObject block, then anything
defined as TObj1 would also have those fields.  Ditto' on the methods.  
There may be more, I only use oop on a need-to-for-efficiency-sake basis,
so it only comes into my larger programs or units.
-chris


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. oops something went wrong with my project..............

2. HELP !!!! Pascal OOPS - Menu Question

3. runtime error 100 (my oops)

4. HELP !!!! Pascal OOPS - Menu Question

5. Oops

6. Tp6: OOPS - DOS shell

7. Tp6: OOPS - DOS shell

8. DBFs, Clipper , FOx, OOPS....

9. Oops! Dumb post!

10. Day in week and week in year calculations, oops!

 

 
Powered by phpBB® Forum Software