TacShortcut component
Hierarchy Properties Methods Example |
The acShortcut component lets you to quickly and easily create a shortcuts (also known as shell links) to files and folders (in any location) and read the information from shorcut files (.lnk).
|
Just point the FileName property to the .lnk file and read the information from other properties:
|
LinkTarget | Points to the file which should be opened on starting s shortcut (on clicking the shortcut icon);
|
Parameters | The command-line parameters for executable file specified by LinkTarget property. (if LinkTarget is an EXE);
|
WorkingDirectory | Working directory for executable file specified in LinkTarget property. (if LinkTarget is an EXE);
|
RunAs | Specifies how the window should be opened: minimized, maximized or in its normal state;
|
IconLocation, IconIndex | Points the location to icon file or another file which contains the icon resources. IconIndex property specifies the resource index, if IconLocation is an EXE or DLL;
|
HotKey | Specifies the key combination which executes a shortcut;
|
LargeIcon, SmallIcon | Read-only properties. Contains the 32x32 and 16x16 icons of shortcut link.
|
|
The FILENAME property works either at run- or design-time, so you can play with acShortcut component, pointing the .lnk file at design-time. After specifyng the FILENAME, all other properties will be filled with information about the shortcut.
|
To create a shortcut you must specify the shortcut information to according properties and call SaveToFile(FileName) method, where the FileName is the name of shortcut. Function returs False when it fails.
|
|
For example, you would like to create a shortcut file on desktop, which points to your current executable file + want to specify the icon #4 from shell32.dll file.
|
procedure TForm1.Button1Click(Sender: TObject);
|
begin
|
acShortcut1.LinkTarget := Application.ExeName;
|
|
// next two lines will set icon #4 from shell32.dll
|
acShortcut1.IconLocation := acSystemInfo1.DirSystem + '\shell32.dll';
|
acShortcut1.IconIndex := 4;
|
|
// saving to Test.lnk file on desktop
|
acShortcut1.SaveToFile(acSystemInfo1.DirDesktop + '\Test.lnk');
|
end;
|
Shortcuts is usual files, with .LNK extension. To remove a shortcuts just delete them using standard routines, such like DeleteFile
|
acSystemInfo component.
|