Jump to content
merijnb

buOverbyteIcsHttpSrv.THttpServer.Create

Recommended Posts

One of the first things the constructor of THttpServer does is setting FName of FWSocketServer, using the current ClassName as a basis:

 

constructor THttpServer.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    CreateSocket;
{$IFDEF NO_ADV_MT}
    FWSocketServer.Name := ClassName + '_SrvSocket' + IntToStr(WSocketGCount);
{$ELSE}
    FWSocketServer.Name := ClassName + '_SrvSocket' + IntToStr(SafeWSocketGCount);

 

The name of a component can only consist of 'A'..'Z', 'a'..'z', '_', '0'..'9' as can been seen in System.SysUtils.IsValidIdent() (called from System.SysUtils.TComponent.SetName())

 

If you define a class, overriding form THttpServer as part of another class:


 

type TMyClass = class(TObject)

private

 type TMyHttpServer = class(THttpServer)

The ClassName of TMyHttpServer will become TMyClass.TMyHttpServer, so it contains a dot, hence breaking the constructor of THttpServer.

 

Fix could be to do a StringReplace() to eliminate dots in the constructor:

 

constructor THttpServer.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    CreateSocket;
{$IFDEF NO_ADV_MT}
    FWSocketServer.Name := StringReplace(ClassName + '_SrvSocket' + IntToStr(WSocketGCount), '.', '', [rfReplaceAll]);
{$ELSE}
    FWSocketServer.Name := StringReplace(ClassName + '_SrvSocket' + IntToStr(SafeWSocketGCount), '.', '', [rfReplaceAll]);

 

Share this post


Link to post

I just noticed the title of this thread isn't what it's supposed to be, it should be bug in OverbyteIcsHttpSrv.THttpServer.Create  🙂

Share this post


Link to post

I'm not sure that this is actually a problem, since ICS already has various derived components like: THttpAppSrv = class(THttpServer) which don't give any errors. 

 

But I don't see any purpose in setting the name FWSocketServer.Name either, it might have been used for debugging a long time ago, but I've just removed it from my copy so your problem will go away, unless anything thinks the name is needed?

 

Angus

 

 

 

Share this post


Link to post
4 minutes ago, Angus Robertson said:

I'm not sure that this is actually a problem, since ICS already has various derived components like: THttpAppSrv = class(THttpServer) which don't give any errors. 

 

But I don't see any purpose in setting the name FWSocketServer.Name either, it might have been used for debugging a long time ago, but I've just removed it from my copy so your problem will go away, unless anything thinks the name is needed?

 

Angus

 

 

 

Hey Angus,

 

I have no need for the name (I wondered why it was set), the reason THttpAppSrv doesn't have this error is because the class definition is not part of another class definition.

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
×