#1 2024-08-05 15:13:11

phss_phss
Member
Registered: 2024-08-05
Posts: 6

How to make a CopyRecord in Free Pacal?

I'm trying to migrate my code from Delphi to Free Pascal and I'm facing the chalange of make the CopyRecord metod from System in Delphi to Free Pascal.
I have the const pSolicitacao: TDTOSolicitacao and the var vSolicitacao: TDTOSolicitacao;
In my code I have to copy pSolicitacao to vSolicitacao because my function GetPosto is gonna change values from the record:

function TSolicitacaoService.Add(const pSolicitacao: TDTOSolicitacao): TServiceCustomAnswer;
var
  vSolicitacao: TDTOSolicitacao;
begin
  CopyRecord(@vSolicitacao, @pSolicitacao, TypeInfo(TDTOSolicitacao));
  if not GetPosto(vSolicitacao) then
  begin
    Result := ReturnRecordNotFound('Posto não encontrado.');
    Exit;
  end;
  etc...
end;

Anyone to help me with this migration?

Offline

#2 2024-08-05 16:30:05

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: How to make a CopyRecord in Free Pacal?

You can use RecordCopy() from mormot.core.rtti for this purpose, without any @ pointer:

RecordCopy(vSolicitacao, pSolicitacao, TypeInfo(TDTOSolicitacao));

Generally, you have in mORMot everything you need for cross-compiler code.

Offline

#3 2024-08-05 21:17:48

mrbar2000
Member
From: Brazil
Registered: 2016-10-26
Posts: 88

Re: How to make a CopyRecord in Free Pacal?

Tnks AB

Offline

Board footer

Powered by FluxBB