"Invalid Pointer Operation" when creating data module

Asked

Viewed 309 times

1

I have a dll made in Delphi 2010, and sometimes there is "Invalid Pointer Operation" error when creating the data module, which contains dbexpress connection components (simpledataset, sqlconnection, clientdataset, etc, as well as some components of the rave report). The dll works 90% of the time, but sometimes generates the error.

The application that calls afunção da dll tb is made in December 2010. I researched a lot on google, but I’ve never seen this error when creating a data module, usually people find this error when giving one . free or when exiting the application, but in my case it is the CREATE data module.

I have tried to put Simplesharemem as 1a. uses declaration, both in the dll source and in the exe source that calls it, same error...

It occurs like this:

  • application starts and calls DLL function, works normal, close the application
  • application starts and calls DLL function, works normal, close the application
  • application starts and calls DLL function, ERROR, close the application
  • application starts and calls DLL function, works normal, close the application
  • and so it goes...

The messages aren’t always the same, that’s what puzzles me:

  • invalid Pointer Operation, OR
  • error Reading sqlTable1FIELD1.Fieldname: invalid Pointer Operation, OR
  • error Reading sqlTable1FIELD1.Sqlconnection: Property 0RAVECOMPLETED does not exist
  • Class Tsmallintfield not found

Any suggestions?

function Imp1(vEmp: Integer): boolean; export; stdcall;
var Registry: TRegistry;
begin
  with dmNFD2 do
  begin
    try
      p_NumEmp := vEmp;
      result := True;
      if not(Assigned(dmNFD2)) then
         //Application.CreateForm(TdmNFD2,dmNFD2); // erro aqui ou
         dmNFD2 := TdmNFD2.Create(nil); // erro aqui
      if not(dmNFD2.sqlConn.Connected) then
      begin
        ConnectBD; // le o registro do windows (path, user e password database)
      end;
      if dmNFD2.sqlConn.Connected then
      begin
        qryGen.Close;
        qryGen.SQL.Text := 'select CAMPO from TABELA where PARNUM = :PARNUM';
        qryGen.Params.ParamByName('PARNUM').AsInteger := p_NumEmp;
        qryGen.Open;
        // insert or update in other table
        // ....
      end;     
    except
      on e:Exception do
      begin
        result := False;
      end; 
    end;
end;    
  • Is the application that uses this data module multi thread? The problem with data modules is already born in its concept: a lot of global objects that depend on constant state maintenance. Also, you have two lines creating instance of Tdmnfd2 for the same variable (although one of the lines is commented). Another thing: check if the variable is Assigned does not guarantee that it refers to a valid instance; it may contain dirt because it was not initialized with nil or by the object once referred to there has already been destroyed.

  • Caffé, the data module is inside a dll, which does not use threads. There are 2 lines to create the data module pq I was testing one or the other (I researched and saw that it is safer to use "nil").

  • @Mteste also tries to use the Self, is usually better than the nil

  • The question is not whether the datamodule uses threads but whether the datamodule consumer uses threads when consuming it.

  • Does not use threads when using dll function.

No answers

Browser other questions tagged

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