Pointer to object expected lazarus / 21-General ---------------------------------------------------------------------- paule32 · 2025-04-01 03:34 The following Line produce me error messages: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure New_PC(var P: Pointer; Cons: TProcedure); stdcall; [public, alias: 'New_PC' ]; export; begin New(P, Cons); end; Unit.pas(122,115) Error: Pointer to object expected Unit.pas(122,115) Error: Illegal expression ---------------------------------------------------------------------- cdbc · 2025-04-01 05:28 Hi Hmmm could it be:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure New_PC(var P: PMyObject; Cons: TProcedure); stdcall; [public, alias: 'New_PC' ]; export; begin New(P, Cons); end;Regards Benny ---------------------------------------------------------------------- H₂SO₄ · 2025-04-01 05:58 What is this function supposed to do? Allocate memory for an object and run  Cons  as the constructor? How is  New  supposed to know the instance size? ---------------------------------------------------------------------- Zvoni · 2025-04-01 06:04 cdbc is right. Think about it: a raw "Pointer" is exactly that: a variable holding a memory address. It's basically an "untyped" Pointer. It doesn't know what kind of Type the Data is at that address. And if it doesn't know the kind of data, it doesn't know its size. Think of it like an "ancestor" of all Pointer-Types Calling "New" for that Pointer, how should "New" know what amount of memory to allocate? It needs a size, which is determined by the size of the Type it points to. It even says so in the documentation: https://www.freepascal.org/docs- html/rtl/system/new.html QuoteNew allocates a new instance of the type pointed to by P, and puts the address in P. If P is an object, then it is possible to specify the name of the constructor with which the instance will be created. EDIT: Crossed with Khrys ---------------------------------------------------------------------- cdbc · 2025-04-01 06:05 Hi @Khrys: It's been like that since TurboPascal 5.5, with the introduction of 'Objects', Borland extended 'new' / 'dispose' to accept / include a constructor 'Init'  and destructor 'Done' and 'New' only accepts typed pointers, thus it knows its size. Regards Benny ---------------------------------------------------------------------- paule32 · 2025-04-01 06:11 so, the procedure is not export'able ? how about to use Generic ? ---------------------------------------------------------------------- cdbc · 2025-04-01 06:26 Hi I'd say no, 'cause it's tied to the object, i.e.: not standalone. One thing you can try, is to /call/ the contructor-parameter from the object's 'Init' constructor  ...I dunno - might work. Generics is probably taking it too far... Regards Benny ---------------------------------------------------------------------- paule32 · 2025-04-01 06:32 Then, I need to know the class (structure) of each one. And this is impossible for a "non-owner" project. ---------------------------------------------------------------------- cdbc · 2025-04-01 06:42 Hi Hmmm, if it's a plugin-system, you're trying to put together, then it's not gonna fly. I've built such a framework and it's quite involved + you need to come up with a way to share the 'meta' -data (types & consts) with the host-application. Regards Benny ---------------------------------------------------------------------- paule32 · 2025-04-01 06:53 thanks for this offer. here: https://github.com/paule32/TinyFPC you can take a look gap project of me. It is an self made idea, to minimze my executables by using DLL (Windows). It's not full, only a little bit - like it is - a gap jumper. ---------------------------------------------------------------------- Zvoni · 2025-04-01 07:27 An alternative might be "GetMem" (don't forget FreeMem) --> https://www.freepascal.org/docs-html/rtl/system/getmem.html In this case you would have to pass the Size of the "Object", which would require a rework of your Procedure ---------------------------------------------------------------------- cdbc · 2025-04-01 07:33 Hi Well, @paule32: You're trying to cut a lot of corners, at once  ...and I'm sorry to have to say: The reality doesn't work like that! An idea only becomes an invention, if it works in practice! You seem to be forgetting, that libraries get loaded into the application memory space, thus you only save a few bytes on disk - for the application. In reality, with all the redundant code surrounding lib-mechanics, you end up wasting space and energy...! FPC is as lean as they come OOTB. Regards Benny edit: typo + rant ---------------------------------------------------------------------- Thaddy · 2025-04-01 08:27 Sigh, The error is simply in declaring the expected pointer as var. Remove var and it works. ---------------------------------------------------------------------- PascalDragon · 2025-04-01 19:19 Quote from: Thaddy on April 01, 2025, 10:27:27 amSigh, The error is simply in declaring the expected pointer as var. Remove var and it works. Sigh, no it does not. 🙄 Did you even remotly check whether this works or - gasp - think about it? The New in use here is one used for structured types (mainly TP-style objects) to pass a constructor, so it requires an object type as argument. Neither a raw pointer nor a formal parameter can be used there. Sidenote: the function pointer can't be used for the constructor argument either.