Marat1961 17 Posted October 28, 2020 The style of construction I saw in the book by Martin Fowler, Domain Specific Languages. Share this post Link to post
Lars Fosdal 1792 Posted October 28, 2020 @Attila Kovacs What about System.IOUtils.TPath.Combine? 1 Share this post Link to post
Kryvich 165 Posted October 28, 2020 1 hour ago, mvanrijnen said: Good idea with the pointer, you do have to encode somevalues in the stringbuilder (escape special chars etc) maybe with an TInterfaced (no need to free) With Marat's proposal, you should not explicitly free the memory. Moreover, the record will be located in the stack, as opposed to the object. Share this post Link to post
Marat1961 17 Posted October 28, 2020 2 hours ago, mvanrijnen said: maybe with an TInterfaced (no need to free) The records do not need to be freed if there are local managed variables, the finalization code is executed before returning from the subroutine. // procedure _FinalizeRecord(p: Pointer; typeInfo: Pointer); 005FD905 8D45D8 lea eax,[ebp-$28] 005FD908 8B1530CF5F00 mov edx,[$005fcf30] 005FD90E E829D6E0FF call @FinalizeRecord 005FD913 C3 ret Share this post Link to post
dummzeuch 1505 Posted October 28, 2020 (edited) 7 hours ago, Marat1961 said: type PxUri = ^TxUri; TxUri = record public function Init(const Scheme, Path: string; Port: Cardinal = 0): PxUri; function Host(const Value: string): PxUri; end; implementation function TxUri.Init(const Scheme, Path: string; Port: Cardinal): PxUri; begin Result := @Self; end; function TxUri.Host(const Value: string): PxUri; begin Result := @Self; end; Now that's a cool idea. I'm going to rewrite my FileFilterBuilder which currently is class / interface based in this way. Thanks a lot. Edited October 28, 2020 by dummzeuch Share this post Link to post
Marat1961 17 Posted October 28, 2020 (edited) 3 hours ago, mvanrijnen said: MP2 := THSURI2.HTTPS A non-empty scheme component followed by a colon (:), consisting of a sequence of characters beginning with a letter and followed by any combination of letters, digits, plus (+), period (.), or hyphen (-). Although schemes are case-insensitive, the canonical form is lowercase and documents that specify schemes must do so with lowercase letters. Examples of popular schemes include http, https, ftp, mailto, file, data, and irc. URI schemes should be registered with the Internet Assigned Numbers Authority (IANA), although non-registered schemes are used in practice. If we analyze the syntax diagram, we can see that the "non-empty scheme component" and "path component" are required, which is why we included them in Init. A port value of 0 is reserved and means no port is specified. If the value can be present in the URI one time, its value will be replaced by the last usage. The builder is syntax-sensitive and helps to avoid errors when generating URI. Edited October 28, 2020 by Marat1961 Share this post Link to post
Attila Kovacs 629 Posted October 28, 2020 (edited) 23 hours ago, Lars Fosdal said: What about System.IOUtils.TPath.Combine? I don't know, it's URL not a Path, and PathSeparator etc.. are class vars, I would not touch it for a second. ah, it's a record, in this case that's what I did not find. I knew there was something but could not remember what, thx. Edit: I tried TPath.Combine and I can't alter the separator char. Either I'm missing something or it's just for file paths. Edited October 29, 2020 by Attila Kovacs Share this post Link to post
Lars Fosdal 1792 Posted October 29, 2020 13 hours ago, Attila Kovacs said: I don't know, it's URL not a Path, and PathSeparator etc.. are class vars, I would not touch it for a second. ah, it's a record, in this case that's what I did not find. I knew there was something but could not remember what, thx. Edit: I tried TPath.Combine and I can't alter the separator char. Either I'm missing something or it's just for file paths. That would be poor design of a class lib, IMO. 😞 Unfortunately not a rare thing in newer Delphi releases. Share this post Link to post
Marat1961 17 Posted November 2, 2020 (edited) System.IOUtils.TPath used for operating the OS file system. File and directory names. At first I missed that the topic was about URLs and I decided that it was about files. The URL is designed to work with Internet entities. Edited November 2, 2020 by Marat1961 Share this post Link to post