• <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 閱讀(103) 評論(0)  編輯 收藏 引用 所屬分類: C++Builder

            一本大道久久东京热无码AV| 狠狠色丁香婷综合久久| 亚洲国产精品无码久久一区二区 | 久久人人爽人人爽人人爽| 久久精品极品盛宴观看| 99久久精品费精品国产一区二区| 久久精品国产99久久香蕉| 精品久久久久久国产潘金莲| 伊人久久大香线蕉综合热线| 久久精品国产福利国产琪琪| 久久精品国产99国产精偷| 久久久久久综合一区中文字幕| 少妇精品久久久一区二区三区 | 久久福利片| 亚洲va国产va天堂va久久| 久久久久国产视频电影| 午夜天堂av天堂久久久| 久久婷婷午色综合夜啪| 国内精品伊人久久久久影院对白 | 日韩精品国产自在久久现线拍| 一本一本久久aa综合精品| 一本大道久久香蕉成人网| 91精品观看91久久久久久| 久久福利青草精品资源站免费| 亚洲欧美伊人久久综合一区二区| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 久久亚洲精品国产精品婷婷| 精品乱码久久久久久夜夜嗨| 成人国内精品久久久久影院VR| 国产成人综合久久综合| 好属妞这里只有精品久久| 97久久综合精品久久久综合| 成人国内精品久久久久一区| 久久精品毛片免费观看| 69久久精品无码一区二区| 国产精品一区二区久久精品| 2022年国产精品久久久久| 国内精品久久久久久野外| 中文字幕一区二区三区久久网站| 品成人欧美大片久久国产欧美...| 国产精久久一区二区三区|