Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Browse thread
Object's constructor cannot access self?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yamagata Yoriyuki <yoriyuki@m...>
Subject: Re: "ocaml_beginners"::[] Object's constructor cannot access self?
From: Richard Jones <rich@a...>
Subject: "ocaml_beginners"::[] Object's constructor cannot access self?
Date: Thu, 10 Jul 2003 14:03:14 +0100

> Because the repaint method uses values and methods from the object, it
> needs to have access to self.

What is wrong with initializer? The code using initializer would
become

class graph ?width ?height ?packing ?show array =
(* The initialization code goes here. *)

object (self)
inherit widget vbox#as_widget

method private repaint () =
(* repaint method, requires access to self *)

initializer 
da#event#connect#expose
~callback:(fun _ -> self#repaint (); false);
end

Then, the code "da#event#connect#expose ~callback:(fun _ ->
self#repaint (); false);" is executed just after the creation of the
object.

--
Yamagata Yoriyuki