Invalid Pointer Operation - Delphi

Asked

Viewed 1,410 times

1

I added a Tclientdataset(cdsTemp) to my Form screen, well, and I implement the Fields of that Tclientdataset(cdsTemp) via code, that way:

for i := 0 to (cdsAux.Fields.Count - 1) do cdsTemp.Fields.Add(cdsAux.Fields[i]);

Notice that I’m playing cdsAux Fields for cdsTemp, I don’t know if it’s the right way to do it, but it’s the one I found, adapted and is working.

So far so good and working, however, when I run the application it passes the fields from cdsAux to cdsTemp good, but when I close the form gives the error "Invalid Pointer Operation". If I comment to the trial that is doing this procedure of playing the fields from cdsAux to cdsTemp the error does not happen anymore.

That is, the problem, apparently is there, I wonder if I’m forgetting something, if I’m doing something wrong, if anyone has been through it etc.

  • 1

    Delphi and his little mistakes that leave us with headache kkk Joking aside, you have already tried to close or destroy this cdsTemp before closing the form?

  • In which event of the form you this code snippet?

  • @Robertofagundes That’s right, boy kkkkkk Yes, Yes I’ve tried to give a Freeandnil(cdsTemp) on Onclose and Ondestroy Form and nothing yet.

  • @Pablovargas I use in action a specific button here in my application. Basically in the Include of my form, because I need to do this procedure there for an action I’m testing. But this mistake is getting in my way

  • @Henriquetavares what I think may be happening, is that this ADD function, is not copying your field, but just passing the reference, IE, when you destroy your form, it automatically destroys your cdsTemp(This if it is inside your form)and destroys the field of cdsAux, and that is where the error occurs. Then try to clear your cdsTemp in the onClose event of your form, this way: cdsTemp.Fields.Clear();

  • @Robertofagundes opa, so I tested here what you said and yet the error persists. However, I was debugging some more and found that where I open my form, in this part: var
 loForm: TfrmTeste;
begin
 loForm := TfrmTeste.Create(Self);
 try
 loForm.ShowModal;
 finally
 FreeAndNil(loForm);
 end;
end;

  • The Invalid Pointer Operation error occurs when you enter Freeandnil(loForm) in Finally. I think it got kind of bad to see the code above because it was lying down kkkk. The error is involved with this part of the ADD function and probably the way I’m working to open the form. I was reading some forums and I saw that some people commented on this possibility of the way the form is opening is influencing this error I’ll take another look here and see if I discover anything else, thank you very much for your attention, really!

Show 2 more comments

1 answer

1


Create the fields as follows (size is a variable integer):

for i := 0 to cdsAux.FieldCount -1 do
begin
  tamanho:= cdsAux.Fields[i].Size;
  if (cdsAux.Fields[i].DataType = ftString) and (tamanho = 0) then
    tamanho:=1
  else
    cdsTemp.FieldDefs.Add(cdsAux.Fields[i].FieldName,
          cdsAux.Fields[i].DataType, tamanho);
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.