You are not logged in.
Pages: 1
TTelefone = class(TSynAutoCreateFields)
protected
fNumero: RawUTF8;
published
property Numero: RawUTF8 read fNumero write fNumero;
end;
TTelefones = array of TTelefone;
TContato = class(TSynAutoCreateFields)
protected
fNome: RawUTF8;
fTelefones: TTelefones;
published
property Nome: RawUTF8 read fNome write fNome;
property Telefones: TTelefones read fTelefones write fTelefones;
end;
TContatos = array of TContato;
TSQLEmpresas = class(TSQLRecord)
protected
fNome: RawUTF8;
fContatos: TContatos;
public
class procedure InitializeTable(Server: TSQLRestServer; const FieldName: RawUTF8;
Options: TSQLInitializeTableOptions); override;
published
property Nome: RawUTF8 index 80 read fnome write fnome;
property Contatos: TContatos read fContatos write fContatos;
end;
class procedure TSQLEmpresas.InitializeTable(Server: TSQLRestServer;
const FieldName: RawUTF8; Options: TSQLInitializeTableOptions);
var
SQLEmpresa: TSQLEmpresas;
Contato: TContato;
begin
inherited InitializeTable(Server, FieldName, Options);
if (FieldName = '') then
begin
SQLEmpresa := TSQLEmpresas.Create;
try
SQLEmpresa.Nome := 'TESTE 1';
With SQLEmpresa.DynArray('Contatos') do begin
Contato := TContato.Create;
Contato.Nome := 'EMPRESA 1';
Contato.Telefones <<<<<------------------ How to create dynamic array here?
Add(Contato);
end;
Server.Add(SQLEmpresa, true);
finally
SQLEmpresa.Free;
end;
end;
end;
Offline
Please don't post such big amount of code in the forum directly, but use a pastebin external website.
Check again the forum rules at https://synopse.info/forum/misc.php?action=rules
For your question, the idea is to use a local dynamic array variable, fill it, then assign it to Contato.Telefones.
Using local variables is much better than using "with" or the "DynArray()" method.
And since they will be copied by reference, using a reference count, it will be instant and won't use any more memory or CPU.
Offline
Sorry for the code posting directly. Thanks for the quick response, it worked using local dynamic arrays.
Offline
Pages: 1