Now I want to create a resource file with two icons and call it.
1. Create a new project and save it. Note that {$ R *. Res} will not be deleted this time}
2. Copy two ICO files to the project directory, for example, icofile_1.ico and icofile_2.ico.
3. Create a text file input:
Ico1 icon icofile_1.ico
Ico2 icon icofile_2.ico
Save it as Myres. RC and add it to the project ,:
4. At this time, the project file will be automatically inserted: {$ R 'myres. res '}
5. Add four buttons to implementCodeAs follows:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; button3: tbutton; button4: tbutton; Procedure submit (Sender: tobject ); end; var form1: tform1; implementation {$ R *. DFM} // use the first custom icon in the resource procedure tform1.button1click (Sender: tobject); begin application. icon. handle: = loadicon (hinstance, 'ico1'); {hinstance current Program Instance handle, which must be used to call a resource file; ico1 is the resource file identifier; loadicon is an API function used to call the ICO file in the resource, it returns the handle of the specified ICO file .} end; // use the second custom icon procedure tform1.button2click (Sender: tobject) in the resource; begin application. icon. handle: = loadicon (hinstance, 'ico2 '); end; // use the default program icon procedure tform1.button3click (Sender: tobject) in the resource; begin application. icon. handle: = loadicon (hinstance, 'mainicon '); end; // do not use the icon (the default icon for Windows is displayed) Procedure tform1.button4click (Sender: tobject); begin application. icon: = nil; end.
//:
Note:
1. Myres. RC is compiled into Myres. Res;
2. The icofile_1.ico and icofile_2.ico files are compiled into Myres. Res;
3. The Myres. Res file is also compiled into project1.exe.