How to enumerate video modes

unit Video;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
 DC      : THandle;  // Display context
 Bits    : Integer;  // Bits per pixel
 HRes    : Integer;  // Horizontal resolution
 VRes    : Integer;  // Vertical resolution
 DM      : TDevMode; // To Save EnumDisplaySettings
 ModeNum : LongInt;  // Video Mode Number
 Ok      : Bool;
begin
// Get current video mode
// DC   := GetDC(Handle);
 DC   := Canvas.Handle;
 Bits := GetDeviceCaps(DC, BITSPIXEL);
 HRes := GetDeviceCaps(DC, HORZRES);
 VRes := GetDeviceCaps(DC, VERTRES);
 Edit1.Text := Format('%d bits, %d x %d',[Bits, HRes, VRes]);
// ReleaseDC(Handle, DC);
// Show all modes available (i.e. supported by the driver)
 ModeNum := 0;    // The 1st one
 EnumDisplaySettings(Nil, ModeNum, DM);
 ListBox1.Items.Add(Format('%d bits, %d x %d',
    [DM.dmBitsPerPel, DM.dmPelsWidth, DM.dmPelsHeight]));
 Ok := True;
 While Ok do
  Begin
   Inc(ModeNum); // Get next one
   Ok := EnumDisplaySettings(Nil, ModeNum, DM);
   If Ok Then ListBox1.Items.Add(Format('%d bits, %d x %d',
      [DM.dmBitsPerPel, DM.dmPelsWidth, DM.dmPelsHeight]));
  End;
end;
end.