HP\李良庭
2025-07-08 868daf94f29ce1ffdd799a68c07bb668cd373bcd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
unit uInput;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, sBitBtn, sEdit, ShellAPI;
 
type
  TfrmInput = class(TForm)
    edtInput: TsEdit;
    edtReturn: TsBitBtn;
    lbGrain: TLabel;
    cbGrain: TComboBox;
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure edtReturnClick(Sender: TObject);
    procedure cbGrainChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    strParam : String;
    thMode   : Integer;   //0-ĬÈÏÊäÈë¿ò£¬1-Á¸ÖÖ´óÀàÑ¡Ôñ¿ò
    procedure InsertStringAtCursor(EditControl: TsEdit; Str: string);
    procedure DeleteCharsBeforeCursor(EditControl: TsEdit; Count: Integer=1);
    procedure InitGrainRec();
  end;
 
var
  frmInput: TfrmInput;
 
implementation
 
uses
  uMain, global, uSaveData;
 
{$R *.dfm}
 
//------- ×Ô¶¨Ò幦Äܺ¯Êý -------------------------------------------------------
//´Ó¹â±ê´¦²åÈë×Ö·û
procedure TfrmInput.InsertStringAtCursor(EditControl: TsEdit; Str: string);
begin
  // ±£´æµ±Ç°¹â±êλÖÃ
  EditControl.SelStart := EditControl.SelStart;
  EditControl.SelLength := 0; // ²»Ñ¡ÔñÈκÎÎı¾£¬È·±£Ö»²åÈë¶ø²»Ìæ»»
  EditControl.SelText := Str; // ²åÈë×Ö·û´®
end;
 
//×Ô¶¨Ò庯Êý£º´Ó¹â±ê´¦É¾³ý×Ö·û
procedure TfrmInput.DeleteCharsBeforeCursor(EditControl: TsEdit; Count: Integer=1);
var
  CursorPos, NewStart: Integer;
begin
  CursorPos := EditControl.SelStart;
  if CursorPos >= Count then
  begin
    NewStart := CursorPos - Count; // ¼ÆËãеÄÑ¡ÔñÆðµã
    EditControl.SelStart := NewStart;
    EditControl.SelLength := Count; // Ñ¡ÔñCount¸ö×Ö·û
    EditControl.SelText := '';      // É¾³ýÑ¡¶¨µÄÎı¾
  end
  else
  begin
    // Èç¹ûCount´óÓÚ¹â±êλÖã¬Ôòɾ³ýËùÓÐÔÚ¹â±ê֮ǰµÄ×Ö·û
    EditControl.SelStart := 0;
    EditControl.SelLength := CursorPos;
    EditControl.SelText := '';
  end;
end;
 
//------- ³õʼ»¯ ---------------------------------------------------------------
procedure TfrmInput.FormShow(Sender: TObject);
begin
  //É趨ÊäÈë¿òģʽ£¬0-ĬÈÏÊäÈë¿ò£¬1-Á¸ÖÖ´óÀàÑ¡Ôñ¿ò
  if thMode=0 then begin
    self.Width := 510;
    self.Height:= 120;
    lbGrain.Visible := false;
    cbGrain.Visible := false;
  end
  else begin
    self.Width := 510;
    self.Height:= 200;
    lbGrain.Visible := true;
    cbGrain.Visible := true;
  end;
  //´«Èë×Ö·û´®
  edtInput.Text := strParam;
  //³õʼ»¯Á¸ÖÖ´óÀàÏÂÀ­¿ò
  queryGrainTypeSql(t_Grain, 1, cbGrain);
  cbGrain.Style := csDropDownList;
  cbGrain.ItemIndex := Grain.Code-1;
end;
 
procedure TfrmInput.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
  frmInput := nil;
end;
 
//×Ô¶¨Ò庯Êý£º³õʼ»¯Á¸ÖÖrec
procedure TfrmInput.InitGrainRec();
begin
  GrainType_rec.Code := 0;
  GrainType_rec.No   := '';
  GrainType_rec.Name := '';
  GrainType_rec.Coef[0] := '';
  GrainType_rec.Coef[1] := '';
  GrainType_rec.Coef[2] := '';
  GrainType_rec.Coef[3] := '';
  GrainType_rec.Coef[4] := '';
end;
 
procedure TfrmInput.edtReturnClick(Sender: TObject);
begin
  //¸ù¾ÝÁ¸ÖÖ´óÀànam²é´óÀàÐÅÏ¢
  GrainType_rec := queryGrainSql(t_grain, cbGrain.Items[cbGrain.ItemIndex]);
  //½«½á¹û¸üе½È«¾Ö±äÁ¿
  glInput := edtInput.Text;
  //´ò¿ª´¥¿Ø°å
  ShellExecute(0, nil, 'OpenTabTip.exe', 'close', nil, SW_SHOWNORMAL);
  //Í˳ö
  Close();
end;
 
procedure TfrmInput.cbGrainChange(Sender: TObject);
begin
  if cbGrain.ItemIndex <> -1 then
    edtInput.SetFocus;
end;
 
end.