Delphi Trik

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

Delphi Tricks Let the computer speak!

(Microsoft Voice API) - Add a Button and Edit box - Add this uses statement: uses Comobj; - Add this coding for the button (the program will read the contents of Edit1): procedure TForm1.Button1Click(Sender: TObject); var CompVoice : OLEVariant; sText : String; begin sText := Edit1.Text; CompVoice := CreateOLEObject('SAPI.SpVoice'); CompVoice.Speak(sText, 0); end; Run another program - Add a Button - Add this coding ('notepad.exe' can be substituted with the path of any other p rogram) procedure TForm1.Button1Click(Sender: TObject); begin WinExec('notepad.exe',SW_SHOWNORMAL); end; Move around with arrows - Add any component (such as a Label) to move around - Click on the Form and double click on the OnKeyDown event (Object Inspector) - Add the following coding: procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if key = 37 then {left} label1.Left := label1.Left - 10; if key = 38 then {up} label1.Top := label1.Top - 10; if key = 39 then {right} label1.Left := label1.Left + 10; if key = 40 then {down} label1.Top := label1.Top + 10; end; Play music file - Add MediaPlayer component (found on the System tab on the Component Palette) - Add the following coding to a button (substitute 'test.wav' with the path of a ny sound file procedure TForm1.Button1Click(Sender: TObject); begin MediaPlayer1.FileName := 'test.wav'; MediaPlayer1.Open; MediaPlayer1.Play; end; Show current computer time in a label - Add a Timer component (found on System tab on the Component Palette)

- Add the following coding to the OnTimer event (Object Inspector) procedure TForm1.Timer1Timer(Sender: TObject); begin Label1.Caption := TimeToStr(Time); end;

You might also like