Forum > Databases

External Access violation on tbufdataset.Post

(1/1)

hamacker:
Hi All,
I try to transfer data from query to tbufdataset, but when I try tbufdataset.Post, External Access violation ocourrs and I dont know why.
There is someting wrong in mycode?
Lazarus 2.2rc2 and FPC 3.2.2
It´s my first time using bufdataset, try to simulate a clientdataset(delphi).
      MemCesta.FieldDefs.Clear; // TBufDataset creation
      MemCesta.FieldDefs.Add('uuid_cesta', ftString, 36);
      MemCesta.FieldDefs.Add('uuid_colaborador', ftString, 36);
      MemCesta.FieldDefs.Add('uuid_epi', ftString, 36);
      MemCesta.FieldDefs.Add('id_ca', ftString, 30);
      MemCesta.FieldDefs.Add('epi_nome', ftString, 120);
      MemCesta.FieldDefs.Add('quantidade', ftInteger, 0);
      MemCesta.FieldDefs.Add('dt_expiracao_calc', ftDate, 0);
      MemCesta.CreateDataset;
      MemCesta.IndexDefs.Add('uuid_cesta','uuid_cesta',[ixPrimary]);
      MemCesta.IndexDefs.Add('por_epi','uuid_colaborador;uuid_epi;id_ca',[ixCaseInsensitive]);
      MemCesta.IndexFieldNames:='uuid_colaborador;uuid_epi;id_ca';
      if not MemCesta.active then
        MemCesta.Open;         
(...)
        MemCesta.Append;
        MemCesta.FieldbyName('uuid_cesta').AsString:=q1.FieldbyName('uuid_cesta').AsString;
        MemCesta.FieldbyName('uuid_colaborador').AsString:=q1.FieldbyName('uuid_colaborador').AsString;
        MemCesta.FieldbyName('uuid_epi').AsString:=q1.FieldbyName('uuid_epi').AsString;
        MemCesta.FieldbyName('id_ca').AsString:=q1.FieldbyName('id_ca').AsString;
        MemCesta.FieldbyName('epi_nome').AsString:=q1.FieldbyName('epi_nome').AsString;
        MemCesta.FieldbyName('dt_expiracao_calc').AsDateTime:=StrToDate('01/01/1970');
        if q1.FieldbyName('dt_expiracao').AsDateTime>Date_Valid_Min then
          MemCesta.FieldbyName('dt_expiracao_calc').AsDateTime:=q1.FieldbyName('dt_expiracao').AsDateTime;
        MemCesta.FieldbyName('quantidade').AsInteger:=iQuantidade;
        MemCesta.Post;    <-- AV Error, why?

hamacker:
Reply to myself.
Dont use property Fields wich the same name of TFields of BufDataset:
(...)
  published
    property UUID_Colaborador:String read FUUID_Colaborador write SetUUID_Colaborador; 
and
(...)
      MemCesta.FieldDefs.Clear; // TBufDataset creation
      MemCesta.FieldDefs.Add('uuid_cesta', ftString, 36);
      MemCesta.FieldDefs.Add('uuid_colaborador', ftString, 36); // <-- will create Access Violation
(...)

egsuh:
Think of

        MemCesta.CopyFromDataSet(q1); 

withouting redefining all the fields.

Navigation

[0] Message Index

Go to full version