By Erick Engelke
July 29, 2025
I sometimes use the browser’s built-in Windows.Alert or EWB’s ShowMessage for various purposes.
I decided I wanted a prettier alert box, so I made this small function and class which you can add to any form or dialog with:
showalert( self, 'My title', 'my message' );
Here are a few shown:
The code to implement this is very easy in EWB.
Users of my nice library can find it in the latest source under nicebase.wbs
type
TMessageBox = class ( TPanel )
public
content : TLabel;
constructor create( activeform: TControl; title, message : string );
end;
constructor TMessageBox.Create( activeform : TControl; title, message : string );
begin
inherited create( activeform );
parent := activeform;
captionbar.allowminimize:=False;
// add borders
border.bottom.visible := True;
border.left.visible := True;
border.right.visible := True;
captionbar.caption := title;
content := TLabel.Create( self );
content.parent := self;
content.layout.position := lptopleft;
content.layout.stretch := lsRight;
content.caption := message;
content.margins.left := 5;
content.margins.Top := 5;
content.margins.bottom := 25;
content.format.wrap := True;
content.Autosize.Height := True;
left := (activeform.width - width) div 4 + random( 0, activeform.width div 4 );
top := (activeform.height - height) div 4 + random( 0, activeform.height div 4 );
end;
procedure ShowAlert( activeform: TControl; title, message : string );
var
mybox : TMessageBox;
begin
mybox := TMessageBox.Create( activeform, title, message );
mybox.Show;
end;