Inherit from TRORemoteDataModule


(Benjamin Keffer) #1

Hey,

is it possible to inherit from TRORemoteDataModule to implement some basic logging functions?
Doing this like = class(TRORemoteDataModule ) won’t work. Any experiences?

Thanks!


(EvgenyK) #2

Hi,

yes, you can.
check our samples - almost each sample contains line, like

  TPhotoServerService = class(TRORemoteDataModule, IPhotoServerService)

(Benjamin Keffer) #3

Nah I’m looking for a solution to do something like this

TPhotoServerService = class(TBaseRemoteDataModule, IPhotoServerService)

So I don’t need to implement the same logging methods for each microservice.

I want to extend your TRORemoteDataModule for future use.


(EvgenyK) #4

Why you can’t use class helper?

also you can create own descendant from TRORemoteDataModule , add some methods into it and inherit your services from this logging service


(Benjamin Keffer) #5

class helper are dirty :stuck_out_tongue:

own descendant from TRORemoteDataModule

Would be great but doesn’t work. The DataModule will be converted to a formular. Therefore the question.


(EvgenyK) #6

how then our DataAbstract Service works w/o problems? :slight_smile:

base service:

TDataAbstractService = class(TRORemoteDataModule, ...

how it was used:

  TDataService = class(TDataAbstractService, IDataService)

try to remove {$R *.dfm} from your _Impl with logging service


(Benjamin Keffer) #7

Test.zip (4.9 MB)

Doesn’t work :-/


(EvgenyK) #8

everything works.
check testcase: Testcase.zip (110.3 KB)


(Benjamin Keffer) #9

Magic :smiley:
I didn’t implement a .dfm that was the mistake. Thaks for your help!


(Benjamin Keffer) #10

Is there any possibility to inherit from LoggingService without creating a LogginService.dfm?


(EvgenyK) #11

if I remove LogService_Impl.dfm and update LogService_Impl.pas as

unit LogService_Impl;

// ----------------------------------------------------------------------
//  This file was automatically generated by Remoting SDK from a
//  RODL file downloaded from a server or associated with this project.
//
//  This is where you are supposed to code the implementation of your objects.
// ----------------------------------------------------------------------

{$I RemObjects.inc}

interface

uses
  {$IFDEF DELPHIXE2UP}System.SysUtils{$ELSE}SysUtils{$ENDIF},
  {$IFDEF DELPHIXE2UP}System.Classes{$ELSE}Classes{$ENDIF},
  {$IFDEF DELPHIXE2UP}System.TypInfo{$ELSE}TypInfo{$ENDIF},
  uROEncoding,
  uROXMLIntf,
  uROClientIntf,
  uROClasses,
  uROTypes,
  uROServer,
  uROServerIntf,
  uROSessions,
  uRORemoteDataModule,
  TestLibrary_Intf;

const __ServiceName = 'LogService';
type
  { Forward declarations }
  TLogService = class;

  TLogService = class(TRORemoteDataModule, ILogService)
  public
    procedure Log(const NewParam: UnicodeString); virtual;
  end;

implementation

{$IFDEF DELPHIXE2UP}
  {%CLASSGROUP 'System.Classes.TPersistent'}
{$ENDIF}

uses
  fServerForm,
  TestLibrary_Invk;

var fClassFactory_LogService: IROClassFactory;

procedure Create_LogService(out anInstance: IInterface);
begin
  anInstance := TLogService.Create(nil);
end;

procedure TLogService.Log(const NewParam: UnicodeString);
begin
  ServerForm.Log(NewParam);
end;

initialization
  fClassFactory_LogService := TROClassFactory.Create(__ServiceName, {$IFDEF FPC}@{$ENDIF}Create_LogService, TLogService_Invoker);
  // RegisterForZeroConf(fClassFactory_LogService, '_LogService_rosdk._tcp.');
finalization
  UnRegisterClassFactory(fClassFactory_LogService);
  fClassFactory_LogService := nil;
end.

everything works correctly


(Benjamin Keffer) #12

There will be a conflict with

inherited TestService: TTestService
end


(EvgenyK) #13

if you are using

object TestService: TTestService
end

form will be shown incorrectly (as a descendant of TForm)

but with

inherited TestService: TTestService
end

everything is ok


(Benjamin Keffer) #14

It will be okay at runtime but at design time an error will occur (what isn’t that dramatic) because
TLogService.dfm isn’t found.


(EvgenyK) #15

why you want to remove LogginService.dfm?


(Benjamin Keffer) #16

Because then I need to reference LogginService.dfm and LogginService.pas in each microservice (and I have a lot of them…). A global path isn’t enough.