delphi代码转BCB 有两个问题
窗体上拖个stringgrid 一个combobox 两个控件 OK 功能是实现stringgrid嵌入combobox的 遍观网上资料 这个最合心意
delphi代码如下:
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.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' 怎么修改}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];}