程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 老友歸來--delphi2005試用手記1

老友歸來--delphi2005試用手記1

編輯:Delphi
 

Delphi出到8時,我曾安裝過。當時第一感覺是失望,因為熟悉的vcl視覺不見了;再一個感覺是陌生,因為delphi改動了它的代碼,我們再要寫東西就得遵循MS的.net命名空間做事。更重要的是,我對使用delphi做b/s開發沒有信心。好不爽了一陣子後,我轉向了java平台。

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /> 

但後來,我看到asp.net真的非常好,而且delphi也可以實現它,這讓我有種想回見老友的沖動。但當時沒時間學,所以還不太懂。我對IntraWeb和asp.net兩種實現都很有興趣,很想試試。在後來,c# builder1.0的試用讓我對borland多少有了點好感,但還是覺得它是跟屁蟲,已經沒有ms抗衡的力量了。這讓我想起了加菲貓的一句話,如果打不過你的敵人,最好的辦法就是加入他們。

 

今天,我對delphi有了另一種態度。不再苛刻地要求它就是最好最快的,而是希望自己在b/s也能用得上delphi,並覺得還好用,這就足夠了。至於它外觀和空間的變化,在delphi8後,我已開始接受,畢竟delphi不走.net就沒什麼路可走了。

 

當我意外地得到borland寄來的delphi2005試用版時,我就想得到了一款正在流行的游戲一樣,非常想試玩一下。可是,borland的注冊太沒有“中國特色”了,害得我跑到網上弄了個注冊機。不做D版用戶還不太習慣。

 

(一)Hello World.

Delphi2005是個集成環境,包括了delphi、c#,好像還可以使用vb.net,但這不是常規菜單裡的內容。我感覺borland對此款軟件的命名有問題,應該叫borland.net2005才對,不然用delphi開發c#,聽起來有點搞笑。

 

先來用delphi寫個Hello World吧。在2005裡,開發delphi有三種不同的途徑,自然應用環境也不同。分別是:

1 VCLForms Application for .NET

2 WindowsForms Application for .NET

3 VCLForms Application for Win32.

<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />


  下面是三個方式下的Hello World.

1 VCLForms Application for .NET

單元代碼:

unit Unit1; 

interface 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls; 

type

  TForm1 = class(TForm)

    Button1: TButton;

    Edit1: TEdit;

    procedure Button1Click(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end; 

var

  Form1: TForm1; 

implementation

{$R *.dfm} 

procedure TForm1.Button1Click(Sender: TObject);

begin

edit1.Text :='Hello World.';

end; 

end.

 

窗體代碼:

object Form1: TForm1

  Left = 0

  Top = 0

  Width = 281

  Height = 138

  Caption = 'Form1'

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'Tahoma'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object Button1: TButton

    Left = 88

    Top = 56

    Width = 75

    Height = 25

    Caption = 'Button1'

    TabOrder = 0

    OnClick = Button1Click

  end

  object Edit1: TEdit

    Left = 8

    Top = 8

    Width = 249

    Height = 21

    TabOrder = 1

  end

end
  
 

這看起來,和從前的win32開發沒有什麼不同。單元和窗體分開,分別作處理和持久化工作。而在2中這兩個工作合並在一個pas文件裡了。

 

2 WindowsForms Application for .NET

unit WinForm;

interface 

uses

  System.Drawing, System.Collections, System.ComponentModel,

  System.Windows.Forms, System.Data; 

type

  TWinForm = class(System.Windows.Forms.Form)

  {$REGION 'Designer Managed Code'}

  strict private

    /// <summary>

    /// Required designer variable.

    /// </summary>

    Components: System.ComponentModel.Container;

    TextBox1: System.Windows.Forms.TextBox;

    Button1: System.Windows.Forms.Button;

    /// <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);

  {$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 

{$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.TextBox1 := System.Windows.Forms.TextBox.Create;

  Self.Button1 := System.Windows.Forms.Button.Create;

  Self.SuspendLayout;

  //

  // TextBox1

  //

  Self.TextBox1.Location := System.Drawing.Point.Create(72, 40);

  Self.TextBox1.Name := 'TextBox1';

  Self.TextBox1.Size := System.Drawing.Size.Create(152, 21);

  Self.TextBox1.TabIndex := 0;

  Self.TextBox1.Text := '';

  //

  // Button1

  //

  Self.Button1.Location := System.Drawing.Point.Create(80, 160);

  Self.Button1.Name := 'Button1';

  Self.Button1.Size := System.Drawing.Size.Create(136, 32);

  Self.Button1.TabIndex := 1;

  Self.Button1.Text := 'Button1';

  Include(Self.Button1.Click, Self.Button1_Click);

  //

  // TWinForm

  //

  Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 14);

  Self.ClientSize := System.Drawing.Size.Create(292, 273);

  Self.Controls.Add(Self.Button1);

  Self.Controls.Add(Self.TextBox1);

  Self.Name := 'TWinForm';

  Self.Text := 'WinForm';

  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.Button1_Click(sender: System.Object; e: System.EventArgs);

begin

  TextBox1.Text:='Hello World!';

end;

 

end.

 

3 VCLForms Application for Win32.

它的代碼和1完全一樣。

 

最後是用c#寫的helloworld.它只有.net一種方式,因為它誕生在.net時代。

 

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

 

namespace Project1

{

         /// <summary>

         /// Summary description for WinForm.

         /// </summary>

         public class WinForm : System.Windows.Forms.Form

         {

                   /// <summary>

                   /// Required designer variable.

                   /// </summary>

                   private System.ComponentModel.Container components = null;

                   private System.Windows.Forms.TextBox textBox1;

                   private System.Windows.Forms.Button button1;

 

                   public WinForm()

                   {

                            //

                            // Required for Windows Form Designer support

                            //

                            InitializeComponent();

 

                            //

                            // TODO: Add any constructor code after InitializeComponent call

                            //

                   }

 

                   /// <summary>

                   /// Clean up any resources being used.

                   /// </summary>

                   protected override void Dispose(bool disposing)

                   {

                            if (disposing)

                            {

                                     if (components != null

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved