Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 09/01/25 in all areas

  1. Stefan Glienke

    A smart case statement in Delphi?

    With a fixed set of strings to look up, hashing is never the fastest way, but a handcrafted way. Let's, for example, imagine a case statement that checks for all keywords in the Pascal language. Arrange the strings in the lookup table by length and first letter. You can see how the C# compiler does it - I wrote a simple demo with just a few keywords: https://sharplab.io/#gist:731036823c89363962d7e79f9dc9ed28 There is a lot of material you can read on that subject: it is called "switch lowering"
  2. Anders Melander

    A smart case statement in Delphi?

    And how is that going for us? There are many, many ways of searching for occurrence of a string in a static set of strings, but hashing certainly isn't the fastest. Hashing is a generic algorithm that doesn't take strings' unique properties into account. A chatbot couldn't have expressed it better - whatever it is.
  3. gkobler

    wuppdi Welcome Page for Delphi 11 Alexandria?

    When officially released then yes
  4. Uwe Raabe

    A smart case statement in Delphi?

    You don't even have to provide that function as long as the strings matches the enum identifiers: s := 'three'; case TRttiEnumerationType<TMyStrings>.GetValue(s) of zero: writeln('zero'); one: writeln('one'); two: writeln('two'); three: writeln('three'); four: writeln('four'); end; Or if you prefer a more readable approach: type TMyStrings = (zero, one, two, three, four); TMyStringsHelper = record helper for TMyStrings public class function FromString(const AString: string): TMyStrings; static; end; class function TMyStringsHelper.FromString(const AString: string): TMyStrings; begin Result := TRttiEnumerationType.GetValue<TMyStrings>(AString); end; ... var s := 'three'; case TMyStrings.FromString(s) of zero: writeln('zero'); one: writeln('one'); two: writeln('two'); three: writeln('three'); four: writeln('four'); else Writeln('What?'); end;
  5. mvanrijnen

    A smart case statement in Delphi?

    there's also the old: IndexText or IndexStr method System.StrUtils.IndexText - RAD Studio API Documentation
  6. Whilst there are many Delphi components for detecting changes to file system folders they suffer from serious limitations: typically they only allow you to monitor a single folder they do not support the monitoring of specific files they rely on the FindFirstChangeNotification API which gives no information about what has changed, requiring an inefficient search. I have created a new file system monitoring library that addresses the above limitations. Features: Easy to use, but also suitable for heavy duty monitoring Single unit with no external dependencies Allows monitoring folders and/or specific files Uses the ReadDirectoryChangesW API which provides information about what exactly was changed A single instance of the component can handle the monitoring of many folders and/or files Uses an I/O completion port for efficient handling of large numbers of requests A single thread handles all requests A different notification handler can be specified for each request You can have multiple handlers for each folder or file When you monitor folders you can specify whether you want to also monitor subfolders Installation: You do not need to install the library. Just download or clone the repo and add the source subdirectory to the Library path. Usage: procedure TForm1.FormCreate(Sender: TObject); begin // Create the IFileSystemMonitor interface FFileSystemMonitor := CreateFileSystemMonitor; // Monitor a directory FFileSystemMonitor.AddDirectory(TPath.GetTempPath, False, HandleChange); // Also monitor a specific file FFileSystemMonitor.AddFile('pathtoyourfile', HandleChange); end; procedure TForm1.HandleChange(Sender: TObject; const Path: string; ChangeType: TFileChangeType); begin with lvEventList.Items.Add do begin Caption := GetEnumName(TypeInfo(TFileChangeType), Integer(ChangeType)); SubItems.Add(Path); end; end; To stop monitoring a specific file or folder you use the following methods: function RemoveDirectory(const Directory: string; OnChange: TMonitorChangeHandler): Boolean; function RemoveFile(const FilePath: string; OnChange: TMonitorChangeHandler): Boolean;
  7. himitsu

    Question about TPasswordEditButton inside TEdit field

    Since other style resources are also missing, I wanted to get an overview of what's in there, but unfortunately, I can't read *.fsf files yet. (It works for *.style) https://www.delphipraxis.net/217749-fmx-style-dateien-auslesen-und-ressourcen-enumerieren.html Project3.zip
  8. Anders Melander

    New file system monitoring component

    Maybe this would be a good occasion to learn Git then... Here's a quick intro I made for someone else that wanted to contribute a change to Graphics32: On Github Create a Github account: https://github.com/signup Fork the Graphics32 repository to your own Github account. This gives you a copy, on your own Github account, of the main repository where you can push your changes. On your local system Clone your own Graphics32 repository to your local system using a Git client. I recommend the Fork git client: https://git-fork.com/ Create a branch in your local repository. Commit your changes to that branch. Push the branch to your own Graphics32 repository. On Github Create a pull request on your Graphics32 repository. Specify the master branch at the main Graphics32 repository as the target, and your branch at your repository as the source. When Github notifies me that you have submitted a pull request I'll review the changes. Once I accept the pull request, the changes are merged into the branch you specified as the target branch.
  9. Tommi Prami

    New file system monitoring component

    Fork the repository from the GitHUB, make changes and make pull request. Details really depends will you use commndline tool(s) or some GUI tool. I mainly use Theirs GitHUB Desktop https://desktop.github.com/download/ It is very simple on most operations, and this is why I kind of like it. -tee-
  10. A.M. Hoornweg

    A smart case statement in Delphi?

    A case statement for strings can be created using generics. Not the fastest (it does a linear probe) but quite practical sometimes. Var s:String; begin s:='three'; CASE tarray.Indexof<string> (tarray<string>.create( 'zero', 'one', 'two', 'three', 'four'), s) of 0:writeln('zero'); 1:writeln('one'); 2:writeln('two'); 3:writeln('three'); 4:writeln('four'); end; end;
×