Archive

Posts Tagged ‘create’

How to Create Multiple Directories

December 15th, 1999 m3Rlin No comments

The standard MkDir() function can create only one directory, it can not create subdirectories at one time. This function allows you to create multiple directories (directories inside directories). Delphi 4+ have the ForceDirectories() routine which does the same thing. It is declared in the FileCtrl unit.

uses
  SysUtils, FileCtrl;
...
procedure MkDirMulti(sPath: string);
begin
  if sPath[Length(sPath)] = '' then
    sPath := Copy(sPath, 1, Length(sPath - 1));

  if (Length(sPath) < 3) or DirectoryExists(sPath) then
    Exit;

  MkDirMulti(SysUtils.ExtractFilePath(sPath));
  try
    MkDir(sPath);
  except
    { Handle errors }
  end;
end;

Example: MkDirMulti(‘C:Program FilesMy GameAudioSpeech’);

How to Create a Gradient Form

December 15th, 1999 m3Rlin No comments

In setup programs or sometimes in AboutBoxes you can find gradient forms.

It sure looks as if it were a lot of work but it’s really very easy. All you have to do is add this code to your program.
This example will create a gradient rectangle on the whole form Canvas. To change it’s size just change the parameters of the Rectangle() function.

Add this code to your form’s OnPaint event:

1) Constant number of steps:

const
  btN = 100; { Number of steps }
var
  iI: Integer;
  Col: TColor;
begin
  for iI := 0 to btN - 1 do
    with Canvas do begin
      Col := RGB(0, 0, Round(50 + 205 * (iI / btN)));
      Pen.Color := Col;
      Brush.Color := Col;
      Rectangle(0, Round(ClientHeight * (iI / btN)), ClientWidth, Round(ClientHeight * ((iI + 1) / btN)));
    end;
end;

To get rid of problems when resizing the form just add this code to the form’s OnResize event:

...
Invalidate;
...

2) It calculates the number of steps:

var
  wHeight, wRow: Word;
begin
  wHeight := (ClientHeight + 255) div 256;
  for Row := 0 to 255 do
    with Canvas do begin
      Brush.Color := RGB(wRow, 0, 0); { Modify this for a different color }
      FillRect(Rect(0, wRow * wHeight, ClientWidth, (wRow + 1) * wHeight)) ;
    end;
end;

3) Hacking our way around… :-)
This function works in Delphi 3 but not in Delphi 4.

uses
  Charts;
...
  GradientFill(Canvas, ClientRect, clBlack, clBlue, False);
...