Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 194899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:38:05+00:00 2026-05-11T16:38:05+00:00

Basically I have a TcxGrid which will be listing various files names and I’d

  • 0

Basically I have a TcxGrid which will be listing various files names and I’d like to give further details based on the file extension, specifically it’s description (e.g. for .PDF it’s “Adobe Acrobat Document”) and it’s related icon.

I notice there is a very similar question already but it’s C# related and I’d like something Delphi based.

Suggestions on where to look for this kind of info would be good and if there is a class similar to the one mentioned in the C# post above (obviously in Delphi) that would be great.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:38:05+00:00Added an answer on May 11, 2026 at 4:38 pm

    Thanks to Rob Kennedy for pointing me in the direction of ShGetFileInfo. I then Googled on that and found these two examples – Delphi 3000, Torry’s. From that I wrote the following class to do what I needed.

    Also, just as I was finishing up Bill Miller’s answer gave me the final bit of help I needed. Originally I was passing full file names through to ShGetFileInfo, which wasn’t ideally what I wanted. The tweak suggested of passing “*.EXT” was great.

    The class could do with more work but it does what I need. It seems to handle file extensions that have no details associated either.

    Finally, in what I’m using I’ve switched it to using a TcxImageList instead of a TImageList, since I was having problems with black borders appearing on the icons, because it was a quick fix.

    unit FileAssociationDetails;
    
    {
      Created       : 2009-05-07
      Description   : Class to get file type description and icons.
                      * Extensions and Descriptions are held in a TStringLists.
                      * Icons are stored in a TImageList.
    
                      Assumption is all lists are in same order.
    }
    
    interface
    
    uses Classes, Controls;
    
    type
      TFileAssociationDetails = class(TObject)
      private
        FImages : TImageList;
        FExtensions : TStringList;
        FDescriptions : TStringList;
      public
        constructor Create;
        destructor Destroy; override;
    
        procedure AddFile(FileName : string);
        procedure AddExtension(Extension : string);    
        procedure Clear;    
        procedure GetFileIconsAndDescriptions;
    
        property Images : TImageList read FImages;
        property Extensions : TStringList read FExtensions;
        property Descriptions : TStringList read FDescriptions;
      end;
    
    implementation
    
    uses SysUtils, ShellAPI, Graphics, Windows;
    
    { TFileAssociationDetails }
    
    constructor TFileAssociationDetails.Create;
    begin
      try
        inherited;
    
        FExtensions := TStringList.Create;
        FExtensions.Sorted := true;
        FDescriptions := TStringList.Create;
        FImages := TImageList.Create(nil);
      except
      end;
    end;
    
    destructor TFileAssociationDetails.Destroy;
    begin
      try
        FExtensions.Free;
        FDescriptions.Free;
        FImages.Free;
      finally
        inherited;
      end;
    end;
    
    procedure TFileAssociationDetails.AddFile(FileName: string);
    begin
      AddExtension(ExtractFileExt(FileName));
    end;
    
    procedure TFileAssociationDetails.AddExtension(Extension : string);
    begin
      Extension := UpperCase(Extension);
      if (Trim(Extension) <> '') and
         (FExtensions.IndexOf(Extension) = -1) then
        FExtensions.Add(Extension);
    end;
    
    procedure TFileAssociationDetails.Clear;
    begin
      FExtensions.Clear;
    end;
    
    procedure TFileAssociationDetails.GetFileIconsAndDescriptions;
    var
      Icon: TIcon;
      iCount : integer;
      Extension : string;
      FileInfo : SHFILEINFO; 
    begin
      FImages.Clear;
      FDescriptions.Clear;
    
      Icon := TIcon.Create;
      try
        // Loop through all stored extensions and retrieve relevant info
        for iCount := 0 to FExtensions.Count - 1 do
        begin
          Extension := '*' + FExtensions.Strings[iCount];
    
          // Get description type
          SHGetFileInfo(PChar(Extension),
                        FILE_ATTRIBUTE_NORMAL,
                        FileInfo,
                        SizeOf(FileInfo),
                        SHGFI_TYPENAME or SHGFI_USEFILEATTRIBUTES
                        );
          FDescriptions.Add(FileInfo.szTypeName);
    
          // Get icon and copy into ImageList
          SHGetFileInfo(PChar(Extension),
                        FILE_ATTRIBUTE_NORMAL,
                        FileInfo,
                        SizeOf(FileInfo),
                        SHGFI_ICON or SHGFI_SMALLICON or
                        SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES
                        );
          Icon.Handle := FileInfo.hIcon;
          FImages.AddIcon(Icon);
        end;
      finally
        Icon.Free;
      end;
    end;
    
    end.
    

    Also here is an example test app using it, it’s very simple, just a form with a TPageControl on it. My actual use was not for this, but for with a Developer Express TcxImageComboxBox in a TcxGrid.

    unit Main;
    
    {
      Created       : 2009-05-07
      Description   : Test app for TFileAssociationDetails.
    }
    
    interface
    
    uses
      Windows, Forms, FileAssociationDetails, Classes, Controls, ComCtrls;
    
    type
      TfmTest = class(TForm)
        PageControl1: TPageControl;
        procedure FormShow(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
        FFileDetails : TFileAssociationDetails;
      public
        { Public declarations }
      end;
    
    var
      fmTest: TfmTest;
    
    implementation
    
    {$R *.dfm}
    
    procedure TfmTest.FormShow(Sender: TObject);
    var
      iCount : integer;
      NewTab : TTabSheet;
    begin
      FFileDetails := TFileAssociationDetails.Create;
      FFileDetails.AddFile('C:\Documents and Settings\...\Test.XLS');
      FFileDetails.AddExtension('.zip');
      FFileDetails.AddExtension('.pdf');
      FFileDetails.AddExtension('.pas');
      FFileDetails.AddExtension('.XML');
      FFileDetails.AddExtension('.poo');
    
      FFileDetails.GetFileIconsAndDescriptions;
      PageControl1.Images := FFileDetails.Images;
    
      for iCount := 0 to FFileDetails.Descriptions.Count - 1 do
      begin
        NewTab := TTabSheet.Create(PageControl1);
        NewTab.PageControl := PageControl1;
        NewTab.Caption := FFileDetails.Descriptions.Strings[iCount];
        NewTab.ImageIndex := iCount;
      end;
    end;
    
    procedure TfmTest.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      PageControl1.Images := nil;
      FFileDetails.Free;
    end;
    
    end.
    

    Thanks everyone for your answers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 305k
  • Answers 305k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Only one I've used in debugging something: [MethodImpl(MethodImplOptions.NoInlining)] This prevents… May 13, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer You need to wrap your function call in an anonymous… May 13, 2026 at 8:59 pm
  • Editorial Team
    Editorial Team added an answer Are you building a Dialog or SDI/MDI type app? If… May 13, 2026 at 8:59 pm

Related Questions

Basically I have a TcxGrid which will be listing various files names and I'd
Basically I have a bunch of unmanaged VC++ static libraries. And the VC++ GUI
Basically I have a website. I have a properly setup sitemap so I assume
Basically I have a small template that looks like: <xsl:template name=templt> <xsl:param name=filter />
Basically I have a mysql query something like the following: mysql_query(SELECT n.title, v.value FROM

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.