本人刚学习delphi 语言编写程序.
想做一个数据库记录查询修改程序.
我用query组件将查询到的 信息对应到 edit 和 combobox 组件中.
当作修改时用相应的sql 语句修改,当处于查询状态时候将 edit.readonly=true.
请问如何设置combobox 的只读属性呀,比如 combobox中为性别项目(男,女).
请给出解决类似性别项目选择(只读,非只读转换方法选择的思路).
请高手帮忙!!不胜感激.!!!

解决方案 »

  1.   

    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
    if 查询状态 then
     key:=#0;
    end;
      

  2.   

    if 查询状态 then
       combobox.enabled;=false;
      

  3.   

    我以前最常用的就是combobox.style:=csDropDownList,改属性多么方便的事情。
      

  4.   

    combobox也是有样式的,即style!
      

  5.   

    这个问题我也知道,呵呵
    csDropDownList
      

  6.   

    如果你非要一个只读的话,你最好自己扩展一下ComboBox的功能。
    添加一个ReadOnly属性,并自己写其read 和write函数就OK了。
    要不给你写一个简单的控件。
      

  7.   

    combobox.style:=csDropDownList;
    combobox.enabled;=false;
      

  8.   

    unit xComboBox;{*******************************************************************************
                      功能:扩展ComboBox控件的功能,添加一个Only属性                  设计者: 谌壮初                  技术支持:[email protected]                  创建时间:2005-2-2*******************************************************************************}interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TxComboBox = class(TComboBox)
      private
        { Private declarations }
        FReadOnly :Boolean;
        procedure SetFReadOnly(value:Boolean);
        function  GetFReadOnly:Boolean;    
      protected
        { Protected declarations }
        procedure KeyPress(var Key: Char);override;
        procedure KeyDown(var Key: Word; Shift: TShiftState);override;  public
        { Public declarations }
         constructor Create(AOwner:TComponent);override;
         destructor  Destroy; override;
      published
        { Published declarations }
        property ReadOnly :Boolean read GetFReadOnly write SetFReadOnly;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Extend UI ', [TxComboBox]);
    end;procedure TxComboBox.SetFReadOnly(value:Boolean);
    begin
      FReadOnly := value;
    end;function TxComboBox.GetFReadOnly:Boolean;
    begin
      Result := FReadOnly ;
    end;constructor TxComboBox.Create(AOwner: TComponent);
    begin
       inherited Create(AOwner);
    end;destructor  TxComboBox.Destroy;
    begin
      inherited Destroy;
    end;procedure TxComboBox.KeyPress(var Key: Char);
    begin
      if GetFReadOnly
      then Key :=#0
      else inherited;
    end;procedure TxComboBox.KeyDown(var Key: Word; Shift: TShiftState);
    begin
      if GetFReadOnly
      then Key :=0
      else inherited;
    end;end.以上代码完全正确
      

  9.   

    设置 Field 的只读就可以了query.FieldByName('性别').ReadOnly := True
      

  10.   

    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
    if 查询状态 then
     key:=#0;
    end;当是需求状态的时候就把按键值为空
    我一向都是这样做的呵呵,要不就象上面说的procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
    if 查询状态 then
     key:=#0;
    end;
    procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
    begin
    if 查询状态 then
     combobox.style:=csDropDownList;
    end;
      

  11.   

    to Blakhawk(黑鹰船长) 你这是脱裤子放屁----多此一举
    一楼 和二楼的兄弟方法都很好,你别吓卖弄风骚,人家楼主只不过刚接触delphi你装个屁啊?????????