Useful website: http://www.delphitips.com/
Even better tip website: Torry Delphi
Delphi Basics Website - excellent site for critical info (the documentation that should be included with Delphi!)
Converting Integers to Strings:
Use "IntToStr" from the SysUtils unit.
aString := IntToStr(i);
To play a sound file:
To create a thread use File; New; Other; ThreadObject - this will create a unit that encapsulates your thread class.
A thread class has the following functions and procedures:
- Create(boolean) - used to actually create the thread; if the boolean value is true it starts "suspended", if the boolean value is false it starts and runs immediately.
- Execute() - this code is run when the thread is created/run
- Synchronize(method) - executes a procedure such that it can access VCL and other things safely.
- Suspend() - pause?
- Resume() - continue?
- WaitFor() - waits for this thread to finish before continuing (i.e. spawn you can spawn a thread and then wait for it to complete before your main logic continues - this could be handy to launch several threads and then wait for them all to complete before your main logic continues.
- Priority - variable that can be set (or read) to "tpIdle, tpLowest, tpLower, tpNormal, tpHigher, tpHighest, tptimeCritical". This adjusts the relative priority of the thread (to set the main priority of a process use "SetPriorityClass(GetCurrentProcess,HIGH_PRIORITY_CLASS)"
Sleep(DWORD) - Win32 API procedure to pause a thread for the specified number of milliseconds.
GetThreadTimes can be used to get timing information for a thread (when created, exit time, kernel time and user time).
To Execute an external application use the Windows API "ShellAPI" to provide "ShellExecute":
ShellExecute(handle, operation, filename, parameters, folder, show command);
- handle is the handle of your parent application
- operation is nil; edit; explore; find; open, print; properties; (nil essentially means "open")
- filename - the program to be run (or file to be processed)
- parameters to be passed to the application
- folder - default execution path
- show command - an integer; common values: SW_HIDE; SW_SHOWNORMAL; SW_SHOWMAXIMIZED
ShellExecute(Form1.Handle, nil, 'c:\windows\notepad.exe','c:\windows\general.txt', nil, SW_SHOWMAXIMIZED);
ShellExecute spawns a separate process (thread) for the application so it runs in parallel with your Delphi application that executed it.
If it fails it will return a longword error code between 0 to 32 (or if higher is the handle of the other application). Try RaiseLastWin32Error() (part of SysUtils) for more error info.