TSQLQuery.Open is Destroying my Objects ? lazarus / 16-Databases ---------------------------------------------------------------------- Weitentaaal · 2021-09-13 08:59 Hello , so here My Problem: 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       TestIt(Elements[15, 3, 0]); --> Here my Element has the Data i gave it   RsDeviceData.Open;        TestIt(Elements[15, 3, 0]); --> Here it doesn't  I really don't know whats going on ? Maybe im overriding my Object in the memory ? Here what my Objects look like before and after: BEFORE: 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 Element = = {   = {     _vptr$ = {       0xa1e8fc4,        0x0}},    FMOVED = DIRLEFT,    FNEXTBTL = $0,    FPREVBTL = $0,    FCOORDS = {     X = 15,      Y = 3,      Z = 0},    FSPLIT = SPNONE, FISCALCULATED = true,    FBTLNUM = 1,    FBTLARTNUM = 1,    FZLAL = 0,    FDATA = 1,    FRAHMENART = 0,    FGAUSF = 0,    FPAUSS = 0,    FPINN = -1,    FPBOD = -1,    FABBOD = 65,    FABSEIT = 48,    FABDACH = 48,    FGNAM = $0,    FGBREIT = 706,    FGHOCH = 571,    FX1 = 0, FX2 = 48,    FY1 = 48,    FY2 = 658,    FZ1 = 48,    FZ2 = 523,    FISEXTENDABLE = false,    FZUBSTR = ';',    FZUBSTRB = $0,    FZUBSTRC = $0,    FZUBSTRD = $0,    FPA = 6,    FPRS = 48,    FPRU = 48,    FLUMENG = 3000,    FAN = 0,    FBED = 0,    FPAEXT = 0,    FPAGES = 0,    FKONSTCHG = 0,    FSPALTEL = $0,    FSPALTER = $0,    FISMARINE = false,    FEKPREIS = 0,    FSKIZZEDATA = 0,    FKG = 0}  var Element: TElement = class(TObject) C:\Projekts\WGK2.0\ustartup.pas(6352,18)   AFTER: 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 Element = = {   = {     _vptr$ = {       0x1,        0x64}},    FMOVED = 100,    FNEXTBTL = $d,    FPREVBTL = $11,    FCOORDS = {     X = 33,      Y = 49,      Z = 53},    FSPLIT = 57,    FISCALCULATED = 61,    FBTLNUM = 65,    FBTLARTNUM = 69,    FZLAL = 73,    FDATA = 77,    FRAHMENART = 81,    FGAUSF = 85,    FPAUSS = 89,    FPINN = 93,    FPBOD = 97,    FABBOD = 2.2280955810125422e-312,    FABSEIT = 2.3978552443292893e-312,    FABDACH = 2.822254402561869e-312,    FGNAM = $95 ,    FGBREIT = 3.6710527191851294e-312,    FGHOCH = 4.0105720458186235e-312,    FX1 = 4.3500913724521176e-312,    FX2 = 4.6047308674470007e-312,    FY1 = 1.0206799755654608e-311,    FY2 = 1.5808868646332543e-311,    FZ1 = 2.667348709737907e-311,    FZ2 = 2.6843246761940863e-311,    FISEXTENDABLE = 245,    FZUBSTR = $4fd ,    FZUBSTRB = $505 ,    FZUBSTRC = $509 ,    FZUBSTRD = $511 ,    FPA = 2.8031564405138329e-311,    FPRS = 2.8201324068474839e-311,    FPRU = 2.8880362721682539e-311,    FLUMENG = 3.4652191274451938e-311,    FAN = 1889,    FBED = 1905,    FPAEXT = 5.128863827830739e-311,    FPAGES = 5.6890707168985325e-311,    FKONSTCHG = 2689,    FSPALTEL = $a85 ,    FSPALTER = $a89 ,    FISMARINE = 141, FEKPREIS = 5.7569745822252314e-311,    FSKIZZEDATA = 2721,    FKG = 5.8163904643880691e-311}  var Element: TElement = class(TObject) C:\Projekts\WGK2.0\ustartup.pas(6352,18)  Any help would be appreciated. ---------------------------------------------------------------------- howardpc · 2021-09-13 09:27 You need to show some compilable code for others to see what you are trying to do. ---------------------------------------------------------------------- Weitentaaal · 2021-09-13 10:33 I can't realy recreate my Problem But i will update this post if i Somehow will be able to do it. (Its not a Single Case) ---------------------------------------------------------------------- Zvoni · 2021-09-13 10:41 The values in AFTER: Are those the values you're pulling from the Database? ---------------------------------------------------------------------- Weitentaaal · 2021-09-13 10:46 The Object in after is the the Same Object as the one before just after i open a Database query (no relation) I got An Object wich Stors Data. i use it to Display on GUI. after GUI returns Modalresult mrOk i store data in Database. The Object will only get Data by the GUI. First call of this is OK. when i try to call it a second time i do get this Error EDIT: Here some code which might cause the Problem 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 If Element.BtlArtNum = 0 then begin            //Create New Instance          temp := TSWData.Create();            //Asssign Current Values to New Instance            Element.AssignTo(temp);            //Release/Destroy old Data because if not i have Memory leak          Element.Free();            //Declare Element as SW            //Element := TSWData.Create();            //Assign old Values to new Created SW            Element := temp;            //Init Data          TSWData(Element).InitData();            //Free Temporary Object          temp.Free();         end else begin            //So´llte das Element ein 2. mal  Aufgerufen werden            Element.IsCalculated:= False;         end; //######################        TAData(Elements[nx, ny, nz]).Show(); //######################    AForm.ReadData(Self); //--> Assign Values to gui elements    Case AForm.ShowModal Of      mrOK: Begin         Result := 1;      End;    mrLast: Begin              Result := -1;      End;      Else Begin            Result := 0;      End;   End; ---------------------------------------------------------------------- Weitentaaal · 2021-09-13 12:50 MY Object gets somehow casted into a TSQLquery... im confused ---------------------------------------------------------------------- Weitentaaal · 2021-09-13 14:32 temp.Free caused the Problem. 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  If Element.BtlArtNum = 0 then begin              //Create New Instance            temp := TSWData.Create();               //Asssign Current Values to New Instance               Element.AssignTo(temp);             //Release/Destroy old Data because if not i have Memory leak             Element.Free();               //Declare Element as SW   //Element := TSWData.Create();   //Assign old Values to new Created SW   Element := temp;               //Init Data   TSWData(Element).InitData();   //Free Temporary Object   temp.Free();end else begin   //So´llte das Element ein 2. mal  Aufgerufen werden   Element.IsCalculated:= False;end;   Its Probably just a bug but it was realy strange that my Element was displayed as TSQLQuery. Anyway thanks for your efort @Zvoni and @howardpc ---------------------------------------------------------------------- PascalDragon · 2021-09-14 06:57 Quote from: Weitentaaal on September 13, 2021, 04:32:56 pmtemp.Free caused the Problem. Yes, as others told you in the other threads, class instances are simply references, so by doing Element := temp both Element and temp point to the same instance. If you now call Free on one of them it will free the instance for both. Quote from: Weitentaaal on September 13, 2021, 04:32:56 pmIts Probably just a bug but it was realy strange that my Element was displayed as TSQLQuery. Once the memory is freed the memory manager will reuse it for other allocations, thus if your class references still points to the memory (and Element will do that) it will point to different data and the debugger will simply try its best to interpret that and thus it might come out as another class instance.