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

奶fly

奶fly

2016-02-19 16:22

下面图老师小编要向大家介绍下老友归来--delphi2005试用手记1,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!
 

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

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

  object Edit1: TEdit

    Left = 8

    Top = 8

    Width = 249

    Height = 21

    TabOrder = 1

  end

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

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.

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

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

展开更多 50%)
分享

猜你喜欢

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

编程语言 网络编程
老友归来--delphi2005试用手记1

CorelDRAW 11抢鲜试用手记(1)

CorelDRAW
CorelDRAW 11抢鲜试用手记(1)

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

WPS2024试用手记

电脑入门
WPS2024试用手记

delphi2005探讨之二

编程语言 网络编程
delphi2005探讨之二

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

delphi2005探讨之四

编程语言 网络编程
delphi2005探讨之四

Delphi2005(DiamondBack)使用体验

编程语言 网络编程
Delphi2005(DiamondBack)使用体验

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

systemparametersinfo详细用法

systemparametersinfo详细用法

ASP入门基础教程-使用Querystring 集合

ASP入门基础教程-使用Querystring 集合
下拉加载更多内容 ↓