AboutBlogContact
Software DevelopmentMay 20, 1999 2 min read 24

Delphi 5: Building Custom VCL Components (1999)

AunimedaAunimeda

Delphi 5: Building Custom VCL Components

Delphi 5 is the peak of rapid application development on Windows. While Visual Basic developers are struggling with COM and DLL hell, we have the VCL (Visual Component Library). The best part? You can write your own components and install them right into the IDE.

Anatomy of a Component

A VCL component is a Delphi class that usually inherits from TCustomControl or an existing component like TEdit.

unit MyCustomLabel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, StdCtrls;

type
  TMyCustomLabel = class(TCustomLabel)
  private
    FFlashColor: TColor;
    procedure SetFlashColor(Value: TColor);
  protected
    procedure Paint; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property FlashColor: TColor read FFlashColor write SetFlashColor;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Aunimeda', [TMyCustomLabel]);
end;

constructor TMyCustomLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FFlashColor := clRed;
end;

procedure TMyCustomLabel.Paint;
begin
  Canvas.Font.Color := FFlashColor;
  inherited Paint;
end;

procedure TMyCustomLabel.SetFlashColor(Value: TColor);
begin
  if FFlashColor <> Value then
  begin
    FFlashColor := Value;
    Invalidate; // Force a repaint
  end;
end;

end.

The 'published' Section

The magic of Delphi's Object Inspector comes from the published section. Any property listed there is automatically available for editing at design-time via RTTI (Run-Time Type Information).

Delphi's component model is so clean because it's just Object Pascal all the way down. Once you register your component, you can drag and drop it onto a form just like a standard button. This is why we can build Windows apps in hours that take C++ developers weeks.

Read Also

Visual Basic 1.0: Drag-and-Drop for the Massesaunimeda
Software Development

Visual Basic 1.0: Drag-and-Drop for the Masses

Windows development used to be a nightmare of C code and message loops. Visual Basic 1.0 changes everything with a radical new idea: drawing your UI.

PowerBuilder: DataWindow Internals (1998)aunimeda
Software Development

PowerBuilder: DataWindow Internals (1998)

The DataWindow is the most productive database abstraction ever created. Let's look at the syntax and the buffer management.

VMware Workstation: Running Windows Inside Linuxaunimeda
Virtualization

VMware Workstation: Running Windows Inside Linux

Virtualization has arrived on the x86 platform. VMware Workstation allows you to run multiple operating systems simultaneously without rebooting.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles