• <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中文字幕无码久久久妻妇 | 久久精品免费大片国产大片| 久久精品18| 国产成人久久精品一区二区三区| 香蕉久久夜色精品升级完成| 99久久免费国产特黄| 99久久伊人精品综合观看| 中文字幕精品久久| 国内精品久久久久影院一蜜桃| 精品国产一区二区三区久久| 久久久免费观成人影院| 久久国产亚洲精品无码| 日本精品久久久久久久久免费| 一本色道久久综合狠狠躁| 一本大道久久a久久精品综合| 久久免费视频1| 91亚洲国产成人久久精品| 久久天天躁夜夜躁狠狠躁2022| 天天爽天天爽天天片a久久网| 久久精品免费全国观看国产| 国产一级做a爰片久久毛片| 久久精品国产亚洲AV影院| 91精品免费久久久久久久久| 婷婷久久香蕉五月综合加勒比| 久久久久亚洲AV无码专区桃色| 国产欧美久久久精品| 亚洲国产另类久久久精品黑人| 国产真实乱对白精彩久久| 2020久久精品国产免费| 少妇内射兰兰久久| 亚洲va久久久噜噜噜久久男同| 欧美日韩中文字幕久久久不卡 | 久久精品中文无码资源站| 久久精品国产亚洲av麻豆图片| 久久99精品久久久久久水蜜桃| 99久久精品国产一区二区三区| 久久久久免费精品国产| 久久久久久久综合日本亚洲| 久久精品一区二区|