• <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, 評(píng)論 - 4, 引用 - 0
            數(shù)據(jù)加載中……

            小觀構(gòu)件

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

            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和外部實(shí)現(xiàn)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; 
            //這就是個(gè)函數(shù)接口
              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()
            {
              
            //這句執(zhí)行時(shí)都是外部來(lái)調(diào)用的,此時(shí)OnMultiple已經(jīng)和外面那個(gè)函數(shù)接口連接上了
              
            //也就是調(diào)用的其實(shí)是外面進(jìn)來(lái)的那個(gè)函數(shù),把this傳出去,讓外部那個(gè)函數(shù)操作
              
            //TExample::MultipleReached(this)
              if (((++FVal) % FMultiple) == 0)
                  OnMultiple(
            this);
            }
            //-------------------------------------------------------------------------

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


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            久久精品国产亚洲精品| 99久久精品免费看国产一区二区三区 | 亚洲精品蜜桃久久久久久| 亚洲精品白浆高清久久久久久| 日韩精品久久无码人妻中文字幕| 久久亚洲精品成人AV| 久久91综合国产91久久精品| 精品久久久久久久久久久久久久久| 精品99久久aaa一级毛片| 久久伊人精品一区二区三区| 日韩精品久久久久久久电影蜜臀| 久久不射电影网| 国产精品中文久久久久久久| www久久久天天com| 亚洲日韩欧美一区久久久久我| 久久久久AV综合网成人| 久久久久亚洲av毛片大| 久久亚洲欧美国产精品| 久久久青草青青国产亚洲免观| 伊人色综合久久天天人手人婷| 精品熟女少妇aⅴ免费久久| 97久久久精品综合88久久| 人妻无码精品久久亚瑟影视| 99999久久久久久亚洲| 亚洲va久久久噜噜噜久久狠狠 | 久久久久九九精品影院| 无码国内精品久久人妻麻豆按摩| 青青热久久国产久精品| 久久久久久精品无码人妻| 精品久久人妻av中文字幕| 精品多毛少妇人妻AV免费久久| 久久夜色精品国产噜噜亚洲a| 久久99这里只有精品国产| 中文字幕久久精品无码| 99久久er这里只有精品18| 精品久久久久中文字| 久久久久久亚洲精品成人| 久久综合九色综合久99| 久久精品国产亚洲综合色| 国产毛片欧美毛片久久久| 色8激情欧美成人久久综合电|