#1 mORMot 1 » RTTI has some problem with Delphi 2010 » 2011-03-24 02:38:58

thunya
Replies: 2

I try to test ObjectToJSON function from TCollection object.
No JSON content generate from that object.
Then I track down to TJSONSerializer.WriteObject.

tkClass: begin
  Obj := pointer(GetOrdProp(Value,pointer(P)));  // works also for CPU64
  if IsTSQLRecord then begin
    if not P^.PropType^^.ClassType.InheritsFrom(TSQLRecordMany) then begin
      HR(P);
      Add(PtrInt(Obj));
    end;
  end else
  if Obj<>nil then begin
    HR(P);
    if Obj.InheritsFrom(TCollection) then begin
      HR;
      ...
      ...
Obj := pointer(GetOrdProp(Value,pointer(P)));  // works also for CPU64

Always return nil to Obj. No JSON content generated

#2 mORMot 1 » JSON RESTful Services, How to implement server method with obj param » 2011-03-22 03:33:48

thunya
Replies: 5

I plan to implement server service that accept new object as parameter and process in server memory.

The formation is...
-Client call server function that accept some object as parameter [AFunction(obj: TSampleRecord)]
-Server decode json object to TSampleRecord
-Server process something with object(TSampleRecord) then save object to database and return result

Could you show some example code to guidance me?

thanks smile

#3 Re: mORMot 1 » Object Inheritance Mapping » 2011-03-22 02:42:54

Now I get the latest version in repository. It's work like charm. The mapping is table per concrete class.
I can use it now in my little project smile

To implement custom logic on server, and use JSON serialization, you've already server-side RESTful services features included in the framework.

If you recommended this method I will try it smile
I have some question about this method, I will post in new topic for easy to find wink

#4 Re: mORMot 1 » Object Inheritance Mapping » 2011-03-21 15:22:58

1.13? really? Can't wait to see it!!!
I really like this framework. It's ORM, Testable, JSON, Http, Fast, Smart etc.

Could you add some sample to show how to implement custom logic on http server when receiving JSON object?
I plan to inherit TSQLite3HttpServer and override Request function.
But the code is too complicate for me to decode smile

#5 Re: mORMot 1 » Object Inheritance Mapping » 2011-03-20 15:09:40

Maybe I doing some mistake. I extend "HTTP Client-Server" sample.
My class model is..

  TSQLSampleRecord = class(TSQLRecord)
  private
    fName: RawUTF8;
    fQuestion: RawUTF8;
    fTime: TDateTime;
  published
    property Name: RawUTF8 read fName write fName;
    property Question: RawUTF8 read fQuestion write fQuestion;
    property Time: TDateTime read fTime write fTime;
  end;

  TSQLInherited = class(TSQLSampleRecord)
  private
    FValue: Integer;
  published
    property Value: Integer read FValue write FValue;
  end;

Then... CreateSampleModel

function CreateSampleModel: TSQLModel;
begin
  result := TSQLModel.Create([TSQLSampleRecord, TSQLInherited]);
end;

On client side....

procedure TForm1.InheritedButtonClick(Sender: TObject);
var Rec: TSQLInherited;
begin
  Rec := TSQLInherited.Create;
  try
    Rec.Time := Now;
    // we use explicit StringToUTF8() for conversion below
    // a real application should use TLanguageFile.StringToUTF8() in SQLite3i18n
    Rec.Name := StringToUTF8(NameEdit.Text);
    Rec.Question := StringToUTF8(QuestionMemo.Text);
    Rec.Value := Random(100);
    if Database.Add(Rec,true)=0 then
      ShowMessage('Error adding the data') else begin
      NameEdit.Text := '';
      QuestionMemo.Text := '';
      NameEdit.SetFocus;
    end;
  finally
    Rec.Free;
  end;
end;

Result in database
inherited.jpg

The data saved to Inherited table with 1 property(Value), Other property is missing
inherited_Value.jpg

#6 mORMot 1 » Object Inheritance Mapping » 2011-03-19 04:46:38

thunya
Replies: 9

Hard to believe no one ask these question.
Is this framework support "Object Inheritance Mapping" ?

How? or When?

Board footer

Powered by FluxBB