2009-09-21 13 views

回答

1

嗯,我不明白爲什麼它是禁止在德爾福行動,但我已經設法在ComponentStyle中創建我自己的查找組合框組件csReplicatable標誌,它的工作原理!

它沒有經過徹底測試,但在我的應用程序它沒有問題。

Here is the source,看看吧。

-2

我剛剛加了一個TDBLookupComboTDBCtrlGrid。當我試圖設置ListSource,我得到了錯誤:

Operation not allowed in a DBCtrlGrid.

因此看來,這是明確禁止的德爾福,所以你將不能夠做到這一點。

0

對於修改/維護修改的VCL/RTL代碼非常沉默,我找到了另一種方法。聲明在單元的接口如下:

interface 

uses 
    ... 
    ; 

type Tdbp = class(TDBCtrlGrid); 
type tdbl = class(TDBLookupControl); 

type 
    TForm4 = class(TForm) 
    ... 
    DBCtrlGrid1: TDBCtrlGrid; 
    ... 
    private 
    ... 
    function FindLCB(DataFieldName: String): TDBLookupComboBox; 
    procedure FixDBLookupDataLinks; 
    public 
    ... 
    end; 



...and in your implementation: 


---------- 


implementation 

procedure TForm4.FormCreate(Sender: TObject); 
begin 
    ... 
    DBCtrlGrid1.DataSource := DataSource1; 
    FixDBLookupDataLinks; 
end; 

procedure TForm4.FixDBLookupDataLinks; 
var 
    lcb: TDBLookupComboBox; 
    I,n: Integer; 
    MyDataLink: TDataLink; 
    ctl: TControl; 
    dbp: Tdbctrlpanel; 
begin 
    dbp := Tdbp(DBControlGrid1).Panel; 
    for n := 0 to Pred(dbp.ControlCount) do 
    begin 
    ctl := dbp.Controls[n]; 
    if ctl.ClassType = TDBLookupComboBox then 
    begin 
     lcb := TDBLookupComboBox(ctl); 
     lcb.ControlStyle := lcb.ControlStyle + [csReplicatable]; 
     TDBL(lcb).ListLink.DataSourceFixed := False; 
     for I := 0 to Pred(lcb.ControlCount) do 
     begin 
     if lcb.Controls[I] is TPopupDataList then 
     begin 
      TDBL(lcb).ListLink.DataSourceFixed := False; 
      TDBL(lcb).DataLink.DataSourceFixed := False; 
      MyDataLink := TDataLink(lcb.Controls[I].Perform(CM_GETDATALINK, 0, 0)); 
      if MyDataLink <> nil then 
      MyDataLink.DataSourceFixed := False; 
      MyDataLink.DataSource := nil; 
     end; 
     end; 
    end; 
    end; 
end; 

function TForm4.FindLCB(DataFieldName: String): TDBLookupComboBox; 
var 
    i: Integer; 
begin 
    Result := Nil; 
    for i := 0 to Pred(ControlCount) do 
    if Controls[i].ClassType = TDBLookupComboBox then 
     if TDBLookupComboBox(Controls[i]).DataField = DataFieldName then 
     begin 
     Result := TDBLookupComboBox(Controls[i]); 
     Break; 
     end; 
end; 
+0

你能否認罪e豐富您的答案,並在信息來源中添加一些關於您的解決方法或一些評論的解釋。如果它適合任何個人使用情況,將更容易實現。謝謝! – bluish

0

我發現Embarcadero Developer Network此變通辦法:

I figured out how to work around the issue. Here is a sample. It assumes that the combobox is placed on the grid at design-time, not runtime. So at the moment the event handler is executing, the controls have been streamed successfully from the DFM and links already established. Though one should test in a real project.

procedure TForm1.FormCreate(Sender: TObject); 
var 
    I: Integer; 
    MyDataLink: TDataLink; 
begin 
    for I := 0 to DBLookupComboBox1.ControlCount - 1 do 
    if DBLookupComboBox1.Controls[I] is TPopupDataList then 
    begin 
     MyDataLink := TDataLink(DBLookupComboBox1.Controls[I].Perform(CM_GETDATALINK, 0, 0)); 
     if MyDataLink <> nil then begin 
     MyDataLink.DataSourceFixed := False; 
     MyDataLink.DataSource := nil; 
     end; 
    end; 
end; 

Andrei Fomine.


如果您在TDBGrid有多個TDBLookupComboBox,您可以使用此代碼段:

procedure TForm1.FormCreate(Sender: TObject); 
var 
    I, C: Integer; 
    curCombo: TDBLookupComboBox; curDL: TDataLink; 
begin 
    for C := 0 to ComponentCount - 1 do begin 
    if Components[C] is TDBLookupComboBox then begin 
     curCombo:= (Components[C] as TDBLookupComboBox); 

     for I := 0 to curCombo.ControlCount - 1 do 
     if curCombo.Controls[I] is TPopupDataList then 
     begin 
      curDL := TDataLink(curCombo.Controls[I].Perform(CM_GETDATALINK, 0, 0)); 
      if curDL <> nil then begin 
      curDL.DataSourceFixed := False; 
      curDL.DataSource := nil; 
      end; 
     end; 
    end; 
    end; 
end;