我的Java方面博客

          天下難事必做于易,天下大事必做于細

          常用鏈接

          統計

          最新評論

          2007年9月3日 #

          重構-保護

               摘要: 重構前的代碼,使用字符串處理狀態 package org.zsk.refact; public class SystemPermission {     private String state;     private boolean&...  閱讀全文

          posted @ 2007-09-14 13:17 張樹坤 閱讀(205) | 評論 (0)編輯 收藏

          函數指針 方法指針

          unit Unit1;

          interface

          uses
            Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
            Dialogs, StdCtrls;

          type
            TEvent 
          = procedure () of object;
            TProc 
          = procedure();

            TForm1 
          = class(TForm)
              btn1: TButton;
              procedure btn1Click(Sender: TObject);
            
          private
              
          { Private declarations }
            
          public
              
          { Public declarations }
            end;

          var
            Form1: TForm1;

          implementation

          {$R *.dfm}

          procedure TForm1.btn1Click(Sender: TObject);
          begin
            showmessage(
          '方法指針的長度是:'+Inttostr(SizeOf(TEvent)));
            showmessage(
          '函數指針的長度是:'+Inttostr(SizeOf(TProc)));
          end;

          //函數指針是指向函數的32位指針,占4個字節。
          //過程的指針結構如下
          //  PProc = ^TProc;//過程指針
          // TProc = record
          //  Code: Pointer;//指向過程的代碼
          // end;
          //方法指針是指向一個結構。方法的指針結構如下
          //  PMethod = ^TMethod;//方法指針
          // TMethod = record
          //  Code: Pointer;//指向方法的代碼
          //    Data: Pointer;//指向對象的數據
          // end;



          end.

          posted @ 2007-09-03 16:08 張樹坤 閱讀(536) | 評論 (0)編輯 收藏

          模擬鍵盤輸入

            SetForegroundWindow(HApp);
            keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 
          0), 00);
            keybd_event(ORD(
          'B'), MapVirtualKey(Byte('t'), 0), 00);
            keybd_event(Byte(
          'B'), MapVirtualKey(Byte('t'), 0), KEYEVENTF_KEYUP, 0);
            keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 
          0), KEYEVENTF_KEYUP, 0);


          //Ctrl: VK_CONTROL
          //SHIFT:VK_SHIFT
          //TAB:  VK_TAB
          //ALT:  VK_MENU
          //'A':  byte('A')

          功能說明,
          通過目標程序的句柄將該程序激活;
          模擬鼠標按下
          模擬鼠標抬起

          posted @ 2007-09-03 16:03 張樹坤 閱讀(998) | 評論 (0)編輯 收藏

          PostMessage和SendMessage區別

          PostMessage 只是把消息放入隊列,不管其他程序是否處理都返回,然后繼續執行 ;
          SendMessage 必須等待其他程序處理消息后才返回,繼續執行。
          PostMessage
          的返回值表示 PostMessage 函數執行是否正確 ;
          SendMessage 的返回值表示其他程序處理消息后的返回值。
          使用這兩個發送消息函數的最重要的是要看你的程序是否要對消息的滯后性關注否 ,PostMessage 會造成消息的滯后性 , SendMessage 則不會 , 但如果 SendMessage 消息處理失敗 , 則會造成程序停止 !

          為了讓大家能清楚的看到他們的效果,可以用下面的代碼進行測試:
          unit Unit1;

          interface

          uses
            Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
            Dialogs, StdCtrls;

          type
            TForm1 
          = class(TForm)
              mmo1: TMemo;
              btn2: TButton;
              btn3: TButton;
              procedure btn2Click(Sender: TObject);
              procedure btn3Click(Sender: TObject);
            
          private
              
          { Private declarations }
              procedure testPostMessage;
              procedure testSendMessage;
            
          public
              
          { Public declarations }
            end;

          var
            Form1: TForm1;

          implementation

          uses uFile;

          {$R *.dfm}
          var
            f: TFile;

          procedure TForm1.btn2Click(Sender: TObject);
          var
            i: Integer;
          begin
            testPostMessage;
            
          for i := 0 to 5000 do
            begin
              mmo1.Lines.Add(IntToStr(i)
          +'======');
            end;
          end;

          procedure TForm1.btn3Click(Sender: TObject);
          var
            i: Integer;
          begin
            testSendMessage;
            
          for i := 0 to 5000 do
            begin
              mmo1.Lines.Add(IntToStr(i)
          +'======');
            end;
          end;

          procedure TForm1.testPostMessage;
          var
            i: Integer;
          begin
            PostMessage(f.Handle, WM_TEST, 
          00);
            
          for i := 0 to 5000 do
            begin
              mmo1.Lines.Add(IntToStr(i))
            end;
          end;

          procedure TForm1.testSendMessage;
          var
            i: Integer;
          begin
            SendMessage(f.Handle, WM_TEST, 
          00);
            
          for i := 0 to 5000 do
            begin
              mmo1.Lines.Add(IntToStr(i))
            end;
          end;

          initialization
            
          if f = nil then
              f :
          = TFile.Create;

          finalization
            
          if f <> nil then
              FreeAndNil(f);;

          end.


          unit uFile;

          interface

          uses
            Classes, Windows, Forms, Messages;

          const
            WM_TEST 
          = WM_USER + 1;

          type
            TFile 
          = class
            
          private
              FHandle: HWND;
            
          protected
              procedure WndProc(var Msg: TMessage);
            
          public
              procedure AfterConstruction; override;
              procedure BeforeDestruction; override;
              property Handle: HWND  read FHandle;
            end;

          implementation

          { TFile }

          procedure TFile.AfterConstruction;
          begin
            inherited;
            FHandle :
          = AllocateHWnd(WndProc);
          end;

          procedure TFile.BeforeDestruction;
          begin
            inherited;
            DeallocateHWnd(FHandle);
          end;

          procedure TFile.WndProc(var Msg: TMessage);
          begin
            
          if msg.Msg = WM_TEST then
            begin
              
          //消息處理內容
              Application.MessageBox('WM_TEST''WM_TEST'0);
            end;  
            windows.DefWindowProc(FHandle, Msg.Msg, Msg.wParam, Msg.lParam);
          end;

          end.

          posted @ 2007-09-03 14:28 張樹坤 閱讀(1490) | 評論 (0)編輯 收藏

          java中的類之類 java.lang.reflect

               不知道java.lang.reflect實現的功能算不算是java中的類之類,
          我暫時是按這個理解的,
          package org.zsk.reflect;

          import java.lang.reflect.*;

          public class TestReflect {
              
          public static void main(String args[]) {
                     
          try {
                         Class c 
          = Class.forName("java.util.Stack");
                         Method m[] 
          = c.getDeclaredMethods();
                         
          for (int i = 0; i < m.length; i++)
                             System.out.println(m[i].toString());
                     }
           catch (Throwable e) {
                         System.err.println(e);
                     }

                 }

          }
          上面代碼能夠使用“java.util.Stack”找到類

          看看Delphi的類之類
          type

            TObject 
          = class;

            TClass 
          = class of TObject;
          TObject是一個類
          TClass是這個TObject類的類,
          如果我們要做個管理類的話,可以用個List實現一個name和一個類之類的對應的map
          我們就可以根據這個name,就是一個字符串,找到、創建、使用、釋放這類的對象。

          java中的類方法
          public static XXX
          delphi中的類方法
          class procedure XXX

          posted @ 2007-09-03 13:09 張樹坤 閱讀(243) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 长海县| 沙坪坝区| 东源县| 收藏| 红河县| 安远县| 伊吾县| 邓州市| 青铜峡市| 凤台县| 钦州市| 台东县| 霍林郭勒市| 中西区| 抚顺市| 安新县| 竹北市| 镇巴县| 攀枝花市| 增城市| 禹城市| 瑞昌市| 呼和浩特市| 普洱| 博白县| 林口县| 合阳县| 东乡县| 塘沽区| 桃源县| 平顺县| 沅陵县| 青龙| 哈尔滨市| 大姚县| 西城区| 清水河县| 合江县| 仁布县| 吉木乃县| 四子王旗|