⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setstringunit.pas

📁 三层的通用架构
💻 PAS
字号:
unit SetStringUnit;

interface

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

type
  TSetStringForm = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Bevel1: TBevel;
    Button1: TButton;
    Button2: TButton;
    ComboBox1: TComboBox;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    CaptionString, LabelString, EditString: string;
    ComboBoxStrings: TStringList;
    OkFlag: Boolean;
  end;

var
  SetStringForm: TSetStringForm;

implementation

{$R *.dfm}

procedure TSetStringForm.FormCreate(Sender: TObject);
begin
  CaptionString := '';
  LabelString := '';
  EditString := '';
  ComboBoxStrings := TStringList.Create;
  OkFlag := False;
end;

procedure TSetStringForm.FormDestroy(Sender: TObject);
begin
  ComboBoxStrings.Free;
end;

procedure TSetStringForm.FormShow(Sender: TObject);
begin
  Caption := CaptionString;
  Label1.Caption := LabelString;
  Edit1.Text := EditString;
  Edit1.Left := Label1.Left + Label1.Width + 8;
  ClientWidth := Edit1.Left + Edit1.Width + Label1.Left;
  if ComboBoxStrings.Count > 0 then
  begin
    ComboBox1.Text := EditString;
    ComboBox1.Left := Label1.Left + Label1.Width + 8;
    ComboBox1.Items.Assign(ComboBoxStrings);
    ComboBox1.Visible := True;
    Edit1.Visible := False;
    Label1.FocusControl := ComboBox1;
  end
  else begin
    ComboBox1.Visible := False;
    Edit1.Visible := True;
    Label1.FocusControl := Edit1;
  end;
  ClientWidth := Edit1.Left + Edit1.Width + Label1.Left;
  Bevel1.Width := ClientWidth - Bevel1.Left * 2;
end;

procedure TSetStringForm.FormResize(Sender: TObject);
begin
  Button1.Left := (ClientWidth - Button1.Width - Button2.Width) div 3;
  Button2.Left := Button1.Left * 2 + Button1.Width;
end;

procedure TSetStringForm.Button1Click(Sender: TObject);
begin
  OkFlag := True;
  EditString := Edit1.Text;
  if ComboBox1.Visible then
    EditString := ComboBox1.Text;
  Close;
end;

procedure TSetStringForm.Button2Click(Sender: TObject);
begin
  Close;
end;

procedure TSetStringForm.Edit1Change(Sender: TObject);
begin
  if Edit1.Text = '' then
    Button1.Enabled := False
  else
    Button1.Enabled := True;
end;

procedure TSetStringForm.ComboBox1Change(Sender: TObject);
begin
  if ComboBox1.Text = '' then
    Button1.Enabled := False
  else
    Button1.Enabled := True;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -