全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2926
推到 Plurk!
推到 Facebook!

請問 在 DBEdit、Edit、DBGrid 中, 有沒有辦法讓 Insert 鍵的功能正常?

尚未結案
chlo
一般會員


發表:7
回覆:13
積分:4
註冊:2003-04-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-02-28 00:04:22 IP:211.76.xxx.xxx 未訂閱
請問各位先進: 在 DBEdit、Edit、DBGrid 中,有沒有辦法讓 Insert 鍵的功能正常作用? PS: 當我按下 Insert 鍵,卻無法取消 Insert 的功能, 永遠都只能在Insert的狀態下,無法進入Edit的狀態。 發表人 - chlo 於 2004/02/28 00:54:25
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-02-28 00:35:55 IP:61.71.xxx.xxx 未訂閱
引言: 請問各位先進: 在 DBEdit、Edit、DBGrid 中,有沒有辦法讓 Insert 鍵的功能正常作用?
不知道你所謂正常作用指的何意! 系統原本設定功能就是插入
chlo
一般會員


發表:7
回覆:13
積分:4
註冊:2003-04-17

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-02-28 00:49:14 IP:211.76.xxx.xxx 未訂閱
引言:
引言: 請問各位先進: 在 DBEdit、Edit、DBGrid 中,有沒有辦法讓 Insert 鍵的功能正常作用?
不知道你所謂正常作用指的何意! 系統原本設定功能就是插入
P.D.您好: 當我按下 Insert 鍵,卻無法取消 Insert 的功能, 永遠都只能在Insert的狀態下嗎?
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-02-29 02:12:59 IP:61.71.xxx.xxx 未訂閱
引言: P.D.您好: 當我按下 Insert 鍵,卻無法取消 Insert 的功能, 永遠都只能在Insert的狀態下嗎?
應該是有辦法的, 不過平常並沒有去注意這個小地方, 一時找不到說明文件出處, 先請其他網友協助吧!
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-02-29 09:28:39 IP:202.39.xxx.xxx 未訂閱
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  iSelStart: integer;
begin
  iSelStart := Edit1.SelStart;      if Odd(GetKeyState(VK_INSERT)) then
  begin
    if Edit1.SelLength = 0 then
    begin
      case Key of
        ' '..#126, #128..#255:
        begin
          Edit1.SelLength := 1;
          if (Edit1.SelLength > 0) and (Edit1.SelText[1] = #13) then
            Edit1.SelLength := 2;
        end;
      end;
      if IsDBCSLeadByte(Byte(Edit1.Text[iSelStart 1])) then
        Edit1.SelLength := 2;
    end;
  end;
end;
--- 屬於那自己生命的歌 不管是什麼顏色
chlo
一般會員


發表:7
回覆:13
積分:4
註冊:2003-04-17

發送簡訊給我
#6 引用回覆 回覆 發表時間:2004-03-01 00:24:42 IP:211.76.xxx.xxx 未訂閱
引言:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  iSelStart: integer;
begin
  iSelStart := Edit1.SelStart;      if Odd(GetKeyState(VK_INSERT)) then
  begin
    if Edit1.SelLength = 0 then
    begin
      case Key of
        ' '..#126, #128..#255:
        begin
          Edit1.SelLength := 1;
          if (Edit1.SelLength > 0) and (Edit1.SelText[1] = #13) then
            Edit1.SelLength := 2;
        end;
      end;
      if IsDBCSLeadByte(Byte(Edit1.Text[iSelStart 1])) then
        Edit1.SelLength := 2;
    end;
  end;
end;
--- 屬於那自己生命的歌 不管是什麼顏色
感謝 hagar 版主 DBEdit、Edit已解決了,但 DBGrid 還是有問題, 是否能再指點迷津,感恩!!
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#7 引用回覆 回覆 發表時間:2004-03-01 08:11:44 IP:202.39.xxx.xxx 未訂閱
var
  IsInsert: Boolean = True; // 此變數記錄現在是 insert 或 override 狀態    procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
var
  iSelStart: integer;
  c: TInplaceEdit;
  i: integer;
begin
  for i := 0 to DBGrid1.ControlCount -1 do
  begin
    if DBGrid1.Controls[i] is TInplaceEdit then
    begin
      c := TInplaceEdit(DBGrid1.Controls[i]);
      Break;
    end;
  end;      iSelStart := c.SelStart;      if not IsInsert then
  begin
    if c.SelLength = 0 then
    begin
      case Key of
        ' '..#126, #128..#255:
        begin
          c.SelLength := 1;
          if (c.SelLength > 0) and (c.SelText[1] = #13) then
            c.SelLength := 2;
        end;
      end;
      if IsDBCSLeadByte(Byte(c.Text[iSelStart 1])) then
        c.SelLength := 2;
    end;
  end;
end;    procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_INSERT then
  begin
    IsInsert := not IsInsert;
    Key := $00; // 吃掉 Insert 鍵, 因為按下 Insert 鍵會做新增一筆的動作
  end;
end;
--- 屬於那自己生命的歌 不管是什麼顏色
chlo
一般會員


發表:7
回覆:13
積分:4
註冊:2003-04-17

發送簡訊給我
#8 引用回覆 回覆 發表時間:2004-03-01 11:04:00 IP:211.76.xxx.xxx 未訂閱
感謝 hagar 版主 都解決了
系統時間:2024-03-29 15:26:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!