You are not logged in.
Pages: 1
Hello Erick,
Thank you for creating this book. It is great news for us mORMot lovers.
Honestly, what is your advice: buy it now or wait for the updated version?
Thanks. Albert
I'm happy to hear, thank you Arnaud.
Is this the correct way to propose this kind of minor changes?
I am sure there will be more to come ...
Hi,
I am not aware of another way of proposing changes, so please don't flame me. This is a minor thing anyway, so I'll put it here because it's easy to explain.
Reason: allow passing an extra parameter to the mORMotClient.GetClient function - the root of the server. This would allow the client exe to connect to any server
// Modified file: CrossPlatform\templates\CrossPlatform.pas.mustache
interface
function GetModel(aServerRoot: String): TSQLModel;
function GetClient(const aServerAddress{{#authClass}}, aUserName,aPassword{{/authClass}}: string;
aServerPort: integer=SERVER_PORT; aServerRoot: String = '{{root}}'): TSQLRestClientHTTP;
implementation
function GetModel(aServerRoot: String): TSQLModel;
begin
result := TSQLModel.Create([{{#orm}}{{className}}{{comma}}{{/orm}}],aServerRoot);
end;
function GetClient(const aServerAddress{{#authClass}}, aUserName,aPassword{{/authClass}}: string;
aServerPort: integer; aServerRoot: String): TSQLRestClientHTTP;
begin
result := TSQLRestClientHTTP.Create(aServerAddress,aServerPort,GetModel(aServerRoot),true); // aOwnModel=true
try
if (not result.Connect) or (result.ServerTimeStamp=0) then
raise ERestException.CreateFmt('Impossible to connect to %s:%d/%s server',
[aServerAddress,aServerPort,aServerRoot]);
{{#authClass}}
if not result.SetUser({{.}},aUserName,aPassword) then
raise ERestException.CreateFmt('%s:%d/%s server rejected "%s" credentials',
[aServerAddress,aServerPort,aServerRoot,aUserName]);
{{/authClass}}
except
result.Free;
raise;
end;
end;
Cheers,
Albert
Sorry, just a quick answer because I was puzzled by a similar problem right now. Did you run the server exe in adminstrator mode (Windows)?
If this does not apply, please forgive me.
Albert
Thank you AB!
It's nice and clean now, and everything is getting more and more clear.
mORMot rules!
Hello fellow mORMot lovers,
I'm still learning (a lot) and I'm stuck with a simple question.
Here is the situation, I was trying to avoid having a dedicated DTO for some SOA calls and use TSQLRecord descendants instead. I like to retrieve a TSQLContact from the server by the ID, and return a boolean to indicate success. This is the generated code, CrossPlatform, client side:
// this code is generated (mORMotClient.pas)
function TServiceContactAdministration.GetContact(const contactID: Integer; var theContact: TSQLContact): Boolean;
var res: TVariantDynArray;
begin
fClient.CallRemoteService(self,'GetContact',2, // raise EServiceException on error
[contactID,ObjectToVariant(theContact)],res);
theContact := TSQLContact.CreateFromVariant(res[0]);
Result := res[1];
end;
My problem is: how to call this code? If I instantiate theContact before calling, there will be a memory leak. If I don't instantiate theContact, I will have a problem on the server. This is what I'm talking about:
// this is on the server side.
// two options:
// option 1 - create theContact inside the function. This works, but will generate a memory leak
function TContactAdministration.GetContact(const contactID: Integer; var theContact: TSQLContact): Boolean;
begin
theContact := TSQLContact.Create(ServiceContext.Request.Server, contactID); // or CreateJoined
Result := (theContact.ID > 0) and (theContact.ID = contactID)
end;
// option 2 - retrieve theContact (no create) inside the function. This does not work if theContact is not instantiated on the client side
function TContactAdministration.GetContact(const contactID: Integer; var theContact: TSQLContact): Boolean;
begin
// theContact := TSQLContact.Create(ServiceContext.Request.Server, contactID); // or CreateJoined
ServiceContext.Request.Server.Retrieve(ContactID, theContact);
Result := (theContact.ID > 0) and (theContact.ID = contactID)
end;
So, what to do? Do I have to give up using TSQLRecord as parameter?
Pages: 1