Virtual Method lazarus / 21-General ---------------------------------------------------------------------- Medhome · 2025-01-03 09:16 Hi all, I got Runtime Error with my sample project using freepascal and concerning casting tform and using virtual method This sample use 2 forms 1 BaseForm (TFORM) 2 TF1 (BaseForm) inherited BaseForm has the procedure Procedure whenDeleteRec(dataset:tdataset) virtual;Abstract TF1 Procedure whenDeletedRec(dataset:tdataset); override; Now in the MainForm when I do baseform (p).WhenDeletedRec(dataset) where p is a pointer to tf1 I got a runtime error. Regards Med ---------------------------------------------------------------------- rvk · 2025-01-03 09:26 Quote from: Medhome on January 03, 2025, 10:16:12 amNow in the MainForm when I do baseform (p).WhenDeletedRec(dataset) where p is a pointer to tf1 I got a runtime error. WHAT runtime error do you get. ALWAYS copy and paste the exact error in your post. And show some code how you declared and created your P variable. Are you sure your P contains a correct initiated class (inherited from BaseForm)? ---------------------------------------------------------------------- Thaddy · 2025-01-04 08:49 The cast to baseform may have changed to the vmt entry of baseform, not the vmt entry of the derived form. Hence you get an abstract error. You are probably using the cast wrong. Either that or the derived form is not created. ---------------------------------------------------------------------- rvk · 2025-01-04 10:41 Quote from: Thaddy on January 04, 2025, 09:49:45 amThe cast to baseform may have changed to the vmt entry of baseform, not the vmt entry of the derived form.More likely is that the pointer p isn't initialized. But since we don't get information about the code and the actual error it's just guessing. I initially thought putting a class in a classless pointer would loose some information but it doesn't. That also just works (see below). So it's not an abstract error that's getting thrown here, is my guess. But just an access violation or something else. 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 program Project1; type  TAnimal = class    procedure Sound; virtual; abstract;  end;   TCat = class(TAnimal)    procedure Sound; override;  end;   procedure TCat.Sound;  begin    writeln('miauw');  end; var  animal: TAnimal; // notice the variable is even base class  p: pointer;begin  animal := TCat.Create; // but we create it as child class  p := animal;  TAnimal(p).Sound;  // shows miauw  readln;end.