Mirror

Delphi .NET: "Hello, world!" (Views: 100)


Problem/Question/Abstract:

How to make a simple application using Delphi .NET compiler

Answer:

WinForms is a programming model used to create Windows Applications. .NET framework offers base classes for building Windows applications. Most of the functionality for these classes is in the System.Windows.Forms.
Lets look at the simplest traditional “hello world” example which will help us create our first Windows application in Delphi .NET
The form class is derived form the System.Windows.Forms.Form class. In the constructor of this class private procedure called InitializeComponents is called. If we want to add a new controls to the form we can do it in this procedure.

program newform;

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

type
  TMyform = class(Form)
  private
    components: IContainer;
    procedure InitializeComponent;
  public
    constructor Create;
    destructor Destroy; override;
  end;

constructor TMyform.Create;
begin
  inherited Create;
  InitializeComponent;
end;

destructor TMyform.Destroy;
begin
  inherited;
end;

procedure TMyform.InitializeComponent;
begin
  Self.components := System.ComponentModel.Container.Create as IContainer;
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(160, 85);
  Self.Name := 'Myform';
  Self.Text := 'Hello World'; //change the form title
end;

var
  MyForm: TMyForm;

begin
  MyForm := TMyForm.Create;
  Application.Run(MyForm);
end.

<< Back to main page