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

📄 winform.pas.~25~

📁 《Delphi程序员成长攻略》-蒙祖强龚涛的源代码
💻 ~25~
字号:
unit WinForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data,SysUtils;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    Button1: System.Windows.Forms.Button;
    TextBox1: System.Windows.Forms.TextBox;
    TextBox2: System.Windows.Forms.TextBox;
    TextBox3: System.Windows.Forms.TextBox;
    Label1: System.Windows.Forms.Label;
    GroupBox1: System.Windows.Forms.GroupBox;
    Label2: System.Windows.Forms.Label;
    Label3: System.Windows.Forms.Label;
    Label4: System.Windows.Forms.Label;
    Label5: System.Windows.Forms.Label;
    GroupBox2: System.Windows.Forms.GroupBox;
    Label6: System.Windows.Forms.Label;
    TextBox4: System.Windows.Forms.TextBox;
    Button2: System.Windows.Forms.Button;
    Label7: System.Windows.Forms.Label;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
    procedure Button2_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

uses localhost.WebService1;

{$AUTOBOX ON}

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
begin
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.TextBox1 := System.Windows.Forms.TextBox.Create;
  Self.TextBox2 := System.Windows.Forms.TextBox.Create;
  Self.TextBox3 := System.Windows.Forms.TextBox.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.GroupBox1 := System.Windows.Forms.GroupBox.Create;
  Self.Label5 := System.Windows.Forms.Label.Create;
  Self.Label4 := System.Windows.Forms.Label.Create;
  Self.Label3 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.GroupBox2 := System.Windows.Forms.GroupBox.Create;
  Self.Label7 := System.Windows.Forms.Label.Create;
  Self.Button2 := System.Windows.Forms.Button.Create;
  Self.TextBox4 := System.Windows.Forms.TextBox.Create;
  Self.Label6 := System.Windows.Forms.Label.Create;
  Self.GroupBox1.SuspendLayout;
  Self.GroupBox2.SuspendLayout;
  Self.SuspendLayout;
  // 
  // Button1
  // 
  Self.Button1.Location := System.Drawing.Point.Create(384, 184);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(88, 23);
  Self.Button1.TabIndex := 0;
  Self.Button1.Text := '求方程的根';
  Include(Self.Button1.Click, Self.Button1_Click);
  // 
  // TextBox1
  // 
  Self.TextBox1.Location := System.Drawing.Point.Create(216, 24);
  Self.TextBox1.Name := 'TextBox1';
  Self.TextBox1.TabIndex := 1;
  Self.TextBox1.Text := '';
  // 
  // TextBox2
  // 
  Self.TextBox2.Location := System.Drawing.Point.Create(216, 64);
  Self.TextBox2.Name := 'TextBox2';
  Self.TextBox2.TabIndex := 2;
  Self.TextBox2.Text := '';
  // 
  // TextBox3
  // 
  Self.TextBox3.Location := System.Drawing.Point.Create(216, 104);
  Self.TextBox3.Name := 'TextBox3';
  Self.TextBox3.TabIndex := 3;
  Self.TextBox3.Text := '';
  // 
  // Label1
  // 
  Self.Label1.Location := System.Drawing.Point.Create(120, 24);
  Self.Label1.Name := 'Label1';
  Self.Label1.TabIndex := 4;
  Self.Label1.Text := '二次项系数:';
  // 
  // GroupBox1
  // 
  Self.GroupBox1.Controls.Add(Self.Label5);
  Self.GroupBox1.Controls.Add(Self.Label4);
  Self.GroupBox1.Controls.Add(Self.Label3);
  Self.GroupBox1.Controls.Add(Self.Label2);
  Self.GroupBox1.Controls.Add(Self.TextBox1);
  Self.GroupBox1.Controls.Add(Self.TextBox2);
  Self.GroupBox1.Controls.Add(Self.TextBox3);
  Self.GroupBox1.Controls.Add(Self.Label1);
  Self.GroupBox1.Controls.Add(Self.Button1);
  Self.GroupBox1.Location := System.Drawing.Point.Create(16, 8);
  Self.GroupBox1.Name := 'GroupBox1';
  Self.GroupBox1.Size := System.Drawing.Size.Create(488, 224);
  Self.GroupBox1.TabIndex := 5;
  Self.GroupBox1.TabStop := False;
  Self.GroupBox1.Text := '求方程的根';
  // 
  // Label5
  // 
  Self.Label5.Font := System.Drawing.Font.Create('宋体', 9, System.Drawing.FontStyle.Bold, 
      System.Drawing.GraphicsUnit.Point, (Byte(134)));
  Self.Label5.Location := System.Drawing.Point.Create(16, 192);
  Self.Label5.Name := 'Label5';
  Self.Label5.Size := System.Drawing.Size.Create(328, 23);
  Self.Label5.TabIndex := 8;
  Self.Label5.Text := '方程的第二个根:';
  // 
  // Label4
  // 
  Self.Label4.Font := System.Drawing.Font.Create('宋体', 9, System.Drawing.FontStyle.Bold, 
      System.Drawing.GraphicsUnit.Point, (Byte(134)));
  Self.Label4.Location := System.Drawing.Point.Create(16, 160);
  Self.Label4.Name := 'Label4';
  Self.Label4.Size := System.Drawing.Size.Create(328, 23);
  Self.Label4.TabIndex := 7;
  Self.Label4.Text := '方程的第一个根:';
  // 
  // Label3
  // 
  Self.Label3.Location := System.Drawing.Point.Create(120, 112);
  Self.Label3.Name := 'Label3';
  Self.Label3.Size := System.Drawing.Size.Create(80, 23);
  Self.Label3.TabIndex := 6;
  Self.Label3.Text := '常数项系数:';
  // 
  // Label2
  // 
  Self.Label2.Location := System.Drawing.Point.Create(120, 72);
  Self.Label2.Name := 'Label2';
  Self.Label2.Size := System.Drawing.Size.Create(80, 23);
  Self.Label2.TabIndex := 5;
  Self.Label2.Text := '一次项系数:';
  // 
  // GroupBox2
  // 
  Self.GroupBox2.Controls.Add(Self.Label7);
  Self.GroupBox2.Controls.Add(Self.Button2);
  Self.GroupBox2.Controls.Add(Self.TextBox4);
  Self.GroupBox2.Controls.Add(Self.Label6);
  Self.GroupBox2.Location := System.Drawing.Point.Create(16, 240);
  Self.GroupBox2.Name := 'GroupBox2';
  Self.GroupBox2.Size := System.Drawing.Size.Create(488, 176);
  Self.GroupBox2.TabIndex := 6;
  Self.GroupBox2.TabStop := False;
  Self.GroupBox2.Text := '求圆的面积';
  // 
  // Label7
  // 
  Self.Label7.Font := System.Drawing.Font.Create('宋体', 9, System.Drawing.FontStyle.Bold, 
      System.Drawing.GraphicsUnit.Point, (Byte(134)));
  Self.Label7.Location := System.Drawing.Point.Create(43, 96);
  Self.Label7.Name := 'Label7';
  Self.Label7.Size := System.Drawing.Size.Create(317, 23);
  Self.Label7.TabIndex := 3;
  Self.Label7.Text := '圆的面积:';
  // 
  // Button2
  // 
  Self.Button2.Location := System.Drawing.Point.Create(392, 136);
  Self.Button2.Name := 'Button2';
  Self.Button2.Size := System.Drawing.Size.Create(80, 23);
  Self.Button2.TabIndex := 2;
  Self.Button2.Text := '求圆的面积';
  Include(Self.Button2.Click, Self.Button2_Click);
  // 
  // TextBox4
  // 
  Self.TextBox4.Location := System.Drawing.Point.Create(126, 43);
  Self.TextBox4.Name := 'TextBox4';
  Self.TextBox4.Size := System.Drawing.Size.Create(176, 21);
  Self.TextBox4.TabIndex := 1;
  Self.TextBox4.Text := '';
  // 
  // Label6
  // 
  Self.Label6.Location := System.Drawing.Point.Create(48, 48);
  Self.Label6.Name := 'Label6';
  Self.Label6.Size := System.Drawing.Size.Create(72, 23);
  Self.Label6.TabIndex := 0;
  Self.Label6.Text := '圆的半径:';
  // 
  // TWinForm
  // 
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 14);
  Self.ClientSize := System.Drawing.Size.Create(520, 430);
  Self.Controls.Add(Self.GroupBox2);
  Self.Controls.Add(Self.GroupBox1);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Self.GroupBox1.ResumeLayout(False);
  Self.GroupBox2.ResumeLayout(False);
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm.Button2_Click(sender: System.Object; e: System.EventArgs);
var CircleSer:TWebService1;
    result:double;
begin
    CircleSer := TWebService1.Create;
    //调用Web服务,求圆的面积
    result := CircleSer.Circle(StrToFloat(TextBox4.Text));
    label7.Text:='圆的面积:S = '+FloatToStr(result);
end;

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var EquationSer:TWebService1;
    result:double;
begin
    EquationSer := TWebService1.Create;
    result := EquationSer.Equation_x1(StrToFloat(TextBox1.Text ), StrToFloat(TextBox2.Text ), StrToFloat(TextBox3.Text));
    label4.Text:='方程的第一个根:x1= '+FloatToStr(result);
    result := EquationSer.Equation_x2(StrToFloat(TextBox1.Text), StrToFloat(TextBox2.Text), StrToFloat(TextBox3.Text));
    label5.Text:='方程的第二个根:x2= '+FloatToStr(result);
end;

{
procedure TWebForm1.Button1_Click(sender: System.Object; e: System.EventArgs);
var EquationSer:TWebService1;
    result:double;
begin
    EquationSer := TWebService1.Create;
    //调用Web服务,求方程的第一个根x1
    result := EquationSer.Equation_x1(StrToFloat(TextBox1.Text ), StrToFloat(TextBox2.Text ), StrToFloat(TextBox3.Text));
    label4.Text:='方程的第一个根:x1= '+FloatToStr(result);
    //调用Web服务,求方程的第二个根x2
    result := EquationSer.Equation_x2(StrToFloat(TextBox1.Text), StrToFloat(TextBox2.Text), StrToFloat(TextBox3.Text));
    label5.Text:='方程的第二个根:x2= '+FloatToStr(result);
end;

/////// 【求圆的面积】按钮(Button2)的事件处理过程 //////
procedure TWebForm1.Button2_Click(sender: System.Object; e: System.EventArgs);
var CircleSer:TWebService1;
    result:double;
begin
    CircleSer := TWebService1.Create;
    //调用Web服务,求圆的面积
    result := CircleSer.Circle(StrToFloat(TextBox4.Text));
    label7.Text:='圆的面积:S = '+FloatToStr(result);
end;

}

end.

⌨️ 快捷键说明

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