想把表中的一列所有字段都读到COMBOBOX里面去,用函数实现出错!帮忙急!(100分)

private
{ Private declarations }
Procedure FillFieldToCombox(AdoTable : TADOTable;FieldName : String;Combobox :TComBoBox);
public
或者放在这里
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

Procedure TForm1.FillFieldToCombox(AdoTable : TADOTable;FieldName : String;Combobox :TComBoBox);
var
bTemp1,bTemp2 : Boolean ;
Tmpstr : String ;
Begin
....
end;
 
放一个dbgrid,然后增加所有字段,然后再做一个循环,再增加到combobox中。
 
刚刚回到家里,肚子饿死吃了两块饼干,路上想起了一个地方总有疑问,现在调试好了!
哈哈!
单元文件代码如下:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;

type
TForm1 = class(TForm)
ComboBox1: TComboBox;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
Button1: TButton;
ADOTable1EngineerID: TStringField;
ADOTable1EngineerName: TStringField;
ADOTable1EngineerPost: TStringField;
Edit1: TEdit;
Procedure FillFieldToCombox(AdoTable : TADOTable;FieldName : String;Combobox :TComBoBox);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public


{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

Procedure TForm1.FillFieldToCombox(AdoTable : TADOTable;FieldName : String;Combobox :TComBoBox);
var
bTemp1,bTemp2 : Boolean ;
Tmpstr : String ;
Begin
bTemp1 := AdoTable.Active ;
bTemp2 := AdoTable.Filtered ;
if not bTemp1 Then
AdoTable.Open ;
if bTemp2 Then
AdoTable.Filtered := False ;
combobox.Items.Clear ;
Adotable.First ;
While Not AdoTable.Eof Do
Begin
[blue]//原来的代码tmpstr := AdoTable.FieldByName(FieldName).AsString ;[/blue]
[red]//现在的正确代码如下 [/red]
[purple] tmpstr:=AdoTable.FieldByName(FieldName).Value;[/purple]
if Combobox.Items.IndexOf(tmpstr)<0 Then
Combobox.Items.Add(tmpstr);
AdoTable.Next ;
End;
AdoTable.Active := bTemp1 ;
AdoTable.Filtered := bTemp2 ;
End;


procedure TForm1.Button1Click(Sender: TObject);
begin
fillfieldtocombox(adotable1,'EngineerName',combobox1);
end;


end.

是字段的value属性,哈哈!原因就在这里。
最后是fillfieldtocombox(adotable1,'EngineerName',combobox1);调用这个过程。
 
谢谢cwmdelpher,你的帮助对我用处很大。3Q
 
顶部