unit U_EmployeeSel; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Buttons, DB, ADODB, U_BaseHelp, System.ImageList, Vcl.ImgList; type TfrmEmployeeSel = class(TfrmBaseHelp) ScrollBox1: TScrollBox; btn1: TSpeedButton; btn2: TSpeedButton; btn3: TSpeedButton; btn4: TSpeedButton; btn5: TSpeedButton; btn6: TSpeedButton; btn7: TSpeedButton; btn8: TSpeedButton; btn58: TSpeedButton; btn9: TSpeedButton; btn10: TSpeedButton; btn11: TSpeedButton; btn12: TSpeedButton; btn13: TSpeedButton; btn14: TSpeedButton; btn15: TSpeedButton; btn59: TSpeedButton; btn16: TSpeedButton; btn17: TSpeedButton; btn18: TSpeedButton; btn19: TSpeedButton; btn20: TSpeedButton; btn21: TSpeedButton; btn22: TSpeedButton; btn60: TSpeedButton; btn23: TSpeedButton; btn24: TSpeedButton; btn25: TSpeedButton; btn26: TSpeedButton; btn27: TSpeedButton; btn28: TSpeedButton; btn29: TSpeedButton; btn61: TSpeedButton; btn30: TSpeedButton; btn31: TSpeedButton; btn32: TSpeedButton; btn33: TSpeedButton; btn34: TSpeedButton; btn35: TSpeedButton; btn36: TSpeedButton; btn62: TSpeedButton; btn37: TSpeedButton; btn38: TSpeedButton; btn39: TSpeedButton; btn40: TSpeedButton; btn41: TSpeedButton; btn42: TSpeedButton; btn43: TSpeedButton; btn63: TSpeedButton; btn44: TSpeedButton; btn45: TSpeedButton; btn46: TSpeedButton; btn47: TSpeedButton; btn48: TSpeedButton; btn49: TSpeedButton; btn50: TSpeedButton; btn64: TSpeedButton; btn51: TSpeedButton; btn52: TSpeedButton; btn53: TSpeedButton; btn54: TSpeedButton; btn55: TSpeedButton; btn56: TSpeedButton; btn57: TSpeedButton; ADOTmp: TADOQuery; ADOConnection1: TADOConnection; procedure FormDestroy(Sender: TObject); procedure FormShow(Sender: TObject); procedure btn1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); private procedure InitEmployee(); { Private declarations } public FRCode, FRName, FPost: string; { Public declarations } end; var frmEmployeeSel: TfrmEmployeeSel; implementation uses U_DataLink; {$R *.dfm} procedure TfrmEmployeeSel.FormDestroy(Sender: TObject); begin inherited; frmEmployeeSel := nil; end; procedure TfrmEmployeeSel.InitEmployee(); type FdDy = record inc: integer; FCode: string[32]; FName: string[32]; end; var BB: array[0..100] of FdDy; i, j: Integer; begin with ADOTmp do begin Close; sql.Clear; sql.Add('select EECode,EEName from SY_Employee where Post=''' + Trim(FPost) + ''' '); SQL.Add('order by EECode,EEName '); Open; end; if ADOTmp.IsEmpty then begin Application.MessageBox('没有定义数据!', '提示', 0); Exit; end; with ADOTmp do begin First; i := 0; while not Eof do begin BB[i].inc := i; BB[i].FCode := Trim(fieldbyname('EECode').AsString); BB[i].FName := Trim(fieldbyname('EEName').AsString); i := i + 1; Next; end; end; i := i - 1; if i > 63 then begin i := 63; end; for j := 0 to i do begin with ScrollBox1 do begin TSpeedButton(Controls[j]).Visible := True; TSpeedButton(Controls[j]).Hint := BB[j].FCode; TSpeedButton(Controls[j]).Caption := BB[j].FName; {TSpeedButton(Controls[j]).Hint:=BB[j]; if Length(BB[j])>4 then begin TSpeedButton(Controls[j]).Caption:=Copy(Trim(BB[j]),1,4)+#13+Copy(Trim(BB[j]),5,Length(BB[j])-4); end else TSpeedButton(Controls[j]).Caption:=BB[j]; } end; end; end; procedure TfrmEmployeeSel.FormShow(Sender: TObject); begin inherited; InitEmployee(); end; procedure TfrmEmployeeSel.btn1Click(Sender: TObject); begin FRCode := Trim(TSpeedButton(Sender).Hint); FRName := Trim(TSpeedButton(Sender).Caption); ModalResult := 1; end; procedure TfrmEmployeeSel.FormClose(Sender: TObject; var Action: TCloseAction); begin inherited; // Action:=caHide; end; procedure TfrmEmployeeSel.FormCreate(Sender: TObject); begin inherited; try with ADOConnection1 do begin Connected := false; ConnectionString := DConString; Connected := true; end; ADOQueryBaseCmd.Connection := ADOConnection1; ADOQueryBaseTemp.Connection := ADOConnection1; except {if Application.MessageBox('网络连接失败,是否要再次连接?','提示',32+4)=IDYES then begin try with ADOConnection1 do begin Connected:=false; ConnectionString:=DConString; //ConnectionString:='23242'; Connected:=true; end; except end; end; } end; end; end.