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

TStringGrid之selTxt

尚未結案
jason_cyl329
高階會員


發表:123
回覆:155
積分:105
註冊:2003-05-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-06-03 15:59:30 IP:61.218.xxx.xxx 未訂閱
請問, 有沒有辦法可以知道在TStringGrid中的某一cells中得到圈選的資訊, 就像是TEdit中的SelLength,SelStart,SelText?
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-06-03 22:32:03 IP:218.16.xxx.xxx 未訂閱
Delphi 是這樣的 :
Type
  TSG = Class(TStringGrid);    procedure TForm1.Button2Click(Sender: TObject);
begin
  StringGrid1.Options := StringGrid1.Options   [goAlwaysShowEditor];
  if StringGrid1.EditorMode then
  begin
    ShowMessage(IntToStr(TSG(StringGrid1).InplaceEditor.SelStart));
    ShowMessage(IntToStr(TSG(StringGrid1).InplaceEditor.SelLength));
    ShowMessage(TSG(StringGrid1).InplaceEditor.SelText);
  end;
end;    BCB 我不會試試翻若錯了請指正 :    .h file :
class TSG :: TStringGrid
{
};    .cpp file :
void __fastcall TForm1::Button2Click(Sender: TObject)
{
  StringGrid1->Options = StringGrid1->Options   [goAlwaysShowEditor];
  if (StringGrid1->EditorMode) 
  {
    ShowMessage(IntToStr(((TSG*)StringGrid1)->InplaceEditor->SelStart));
    ShowMessage(IntToStr(((TSG*)StringGrid1)->InplaceEditor->SelLength));
    ShowMessage(((TSG*)StringGrid1)->InplaceEditor->SelText);
  };
};
發表人 - Justmade 於 2003/06/03 22:35:57
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-06-03 23:32:33 IP:61.224.xxx.xxx 未訂閱
BCB 無法像 Delphi 那樣自由,可以直接存取別的物件的父類別的 protected 屬性。InplaceEditor 是 TCustomGrid 的 protected 屬性,在 BCB 中可以使用如下的方式變成公開的屬性:(直接改 Justmade 提供的 code)
    .h file :
class TSG : public TStringGrid
{
__published:
  __property InplaceEditor ;
};    .cpp file :
void __fastcall TForm1::Button2Click(Sender: TObject)
{
  StringGrid1->Options = StringGrid1->Options << goAlwaysShowEditor;
  if (StringGrid1->EditorMode) 
  {
    ShowMessage(IntToStr(((TSG*)StringGrid1)->InplaceEditor->SelStart));
    ShowMessage(IntToStr(((TSG*)StringGrid1)->InplaceEditor->SelLength));
    ShowMessage(((TSG*)StringGrid1)->InplaceEditor->SelText);
  };
};
我試了一下,如果 StringGrid1 沒有任何內容,沒有先編輯一下的話,在第一次按下按鈕執行上述的 code 時會發生 Exception,但只要 StringGrid1 編輯過,則不會再有任何 Exception。 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
Justmade
版主


發表:94
回覆:1934
積分:2030
註冊:2003-03-12

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-06-04 00:06:25 IP:218.16.xxx.xxx 未訂閱
謝謝 dllee 版主的更正 小弟 >
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-06-04 09:28:59 IP:61.224.xxx.xxx 未訂閱
引言: 謝謝 dllee 版主的更正 小弟 > < face="Verdana, Arial, Helvetica"> 別這麼說,如果您手邊有 BCB 的話,應該也是可以很快就可以 try 出來,因為您的 code 已經接近完整了,而我也才改兩點就 OK 了。 也要感謝您提醒有 InplaceEditor 可用 < > 剛看到這個問題,我查一下 > 沒想到在其父類別內有記錄的東西,到後代竟然不給人看了 < > 還是 > 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
jason_cyl329
高階會員


發表:123
回覆:155
積分:105
註冊:2003-05-26

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-06-09 11:28:25 IP:61.218.xxx.xxx 未訂閱
感謝各位前輩的鼎力相助,因為是dllle版主的code完全可用, 所以分數只好給他了,不過還是再次謝謝各位的討論,再請問一下, 是不是有關物件中protect的屬性或是方法都可用上述的方式來開放?
dllee
站務副站長


發表:321
回覆:2519
積分:1711
註冊:2002-04-15

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-06-09 15:30:31 IP:61.231.xxx.xxx 未訂閱
引言: 感謝各位前輩的鼎力相助,因為是dllle版主的code完全可用, 所以分數只好給他了,不過還是再次謝謝各位的討論,再請問一下, 是不是有關物件中protect的屬性或是方法都可用上述的方式來開放?
是的,不過,並不一定就可以用!因為有些屬性會透過一些 Method 來完成,如果父類別沒有實作,子類別也沒有實作,那開放出來也沒有用。 沒空更新的網頁... http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell....
------
http://www.ViewMove.com
系統時間:2024-04-29 18:56:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!