Place TButton and TImage on the form and test this code...
uses
ShellAPI;
function GetFileIcon(FileName: string; var DocType: string): TIcon;
var
Info: SHFILEINFO;
begin
FillChar(Info, SizeOf(Info), 0);
Result := TIcon.Create;
SHGetFileInfo(PChar(FileName), 0, Info, SizeOf(Info), SHGFI_ICON or SHGFI_TYPENAME);
DocType := Info.szTypeName;
Result.Handle := Info.hIcon;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Icon: TIcon;
DocType: string;
begin
with TOpenDialog.Create(Self) do
try
if not Execute then
Exit;
Icon := GetFileIcon(FileName, DocType);
try
ShowMessage('File type: ' + DocType);
Image.Picture.Icon.Assign(Icon);
finally
Icon.Free;
end;
finally
Free;
end;
end;