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

  • SEARCH
  • Home
  • 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 9186997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:39:57+00:00 2026-06-17T19:39:57+00:00

A blog entry from Raymond Chen today made me realize the elegant solution to

  • 0

A blog entry from Raymond Chen today made me realize the elegant solution to a problem i’m having.

Various shell functions, rather than all taking ITEM­ID­LIST structure, can be made to only accept:

  • ITEM­ID_CHILD
  • ID­LIST_RELATIVE
  • ID­LIST_ABSOLUTE
  • ITEM­ID_CHILD_ARRAY

structures. The structures are all identical, but now you can enforce conceptual types at the compiler level.

Back to Delphi

i have a set of functions:

  • some only take a path: (e.g. C:\Users\Ian\Desktop\AllisonAngel.jpg)
  • some only take a filename: (e.g. AllisonAngel.jpg)
  • some only take a folder: (e.g. C:\Users\Ian\Desktop)

And right now they’re all declared as string, e.g.:

 function GetFilenames(Folder: string; ...): ...
 function IsValidBatchFilename(Path: string): ...
 function GetReportType(Filename: string): ...

and i have to trust that i’m passing the right stuff; and i’m trusting that developers (e.g. me), know the difference between:

  • a path
  • a filename
  • and a folder

i want to change the functions to use “typed” strings:

 function GetFilenames(Folder: TFolderOnly; ...): ...
 function IsValidBatchFilename(Path: TFullPath): ...
 function GetReportType(Filename: TFilenameOnly): ...

Where:

type
   TFullPath = type string;
   TFolderOnly = type string;
   TFilenameOnly = type string;

Except that there’s no actual typing happening:

var
   dropFolder: string;
begin
   dropFolder := GetDropFolderPath(LCT);

   GetFilenames(dropFolder); <-- no compile error

end;

What i want is a “distinct” type of string; that is string insofar that it is length prefixed, reference counted, null terminated.

  • 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-06-17T19:39:59+00:00Added an answer on June 17, 2026 at 7:39 pm

    You can use advanced records to accomplish this. For instance, you could do

    type
      TFileName = record
        FFileName: string;
      public
        class function IsValidFileName(const S: string): boolean; static;
        class operator Implicit(const S: string): TFileName;
        class operator Implicit(const S: TFileName): string;
      end;
    
    implementation
    
    class function TFileName.IsValidFileName(const S: string): boolean;
    begin
      result := true {TODO};
    end;
    
    class operator TFileName.Implicit(const S: string): TFileName;
    begin
      if IsValidFileName(S) then
        result.FFileName := S
      else
        raise Exception.CreateFmt('Invalid file name: "%s"', [S]);
    end;
    
    class operator TFileName.Implicit(const S: TFileName): string;
    begin
      result := S.FFileName;
    end;
    

    and similarly for TPath and TFolder. Advantages:

    • A function expecting TPath will not accept a TFileName (or some other combination).
    • You can still assign a TPath to/from a regular string. If you cast from a string to a TPath, you will automatically check the string to see if it contains a valid path.
    • Optionally, you can specify how a TPath can be assigned to a TFileName (or some other combination), by writing more Implicit class operators.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I was reading a blog entry from Scott Gu which has a nice
In an old blog entry titled Cleaner, more elegant, and harder to recognize ,
Im having some issues with deleting an entry from mongo DB. Im using node-mongodb-native
I've been trying to understand this example Ruby code from a blog entry which
I've been using the macro from this blog entry for attaching the Visual Studio
I'm using the code from the below blog entry to re-assign user queries to
In Eric Lippert's blog entry on umpires and the C# compiler and spec, he
I was reading a blog entry by Josh Smith where he used a cache
Scott Hanselman's latest blog entry about the new VS 2010 features mentions the new
This question is in regards to this blog entry. https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/ All the way at

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.