• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 1, 文章 - 9, 評論 - 4, 引用 - 0
            數據加載中……

            小觀構件

            摘自BCB的例子,越看越有點迷糊,還越覺得niubility.像觀察者又肯定不是,實在是牛...

            Main.cpp:

            //----------------------------------------------------------------------------
            //Borland C++Builder
            //Copyright (c) 1987, 1998-2002 Borland International Inc. All Rights Reserved.
            //----------------------------------------------------------------------------
            //-------------------------------------------------------------------------
            //    minicomp.cpp - uses the TCounter example component
            //-------------------------------------------------------------------------
            #include "minicomp.h"
            #include 
            <stdio.h>
            #include 
            <stdlib.h>
            #include 
            <condefs.h>
            //-------------------------------------------------------------------------
            USEUNIT("counter.cpp");
            //---------------------------------------------------------------------------
            main()
            {
              TExample example;

              
            return 0;
            }
            //-------------------------------------------------------------------------
            TExample::TExample()
            {
              TCounter Counter(
            7);
              
            int i;
              
            //把控件Counter的接口FMultiple和外部實現MultipleReached連接上
              Counter.OnMultiple = MultipleReached;

              
            for (i=0; i < 100; i++)
                Counter.Increment();
            }
            //-------------------------------------------------------------------------
            void TExample::MultipleReached(TCounter *Sender)
            {
              printf(
            "Multiple=%d reached with val=%d\n", Sender->Multiple, Sender->Val);
            }
            //-------------------------------------------------------------------------

            minicomp.h:

            //-------------------------------------------------------------------------
            //    minicomp.h - uses the TCounter example component
            //-------------------------------------------------------------------------
            #include "counter.h"
            //-------------------------------------------------------------------------
            class TExample
            {
            private:
              
            void MultipleReached(TCounter *Sender);
            public:
              TExample();
            };
            //-------------------------------------------------------------------------

            counter.h:

            //-------------------------------------------------------------------------
            //    counter.h. - example of a small, non-visual counter component
            //-------------------------------------------------------------------------
            class TCounter;         // forward

            typedef 
            void (__closure *TCounterEvent)(TCounter *Sender);
            //-------------------------------------------------------------------------
            class TCounter 
            {
            private:
              TCounterEvent FOnMultiple; 
            //這就是個函數接口
              int FVal;
              
            int FMultiple;
            public:
              __property 
            int Val = {read=FVal, write=FVal};
              __property 
            int Multiple = {read=FMultiple};
              __property TCounterEvent OnMultiple 
            = {read=FOnMultiple, write=FOnMultiple};
              
            void Clear();
              
            void Increment();
              TCounter(
            int Multiple);
            };
            //-------------------------------------------------------------------------

            counter.cpp:

            //-------------------------------------------------------------------------
            //    counter.cpp - example of a small, non-visual counter component
            //-------------------------------------------------------------------------
            #include "counter.h"
            //-------------------------------------------------------------------------
            TCounter::TCounter(int Multiple)
            {
              FMultiple 
            = Multiple;
            }
            //-------------------------------------------------------------------------
            void TCounter::Clear()
            {
              FVal 
            = 0;
            }
            //-------------------------------------------------------------------------
            void TCounter::Increment()
            {
              
            //這句執行時都是外部來調用的,此時OnMultiple已經和外面那個函數接口連接上了
              
            //也就是調用的其實是外面進來的那個函數,把this傳出去,讓外部那個函數操作
              
            //TExample::MultipleReached(this)
              if (((++FVal) % FMultiple) == 0)
                  OnMultiple(
            this);
            }
            //-------------------------------------------------------------------------

            posted on 2009-01-02 22:21 EiN 閱讀(101) 評論(0)  編輯 收藏 引用 所屬分類: C++Builder

            国产成人99久久亚洲综合精品| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | av午夜福利一片免费看久久| 精品久久久久久成人AV| 久久久久国产视频电影| 国产精品久久久久久久久软件| 性做久久久久久久| 久久久久久久国产免费看| 亚洲国产精品久久久天堂| 精品久久久无码中文字幕 | 久久精品日日躁夜夜躁欧美| 久久国产精品无码HDAV| 久久久久九九精品影院| 91精品国产综合久久精品| 一级a性色生活片久久无| 996久久国产精品线观看| 波多野结衣久久| 久久久久国产| 久久精品无码一区二区app| a高清免费毛片久久| 99久久国产宗和精品1上映| 人人狠狠综合88综合久久| 97久久精品国产精品青草| 精品国产乱码久久久久久人妻 | 久久久久久久久久久久久久| 精品国产91久久久久久久a| 97久久精品国产精品青草| 欧洲精品久久久av无码电影 | 久久久精品国产亚洲成人满18免费网站 | 91精品婷婷国产综合久久 | 国内精品久久久久久久久电影网| 久久人人爽人人爽人人片AV不| 久久久久精品国产亚洲AV无码| 久久夜色精品国产亚洲av| 国产精品九九久久免费视频 | 人妻丰满AV无码久久不卡| 久久久久亚洲AV无码专区首JN | 91精品婷婷国产综合久久| 久久精品男人影院| 99久久精品免费看国产一区二区三区 | 久久人妻少妇嫩草AV无码专区|