#1 2024-07-30 19:19:43

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

Free Pacal issues

I'm finding some errors when try to compile my project in FPC.

function TAmostraService.InsertMany(pAmostras: variant): TServiceCustomAnswer;
var
  vListaAmostras: IDocList;
  vItemAmostra: variant;
  vAmostra: TAmostra;
begin
  vAmostra := TAmostra.Create;
  try
    // delphi compiles, fpc no (Sorotrack.AmostraService.pas(339,23) Error: Can't determine which overloaded function to call)
    vListaAmostras := DocListFrom(pAmostras.amostras);
    for vItemAmostra in vListaAmostras do
    begin
      // delphi compiles, fpc no. what do do? Sorotrack.AmostraService.pas(343,38) Error: Incompatible types: got "OleVariant" expected "UTF8String"
      vAmostra.Numero := vItemAmostra.Numero;
      // delphi compiles, fpc no. what do do?
      // Sorotrack.AmostraService.pas(347,31) Error: Incompatible types: got "Pointer" expected "TSolicitacao"
      vAmostra.Solicitacao := Pointer(PtrInt(vItemAmostra.Solicitacao));
      vAmostra.Exames := vItemAmostra.Exames;
      vAmostra.DataEtiqueta := vItemAmostra.DataEtiqueta;
      vAmostra.Empresa := Pointer(PtrInt(CurrentUserCompany));
      Result := Add(vAmostra);
    end;
  finally
   vAmostra.Free;
  end;
end;  

I've alredy read at the documentacion the part about FPC Clients here:  https://synopse.info/files/html/Synopse … m*%20units , but it didn't works for me. Can someone help me with this issues?

Offline

#2 2024-07-30 19:36:38

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

Re: Free Pacal issues

Seems like a FPC limitation: the conversion should be explicit with late binding, like

  vAmostra.Numero := VariantToUtf8(vItemAmostra.Numero);

Instead of using late binding and IDocList, I would use a PDocVariantData() and its methods.

var
  vListAmostras, vItemAmostra: PDocVariantData;   
..
  vListAmostras := _Safe(paMostras.amostras);
  for vItemAmostra in vListAmostras.Objects do
  begin
    vAmostra.Numero := vItemAmostra.U['Numero'];
  ...
end;

Offline

#3 2024-07-30 20:46:53

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

Re: Free Pacal issues

pAmostras: Variant receive a int64 number => Solicitacao: 123

vAmostra.Solicitacao: TAmostra(TOrm)

How can i pass this integer as  TID to works in delphi and freepascal?

vAmostra.Solicitacao := Pointer(PtrInt(vItemAmostra.Solicitacao));

tnks

Offline

#4 2024-07-31 08:25:00

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

Re: Free Pacal issues

It is safer to define this property as a real TID and NOT a TOrm, if you don't use TOrmMany features.
It would be much less confusing.

And take a look at my code using PDocVariantData: it is safer than using late binding.
You can just write, with your TID property:

vAmostra.Solicitacao := vITemAmostra.I['Solicitacao']

Offline

#5 2024-07-31 13:15:24

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

Re: Free Pacal issues

There are something way to store null instead 0 on Solicitacao?

0 will raise foreign key error.

I find TNullableID or TIDNullable wothout success!

Offline

#6 2024-07-31 16:52:42

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

Re: Free Pacal issues

The foreign key is defined in your own SQL I guess, not by the ORM.
It is not supported.

Offline

Board footer

Powered by FluxBB