现在因为多个窗体界面都要用到,所以想放到一个公共单元,各个窗体可以调用。这样的话在公共单元怎么写?各个窗体又如何调用呢?
procedure ShowComboBox(MODE:integer);
begin
combobox1.Items.Clear;
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select mc from unit where mod=:mode');
parameters.ParamByName('mode').Value:=mode;
Open;
while not Eof do
begin
combobox1.Items.Add(FieldByName('mc').AsString);
Next;
end;
end;
end;
2 个解决方案
#1
公用函数
procedure ShowComboBox(combobox: Tcombobox1; MODE:integer);
begin
combobox.Items.Clear;
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select mc from unit where mod=:mode');
parameters.ParamByName('mode').Value:=mode;
Open;
while not Eof do
begin
combobox.Items.Add(FieldByName('mc').AsString);
Next;
end;
end;
end;
调用
ShowComboBox(combobox1, 0);
procedure ShowComboBox(combobox: Tcombobox1; MODE:integer);
begin
combobox.Items.Clear;
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select mc from unit where mod=:mode');
parameters.ParamByName('mode').Value:=mode;
Open;
while not Eof do
begin
combobox.Items.Add(FieldByName('mc').AsString);
Next;
end;
end;
end;
调用
ShowComboBox(combobox1, 0);
#2
因为Combobox的items的值,并非公共的,是随需变化的,就不适应公共的了。这就需要在各自的单元中,分别设置Combobox,可在Onsho设置items。
#1
公用函数
procedure ShowComboBox(combobox: Tcombobox1; MODE:integer);
begin
combobox.Items.Clear;
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select mc from unit where mod=:mode');
parameters.ParamByName('mode').Value:=mode;
Open;
while not Eof do
begin
combobox.Items.Add(FieldByName('mc').AsString);
Next;
end;
end;
end;
调用
ShowComboBox(combobox1, 0);
procedure ShowComboBox(combobox: Tcombobox1; MODE:integer);
begin
combobox.Items.Clear;
with ADOQuery1 do
begin
close;
SQL.Clear;
SQL.Add('select mc from unit where mod=:mode');
parameters.ParamByName('mode').Value:=mode;
Open;
while not Eof do
begin
combobox.Items.Add(FieldByName('mc').AsString);
Next;
end;
end;
end;
调用
ShowComboBox(combobox1, 0);
#2
因为Combobox的items的值,并非公共的,是随需变化的,就不适应公共的了。这就需要在各自的单元中,分别设置Combobox,可在Onsho设置items。