Others

Multilines hint

Posted in Others

Creating multiline hint is not so difficult. Set ShowHint of Button1 to True and try this:

procedure TForm1.FormCreate(Sender: TObject);
begin
  Button1.Hint:='Greatis'+#13+'Delphi Pages';
end;

Get sound volume

Posted in Others

To get sound volume, use WaveOutGetVolume function. A sound volume is variable of DWord type.

uses mmsystem;

procedure TForm1.Button1Click(Sender: TObject);
var
  Volume: DWord;
  MyWaveOutCaps: TWaveOutCaps;
begin
  if WaveOutGetDevCaps(
    WAVE_MAPPER, 
    @MyWaveOutCaps, 
    sizeof(MyWaveOutCaps))=MMSYSERR_NOERROR then
  begin
    WaveOutGetVolume(WAVE_MAPPER, @Volume);
    Label1.Caption:=IntToStr(Volume);
  end;
end;

Get information of playing track

Posted in Others

Use MCI_TMSF_MINUTE, MCI_TMSF_SECOND and MCI_TMSF_TRACK structures, if you want to get some information about playing sound track. This example use Timer component and MCI_TMSF_MINUTE structure for getting count of seconds of small playing file.

procedure TForm1.Button1Click(Sender: TObject);
begin
  with MediaPlayer1 do
  begin
    FileName:='Test.wav';
    Open;
    Play;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Min: Real;
begin
  Min:=MCI_TMSF_MINUTE(MediaPlayer1.Position);
  Label1.Caption:='Seconds - '+FloatToStr(Min/4);
end;

Get frames of animated cursor

Posted in Others

Use MCI_TMSF_MINUTE, MCI_TMSF_SECOND and MCI_TMSF_TRACK structures, if you want to get some information about playing sound track. This example use Timer component and MCI_TMSF_MINUTE structure for getting count of seconds of small playing file.

procedure TForm1.Button1Click(Sender: TObject);
begin
  with MediaPlayer1 do
  begin
    FileName:='Test.wav';
    Open;
    Play;
  end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Min: Real;
begin
  Min:=MCI_TMSF_MINUTE(MediaPlayer1.Position);
  Label1.Caption:='Seconds - '+FloatToStr(Min/4);
end;

Get data from excel file

Posted in Others

This example shows, how to run Excel, open *.xls file and get data of this file into StringGrid component. Don't forget add ComObj in uses chapter.

procedure TForm1.Button1Click(Sender: TObject);
begin
  Excel:=CreateOleObject('Excel.Application');
  Excel.Visible:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Excel.Workbooks.Open(GetCurrentDir+'\book1.xls');
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  Excel.Workbooks.Close;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
  i, j: Integer;
begin
  for i:=1 to 4 do
    for j:=1 to 2 do
      StringGrid1.Cells[j,i]:=
        Excel.ActiveSheet.Cells[i,j].Value;
end;