我的Java方面博客

天下难事必做于易,天下大事必做于细

常用链接

统计

最新评论

2007年9月3日 #

重构-保护

     摘要: 重构前的代码,使用字符串处理状态 package org.zsk.refact; public class SystemPermission {     private String state;     private boolean&...  阅读全文

posted @ 2007-09-14 13:17 张树坤 阅读(185) | 评论 (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 张树坤 阅读(523) | 评论 (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 张树坤 阅读(983) | 评论 (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 张树坤 阅读(1476) | 评论 (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 张树坤 阅读(230) | 评论 (0)编辑 收藏