小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

delphi 禁止Tedit,Tcombobox控件復(fù)制、粘貼操作

 獨孤求財 2012-03-20

delphi 禁止Tedit,Tcombobox控件復(fù)制、粘貼操作

時間:2011-5-26來源:yang 作者: peng點擊: 26次

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  Found: boolean;
  i,SelSt,j: Integer;
  TmpStr: string;
begin
      with (Sender as TEdit) do
        begin
          j :=0;
          SelSt :=SelStart;
          if (Key = Chr(vk_Back)) and (SelLength <> 0) then
            TmpStr := Copy(Text,1,SelStart)+Copy(Text,SelLength+SelStart+1,255)
          else if Key = Chr(vk_Back) then {SelLength = 0}
            TmpStr := Copy(Text,1,SelStart-1)+Copy(Text,SelStart+1,255)
          else if Key in [‘0‘..‘9‘] then
            begin
              TmpStr := Copy(Text,1,SelStart)+Key+Copy(Text,SelLength+SelStart+1,255);
              j :=1;
            end
          else  {Key in [‘A‘..‘Z‘, etc]}
            TmpStr := Copy(Text,1,SelStart)+Copy(Text,SelStart+1,255);

          if (Key = Chr(vk_Back)) and (SelSt > 0) then
            Dec(SelSt)
          else if Key <> Chr(vk_Back) then
            Inc(SelSt);
          Key := #0; { indicate that key was handled }
          if SelSt = 0 then
            begin
              Text:= ‘‘;
              Exit;
            end
          else
            begin
              Text :=TmpStr;
              SelStart :=SelSt+j;
            end;
        end;

end;

end.

  {因為ComboBox是個組合控件,所有只替換CombobOx的消息處理過程是沒辦法截獲它的子控件Edit的消息的,針對TComboBox,你可以這樣改:}
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    oldwndproc:TWndMethod;//保存原來的
    procedure EditWndProc(var Message : TMessage);
  end;

var
  Form1: TForm1;
  EditHandle: THandle;
  EditPointer:Pointer;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.EditWndProc(var Message: TMessage);
begin
  case Message.Msg of
      WM_COPY : exit;//做你想做的
      WM_PASTE : exit;
   end;
   Message.Result:=CallWindowProc(EditPointer, EditHandle, Message.Msg, Message.WParam, Message.LParam);
   //oldwndproc(Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
Var P:Pointer;
begin
  EditHandle:=GetWindow(Combobox1.Handle,GW_CHILD);
  if EditHandle<>0 then
  begin
    if ComboBox1.Style=csSimple then EditHandle:=GetWindow(EditHandle, GW_HWNDNEXT);
    EditPointer := Pointer(GetWindowLong(EditHandle, GWL_WNDPROC));
    //
    P := Classes.MakeObjectInstance(EditWndProc);
    SetWindowLong(EditHandle, GWL_WNDPROC, Longint(P));
  end;
//oldwndproc:=combobox1.WindowProc;
//Combobox1.WindowProc := ImageWndProc;
end;

end.
 
*****************************************
用delphi修改 文件屬性

1. 在interface下的uses中引用filectrl單元

2. 首先取文件屬性

    var        
      attr : integer;        
      filename : string;    
    begin        
      filename := ‘myfile‘;        
      attr     := FileGetAttr(filename);    
    end;



3. 設(shè)置文件屬性(如設(shè)置歸檔屬性 -> faArchive )
   
    attr := attr or faArchive;    
    //如要去掉某一屬性,則如下句    
    attr := attr and (not faArchive);    
    //保留其它屬性    
    if FileSetAttr(filename, attr)=0 then        
       //成功代碼    
    else        
       //失敗代碼

4. 附文件屬性常量
    Constant Value Description
    faReadOnly $00000001 Read-only files 只讀文件
    faHidden $00000002 Hidden files 隱藏文件
    faSysFile $00000004 System files 系統(tǒng)文件
    faVolumeID $00000008 Volume ID files 卷標文件
    faDirectory $00000010 Directory files 目錄
    faArchive $00000020 Archive files 歸檔文件
    faAnyFile $0000003F Any file 任意文件  

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多