procedure TfrmMainForm.btnSaveClick(Sender: TObject);
var
IconHandle: THandle;
ExtractedIcon: Ticon;
IconDatei: Array[0..255] of char;
IconSaveFile: String;
begin
// Create an Icon
ExtractedIcon := Ticon.create;
// Copy the name + path of the EXE to an Array of Char
StrPcopy(IconDatei,edtFileName.Text);
// Extract the icon and show it in the Image control
IconHandle := ExtractIcon(hInstance, IconDatei, 0);
ExtractedIcon.Handle := IconHandle;
imgIcon.Picture.Icon := ExtractedIcon;
// File Name of the Icon file is the current folder + File-name of the EXE (where the icon is extractedfrom)
IconSaveFile := ExtractFilePath(Paramstr(0));
IconSaveFile := IconSaveFile + ExtractFileName(edtFileName.Text);
IconSaveFile := StringReplace(IconSaveFile, '.exe', '.ico', [rfReplaceAll, rfIgnoreCase]);
IconSaveFile := StringReplace(IconSaveFile, '.dll', '.ico', [rfReplaceAll, rfIgnoreCase]);
ExtractedIcon.SaveToFile(IconSaveFile);
ExtractedIcon.Free;
end;