首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

delphi代码转BCB 有两个有关问题

2012-03-23 
delphi代码转BCB 有两个问题窗体上拖个stringgrid一个combobox 两个控件 OK功能是实现stringgrid嵌入combo

delphi代码转BCB 有两个问题
窗体上拖个stringgrid 一个combobox 两个控件 OK 功能是实现stringgrid嵌入combobox的 遍观网上资料 这个最合心意
delphi代码如下:

Delphi(Pascal) code
implementation{$R *.dfm}procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,  ARow: Integer; var CanSelect: Boolean);var  R: TRect;  org: TPoint;begin  with Sender as TStringGrid do    if (ACol = 2) and (ARow >= FixedRows) then //在第二列显示一个ComboBox    begin      perform(WM_CANCELMODE, 0, 0);      R := CellRect(ACol, ARow);      org := Self.ScreenToClient(ClientToScreen(R.topleft));   //Self相当于VC里的this指针,是对象自身      with ComboBox1 do      begin        setbounds(org.X, org.Y, R.right - R.left, height);        itemindex := Items.IndexOf(Cells[ACol, ARow]);        Show;        BringTofront;        SetFocus;        DroppedDown := true;      end;    end;end;procedure TForm1.FormCreate(Sender: TObject);begin//  ComboBox1.Visible := False;end;procedure TForm1.ComboBox1Exit(Sender: TObject);begin  with Sender as TComboBox do  begin    hide;    if itemindex >= 0 then      with StringGrid1 do        Cells[col, row] := Items[itemindex];  end;end;end.


BCB代码如下: 自己乱搞的 肯定不合适不合理的地方多多
C/C++ code
void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol, int ARow,          bool &CanSelect){    TRect R;    TPoint org;    if(ACol == 2 && ARow >= StringGrid1->FixedRows )    {        Perform(WM_CANCELMODE,0,0);        R = StringGrid1->CellRect(ACol,ARow);        org = this->ScreenToClient(ClientToScreen(R.。。));  // 这里没有R.topleft 啊   这句怎么写        SetBounds(org.x ,org.y ,R.right - R.left ,Height);        ComboBox1->ItemIndex  = ComboBox1->Items->IndexOf(StringGrid1->Cells[ACol][ARow]);        this->Show() ;        this->BringToFront();        this->SetFocus();        ComboBox1->DroppedDown ;    }}//---------------------------------------void __fastcall TForm1::FormCreate(TObject *Sender){    ComboBox1->Visible = false;}//---------------------------------------void __fastcall TForm1::ComboBox1Exit(TObject *Sender){    ComboBox1->Hide();    if(ComboBox1->ItemIndex >=0)        StringGrid1->Cells [StringGrid1->Col][StringGrid1->Row] = ComboBox1->Items [ComboBox1->ItemIndex];     // 此处提示 Cannot convert 'TStrings' to 'UnicodeString'  怎么修改}


求解决,另外我写的不对的地方您就带手给修正一下吧 谢谢鸟!

[解决办法]
木时间看你的了,我帮你翻译并且已经测试过,木有问题的:
C/C++ code
void __fastcall TForm1::StringGrid1SelectCell(TObject *Sender, int ACol,        int ARow, bool &CanSelect){    TStringGrid *sg = dynamic_cast<TStringGrid *>(Sender);    if (!sg) return;    if (ACol == 2 && ARow >= sg->FixedRows)    {        sg->Perform(WM_CANCELMODE, 0, 0);        TRect R = sg->CellRect(ACol, ARow);        TPoint org = ScreenToClient(sg->ClientToScreen(TPoint(R.Left, R.Top)));        ComboBox1->SetBounds(org.x, org.y, R.right - R.left, ComboBox1->Height);        ComboBox1->ItemIndex = ComboBox1->Items->IndexOf(sg->Cells[ACol][ARow]);        ComboBox1->Show();        ComboBox1->BringToFront();        ComboBox1->SetFocus();        ComboBox1->DroppedDown = true;    }}void __fastcall TForm1::FormCreate(TObject *Sender){    //  ComboBox1->Visible = false;}void __fastcall TForm1::ComboBox1Exit(TObject *Sender){    TComboBox *cbx = dynamic_cast <TComboBox *>(Sender);    if (!cbx) return;    cbx->Hide();    if (cbx->ItemIndex >= 0)        StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] =                cbx->Items->Strings[cbx->ItemIndex];} 

热点排行