分享
 
 
 

老友归来--delphi2005试用手记1

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Delphi出到8时,我曾安装过。当时第一感觉是失望,因为熟悉的vcl视觉不见了;再一个感觉是陌生,因为delphi改动了它的代码,我们再要写东西就得遵循MS的.net命名空间做事。更重要的是,我对使用delphi做b/s开发没有信心。好不爽了一阵子后,我转向了java平台。

但后来,我看到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.

下面是三个方式下的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)

{

components.Dispose();

}

}

base.Dispose(disposing);

}

#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>

private void InitializeComponent()

{

this.textBox1 = new System.Windows.Forms.TextBox();

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// textBox1

//

this.textBox1.Location = new System.Drawing.Point(72, 88);

this.textBox1.Name = "textBox1";

this.textBox1.Size = new System.Drawing.Size(120, 21);

this.textBox1.TabIndex = 0;

this.textBox1.Text = "textBox1";

this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);

//

// button1

//

this.button1.Location = new System.Drawing.Point(88, 176);

this.button1.Name = "button1";

this.button1.TabIndex = 1;

this.button1.Text = "button1";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// WinForm

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(292, 273);

this.Controls.Add(this.button1);

this.Controls.Add(this.textBox1);

this.Name = "WinForm";

this.Text = "WinForm";

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new WinForm());

}

private void button1_Click(object sender, System.EventArgs e)

{

textBox1.Text="Hello World.";

}

private void textBox1_TextChanged(object sender, System.EventArgs e)

{

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有