You are not logged in.
Pages: 1
type
TNamesVO = class
private
fname : String;
published
property name : String read fname write fname;
end;
type
TExtjsVO = class
private
fsuccess : boolean;
frows : TList;
ftotal : integer;
published
property success : boolean read Fsuccess write Fsuccess;
property rows : TList read Frows write Frows;
property total : integer read Ftotal write Ftotal;
end
.
.
.
var
ExtjsVO : TExtjsVO;
List : TList;
Names : TNamesVO;
begin
ExtjsVO := TExtjsVO.Create;
List := TList.Create;
Names := TNamesVO.Create;
Names.name := 'Test';
List.Add(Names);
try
ExtjsVO.success := True;
ExtjsVO.rows := List;
ExtjsVO.total := 1;
MemoServer.Lines.Text := ObjectToJson(ExtjsVO);
finally
List.Clear;
FreeAndNil(List);
FreeAndNil(ExtjsVO);
end;
it returns:
{"success":null,"rows":[{"name":"Test"}],"total":1}
should not it be?
{"success":true,"rows":[{"name":"Test"}],"total":1}
in delphi it does correct.
My Code:
type
TTestItensVO = class(TCollectionItemAutoCreateFields)
private
fitems_id : Integer;
fitems_descriptions : RawUTF8;
published
property items_id : Integer read fitems_id write fitems_id;
property Itens_descriptions : RawUTF8 read fitems_descriptions write fitems_descriptions;
end;
TTestItensVOSubVO = class(TInterfacedCollection)
private
function GetCollItem(aIndex: Integer): TTestItensVO;
protected
class function GetClass: TCollectionItemClass; override;
public
property Item[aIndex: Integer]: TTestItensVO read GetCollItem; default;
function Add: TTestItensVO;
end;
type
TTestVO = class
private
fcode : Integer;
fname : String;
fanswers : String;
ftotal : Real;
fitems : TTestItensVOSubVO;
published
property code : integer read fcode write fcode;
property name : string read fname write fname;
property answers : string read fanswers write fanswers;
property total : real read ftotal write ftotal;
property items : TTestItensVOSubVO read fitems write fitems;
constructor Create;
destructor Destroy; override;
end;
.
.
constructor TTestVO.Create;
begin
items := TTestItensVOSubVO.Create;
end;
destructor TTestVO.Destroy;
begin
FreeAndNil(fitems);
inherited;
end;
function TTestItensVOSubVO.Add: TTestItensVO;
begin
result := TTestItensVO(inherited Add);
end;
class function TTestItensVOSubVO.GetClass: TCollectionItemClass;
begin
result := TTestItensVO;
end;
function TTestItensVOSubVO.GetCollItem(aIndex: Integer): TTestItensVO;
begin
result := TTestItensVO(GetItem(aIndex));
end;
.
.
procedure TFormTest.SBObjectListClick(Sender: TObject);
var
StringJson : RawUTF8;
ListObj : TList;
Itens : Integer;
Elements : Integer;
TestVO : TTestVO;
begin
StringJson :='[{"code": 1,"name": "Margaret","answers": "yes","total": 10,"items": [{"items_id": 1,"items_descriptions": "item1"},{"items_id": 2,"items_descriptions": "item2"}]},' +
'{"code": 2,"name": "Mary","answers": "no","total": 20,"items":[{"items_id": 3,"items_descriptions": "item3"},{"items_id": 4,"items_descriptions": "item4"}]}]';
ListObj := JSONToObjectList(TTestVO,StringJson);
try
for Itens := 0 to ListObj.Count -1 do
begin
TestVO := ListObj[Itens];
ShowMessage(TestVO.name);
for Elements := 0 to TestVO.items.Count -1 do
ShowMessage('Item: ' + IntToStr(TestVO.items.Item[Elements].items_id) + ' Descriptions: ' + TestVO.items.Item[Elements].Itens_descriptions);
end;
finally
FreeAndNil(ListObj);
end;
end;
this code error:
First chance exception at $00710079. Exception class $C0000005 with message 'access violation at 0x00710079: read of address 0x00000008'. Process Teste.exe (11100)
Perfect, thank you...
type
TTestVO = class
private
fcode : Integer;
fname : String;
fanswers : String;
ftotal : Real;
published
property code : integer read fcode write fcode;
property name : string read fname write fname;
property answers : string read fanswers write fanswers;
property total : real read ftotal write ftotal;
end;
var
StringJson : RawUTF8;
ListObj : TList;
Itens : Integer;
TestVO : TTestVO;
begin
StringJson :='[{"code": 1,"name": "Margaret","answers": "yes","total": 10},{"code": 2,"name": "Mirian","answers": "no","total": 20}]';
ListObj := JSONToObjectList(TTestVO,StringJson);
try
for Itens := 0 to ListObj.Count -1 do
TestVO := ListObj[Itens];
finally
for Itens := 0 to ListObj.Count - 1 do
TTestVO(ListObj.Items[Itens]).Free;
FreeAndNil(ListObj);
end;
I am trying to remove this object from memory and I have the following error:
"Invalid pointer operation."
I need to use HTTPS with mormot is there any example of how to do this ??
thanks.
sorry if it's a stupid question.
but the example:
https://github.com/synopse/mORMot/blob/ … Server.dpr
there is not a port number
as you would in the browser?
http://localhost:8050/root/sum ??
sorry my little experience, but I use ExtJs 6.01 as a customer.
would like to access a method with serverservice not have PORTNUMBER
http://localhost:8050/root/myobjectJSON
I'm sending an object JSON with the POST method by ExtJs 6.01.
the object is inside request payload or (http request body).
I would like to capture the object with class(TSQLHttpServer) is possible?
sorry if not expressed myself well.
how I capture methodos CREATE /GET / PUT / DELETE using TSQLHttpServer
I not found any examples of how to do this
I use Firebird 2.5 delphi 10 seatlle
thanks for the answer
How to create a restful class as using mormot
the TSQLHttpServer
but need to use restful, I use firebird and needed to have access to methods PUT / GET / DELETE
mormot are only example I use sqlite firebird
I have used directly as below but need RESTful.
unit UnitJson;
interface
uses
SynCommons, mORMot, mORMotHttpServer,mORMotReport,
System.SysUtils,Vcl.Forms, Winapi.Windows, System.Classes,Contnrs,XSBuiltIns,System.StrUtils;
type
TMyService = class(TSQLRestServerFullMemory)
published
procedure myapp(Ctxt: TSQLRestServerURIContext);
end;
TMyHTTPServer = class(TSQLHttpServer)
private
oModel: TSQLModel;
oSQLRestServerFullMemory: TMyService;
public
Model : TSQLModel;
function ServiceRegister(AImplementationClass: TInterfacedClass; const AInterfaces: PTypeInfo;const AContractExpected: RawUTF8): boolean;
constructor Create(const APorta: RawUTF8; AThreadPoolCount: Integer); reintroduce;
destructor Destroy; override;
end;
// Class Return
['{E6C6ADFD-5977-4759-B400-AA4140F1D683}']
function cadastrosCrud(acao,tabela,conteudo,ordem,ativo,start,limit,chave:String;StrJson:RawUTF8): RawJSON;
end;
TMyClassDirect = class(TInterfacedObject, IMyInterface)
public
function cadastrosCrud(acao,tabela,conteudo,ordem,ativo,start,limit,chave:String;strjson:RawUTF8): RawJSON;
end;
implementation
{ TMyService }
procedure TMyService.myapp(Ctxt: TSQLRestServerURIContext);
var
sFileName: TFileName;
begin
sFileName := Ctxt.ResourceFileName;
if sFileName = '' then
Ctxt.Redirect('myapp/index.html')
else
Ctxt.ReturnFile(ExtractFilePath(Application.ExeName) + sFileName, true);
end;
{ TMyHTTPServer }
constructor TMyHTTPServer.Create(const APorta: RawUTF8; AThreadPoolCount: Integer);
begin
oModel := TSQLModel.Create([], 'app');
oSQLRestServerFullMemory := TMyService.Create(oModel, '', false, false);
inherited Create(APorta, [oSQLRestServerFullMemory], '+', useHttpApiRegisteringURI, AThreadPoolCount);
end;
function TMyHTTPServer.ServiceRegister(AImplementationClass: TInterfacedClass; const AInterfaces: PTypeInfo; const AContractExpected: RawUTF8): boolean;
begin
oSQLRestServerFullMemory.ServiceRegister(AImplementationClass,[AInterfaces], sicSingle).ContractExpected := AContractExpected;
Result := true;
end;
destructor TMyHTTPServer.Destroy;
begin
FreeAndNil(oModel);
FreeAndNil(oSQLRestServerFullMemory);
inherited;
end;
{ TMyClassDirect }
function TMyClassDirect.cadastrosCrud(acao,tabela,conteudo,ordem,ativo,start,limit,chave:String;strjson:RawUTF8): RawJSON;
var
ExtjsVO : TExtjsVO;
ListaCadastros : TList;
CadastrosControl : TCadastrosController;
begin
ExtjsVO := TExtjsVO.Create;
ListaCadastros := TList.Create();
CadastrosControl := TCadastrosController.Create;
try
if CadastrosControl.Crud_Cadastros(acao,tabela,conteudo,ordem,ativo,start,limit,chave,ListaCadastros,strjson) then
begin
ExtjsVO.rows := ListaCadastros;
ExtjsVO.success := true;
ExtjsVO.total := CadastrosControl.Registros;
end
else
begin
ExtjsVO.success := False;
ExtjsVO.total := 0;
end;
except
on E: Exception do
begin
ExtjsVO.success := False;
ExtjsVO.rows := ListaCadastros;
ExtjsVO.total := 0;
end;
end;
Result := ObjectToJson(ExtjsVO,[]);
FreeAndNil(ExtjsVO);
FreeAndNil(ListaCadastros);
FreeAndNil(CadastrosControl);
Manager.CloseConnectionDef('Firebird_Pooled');
end;
end.
sorry i read all the documentation
but still did not understand
my client is extjs 4
only understands json
so I can not send as Interface
if you can help with an example in direct mode?
sorry if I did not understand me
I just want to get a pdf server and render on the client using httpserver
researched and found not to do
I'm starting in mormot
this already implemented
My problem is how to send PDF to the client
function TMyClassDirect.relatorio(): RawJSON;
var
ExtjsVO : TExtjsVO;
ListaRelatorio : TList;
RelatorioVO : TRelatorioVO;
FS : TFileStream;
begin
ExtjsVO := TExtjsVO.Create;
ListaRelatorio := TList.Create();
RelatorioVO := TRelatorioVO.Create;
try
FS := TFileStream.Create('\pdf\pedido.pdf', fmCreate);
RelatorioVO.LISTA := FS;
ListaRelatorio.Add(RelatorioVO);
ExtjsVO.success := true;
ExtjsVO.rows := ListaRelatorio;
ExtjsVO.total := Registros;
except
ExtjsVO.success := False;
ExtjsVO.rows := ListaRelatorio;
ExtjsVO.total := 0;
end;
Result := ObjectToJson(ExtjsVO,[]);
FreeAndNil(ExtjsVO);
FreeAndNil(ListaRelatorio);
FreeAndNil(RelatorioVO);
FreeAndNil(FS);
end;
return:
{"result":[{"success":false,"rows":[],"total":0}]}
I generated a report using FastReport and would like to send to client extjs, what steps?
I am using Delphi XE7 with mormot.
I would like to fill a DataSet with a JSON
I'm trying like this but I'm not getting it.
someone help me?
TB_MANAGER := TDataSet.Create(nil);
TB_MANAGER := JSONToDataSet(self, '{"ID":"00001","NAME":"MANAGER E CIA LTDA"}');
TB_MANAGER.Open;
DS_MANAGER := TDataSource.Create(nil);
DS_MANAGER.DataSet := TB_MANAGER;
DBGridManager.DataSource := DS_MANAGER;
thanks !!
iI am trying to fill a dataset with the json
follows and I am not getting,
someone help me with a sample ?.
fData := TSQLTableJSON.Create([],'','{"ID":"00001","NAME":"MANAGER E CIA LTDA"}');
fDataSet := TDataSet.Create(nil);
fDataSet := JSONToDataSet(self, fData);
fDataSet.Open;
showmessage(IntToStr(fDataSet.recordCount));
my app return :
{"result":[{"success":true,"rows":[{"CODIGO":"00001","NOME":"JOSE"}],"total":2}]}
I would like the result to be;
{"success":true,"rows":[{"CODIGO":"00001","NOME":"JOSE"}],"total":2}
I published the method:
Result := ObjectToJson(ExtjsObject, []);
it is possible to remove?
sorry I'm starting at mormot
cido
Pages: 1