Jump to content

Recommended Posts

The style of construction I saw in the book by Martin Fowler, Domain Specific Languages.

Share this post


Link to post
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
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
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 by dummzeuch

Share this post


Link to post
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 by Marat1961

Share this post


Link to post
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 by Attila Kovacs

Share this post


Link to post
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

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 by Marat1961

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×