Recent

Author Topic: TSQLQuery.Open is Destroying my Objects ?  (Read 1859 times)

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 328
  • Weitental is a very beautiful garbage depot.
TSQLQuery.Open is Destroying my Objects ?
« on: September 13, 2021, 10:59:40 am »
Hello :),

so here My Problem:

Code: Pascal  [Select][+][-]
  1.       TestIt(Elements[15, 3, 0]); --> Here my Element has the Data i gave it
  2.    RsDeviceData.Open;  
  3.       TestIt(Elements[15, 3, 0]); --> Here it doesn't
  4.  

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][+][-]
  1. Element = <TELEMENT> = {
  2.  
  3.   <TOBJECT> = {
  4.  
  5.     _vptr$ = {
  6.  
  7.       0xa1e8fc4,
  8.  
  9.       0x0}},
  10.  
  11.   FMOVED = DIRLEFT,
  12.  
  13.   FNEXTBTL = $0,
  14.  
  15.   FPREVBTL = $0,
  16.  
  17.   FCOORDS = {
  18.  
  19.     X = 15,
  20.  
  21.     Y = 3,
  22.  
  23.     Z = 0},
  24.  
  25.   FSPLIT = SPNONE,
  26.  
  27.   FISCALCULATED = true,
  28.  
  29.   FBTLNUM = 1,
  30.  
  31.   FBTLARTNUM = 1,
  32.  
  33.   FZLAL = 0,
  34.  
  35.   FDATA = 1,
  36.  
  37.   FRAHMENART = 0,
  38.  
  39.   FGAUSF = 0,
  40.  
  41.   FPAUSS = 0,
  42.  
  43.   FPINN = -1,
  44.  
  45.   FPBOD = -1,
  46.  
  47.   FABBOD = 65,
  48.  
  49.   FABSEIT = 48,
  50.  
  51.   FABDACH = 48,
  52.  
  53.   FGNAM = $0,
  54.  
  55.   FGBREIT = 706,
  56.  
  57.   FGHOCH = 571,
  58.  
  59.   FX1 = 0,
  60.  
  61.   FX2 = 48,
  62.  
  63.   FY1 = 48,
  64.  
  65.   FY2 = 658,
  66.  
  67.   FZ1 = 48,
  68.  
  69.   FZ2 = 523,
  70.  
  71.   FISEXTENDABLE = false,
  72.  
  73.   FZUBSTR = ';',
  74.  
  75.   FZUBSTRB = $0,
  76.  
  77.   FZUBSTRC = $0,
  78.  
  79.   FZUBSTRD = $0,
  80.  
  81.   FPA = 6,
  82.  
  83.   FPRS = 48,
  84.  
  85.   FPRU = 48,
  86.  
  87.   FLUMENG = 3000,
  88.  
  89.   FAN = 0,
  90.  
  91.   FBED = 0,
  92.  
  93.   FPAEXT = 0,
  94.  
  95.   FPAGES = 0,
  96.  
  97.   FKONSTCHG = 0,
  98.  
  99.   FSPALTEL = $0,
  100.  
  101.   FSPALTER = $0,
  102.  
  103.   FISMARINE = false,
  104.  
  105.   FEKPREIS = 0,
  106.  
  107.   FSKIZZEDATA = 0,
  108.  
  109.   FKG = 0}
  110.  
  111.  
  112. var
  113.  Element: TElement =
  114. class
  115. (TObject)
  116.  
  117. C:\Projekts\WGK2.0\ustartup.pas(6352,18)
  118.  
  119.  

AFTER:
Code: Pascal  [Select][+][-]
  1. Element = <TELEMENT> = {
  2.  
  3.   <TOBJECT> = {
  4.  
  5.     _vptr$ = {
  6.  
  7.       0x1,
  8.  
  9.       0x64}},
  10.  
  11.   FMOVED = 100,
  12.  
  13.   FNEXTBTL = $d,
  14.  
  15.   FPREVBTL = $11,
  16.  
  17.   FCOORDS = {
  18.  
  19.     X = 33,
  20.  
  21.     Y = 49,
  22.  
  23.     Z = 53},
  24.  
  25.   FSPLIT = 57,
  26.  
  27.   FISCALCULATED = 61,
  28.  
  29.   FBTLNUM = 65,
  30.  
  31.   FBTLARTNUM = 69,
  32.  
  33.   FZLAL = 73,
  34.  
  35.   FDATA = 77,
  36.  
  37.   FRAHMENART = 81,
  38.  
  39.   FGAUSF = 85,
  40.  
  41.   FPAUSS = 89,
  42.  
  43.   FPINN = 93,
  44.  
  45.   FPBOD = 97,
  46.  
  47.   FABBOD = 2.2280955810125422e-312,
  48.  
  49.   FABSEIT = 2.3978552443292893e-312,
  50.  
  51.   FABDACH = 2.822254402561869e-312,
  52.  
  53.   FGNAM = $95 <error: Cannot access memory at address 0x95>,
  54.  
  55.   FGBREIT = 3.6710527191851294e-312,
  56.  
  57.   FGHOCH = 4.0105720458186235e-312,
  58.  
  59.   FX1 = 4.3500913724521176e-312,
  60.  
  61.   FX2 = 4.6047308674470007e-312,
  62.  
  63.   FY1 = 1.0206799755654608e-311,
  64.  
  65.   FY2 = 1.5808868646332543e-311,
  66.  
  67.   FZ1 = 2.667348709737907e-311,
  68.  
  69.   FZ2 = 2.6843246761940863e-311,
  70.  
  71.   FISEXTENDABLE = 245,
  72.  
  73.   FZUBSTR = $4fd <error: Cannot access memory at address 0x4fd>,
  74.  
  75.   FZUBSTRB = $505 <error: Cannot access memory at address 0x505>,
  76.  
  77.   FZUBSTRC = $509 <error: Cannot access memory at address 0x509>,
  78.  
  79.   FZUBSTRD = $511 <error: Cannot access memory at address 0x511>,
  80.  
  81.   FPA = 2.8031564405138329e-311,
  82.  
  83.   FPRS = 2.8201324068474839e-311,
  84.  
  85.   FPRU = 2.8880362721682539e-311,
  86.  
  87.   FLUMENG = 3.4652191274451938e-311,
  88.  
  89.   FAN = 1889,
  90.  
  91.   FBED = 1905,
  92.  
  93.   FPAEXT = 5.128863827830739e-311,
  94.  
  95.   FPAGES = 5.6890707168985325e-311,
  96.  
  97.   FKONSTCHG = 2689,
  98.  
  99.   FSPALTEL = $a85 <error: Cannot access memory at address 0xa85>,
  100.  
  101.   FSPALTER = $a89 <error: Cannot access memory at address 0xa89>,
  102.  
  103.   FISMARINE = 141,
  104.  
  105.   FEKPREIS = 5.7569745822252314e-311,
  106.  
  107.   FSKIZZEDATA = 2721,
  108.  
  109.   FKG = 5.8163904643880691e-311}
  110.  
  111.  
  112. var
  113.  Element: TElement =
  114. class
  115. (TObject)
  116.  
  117. C:\Projekts\WGK2.0\ustartup.pas(6352,18)
  118.  

Any help would be appreciated. :)
« Last Edit: September 13, 2021, 11:01:51 am by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.0

howardpc

  • Hero Member
  • *****
  • Posts: 3836
Re: TSQLQuery.Open is Destroying my Objects ?
« Reply #1 on: September 13, 2021, 11:27:50 am »
You need to show some compilable code for others to see what you are trying to do.

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 328
  • Weitental is a very beautiful garbage depot.
Re: TSQLQuery.Open is Destroying my Objects ?
« Reply #2 on: September 13, 2021, 12:33:02 pm »
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) 
« Last Edit: September 13, 2021, 12:53:29 pm by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.0

Zvoni

  • Hero Member
  • *****
  • Posts: 808
Re: TSQLQuery.Open is Destroying my Objects ?
« Reply #3 on: September 13, 2021, 12:41:11 pm »
The values in AFTER: Are those the values you're pulling from the Database?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 328
  • Weitental is a very beautiful garbage depot.
Re: TSQLQuery.Open is Destroying my Objects ?
« Reply #4 on: September 13, 2021, 12:46:23 pm »
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][+][-]
  1. If Element.BtlArtNum = 0 then begin
  2.             //Create New Instance
  3.             temp := TSWData.Create();
  4.             //Asssign Current Values to New Instance
  5.             Element.AssignTo(temp);
  6.             //Release/Destroy old Data because if not i have Memory leak
  7.             Element.Free();
  8.             //Declare Element as SW
  9.             //Element := TSWData.Create();
  10.             //Assign old Values to new Created SW
  11.             Element := temp;
  12.             //Init Data
  13.             TSWData(Element).InitData();
  14.             //Free Temporary Object
  15.             temp.Free();
  16.          end else begin
  17.             //So´llte das Element ein 2. mal  Aufgerufen werden
  18.             Element.IsCalculated:= False;
  19.          end;
  20.  
  21. //######################
  22.  
  23.          TAData(Elements[nx, ny, nz]).Show();
  24.  
  25. //######################
  26.  
  27.    AForm.ReadData(Self); //--> Assign Values to gui elements
  28.  
  29.    Case AForm.ShowModal Of
  30.       mrOK: Begin
  31.          Result := 1;
  32.       End;
  33.       mrLast: Begin
  34.               Result := -1;
  35.       End;
  36.       Else Begin
  37.               Result := 0;
  38.       End;
  39.    End;
  40.  
  41.  

« Last Edit: September 13, 2021, 02:57:30 pm by Weitentaaal »
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.0

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 328
  • Weitental is a very beautiful garbage depot.
Re: TSQLQuery.Open is Destroying my Objects ?
« Reply #5 on: September 13, 2021, 02:50:23 pm »
MY Object gets somehow casted into a TSQLquery... im confused
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.0

Weitentaaal

  • Sr. Member
  • ****
  • Posts: 328
  • Weitental is a very beautiful garbage depot.
Re: TSQLQuery.Open is Destroying my Objects ?
« Reply #6 on: September 13, 2021, 04:32:56 pm »
temp.Free caused the Problem.

Code: Pascal  [Select][+][-]
  1.  
  2. If Element.BtlArtNum = 0 then begin          
  3.    //Create New Instance          
  4.    temp := TSWData.Create();            
  5.    //Asssign Current Values to New Instance            
  6.    Element.AssignTo(temp);            
  7.    //Release/Destroy old Data because if not i have Memory leak            
  8.    Element.Free();            
  9.    //Declare Element as SW
  10.    //Element := TSWData.Create();
  11.    //Assign old Values to new Created SW
  12.    Element := temp;            
  13.    //Init Data
  14.    TSWData(Element).InitData();
  15.    //Free Temporary Object
  16.    temp.Free();
  17. end else begin
  18.    //So´llte das Element ein 2. mal  Aufgerufen werden
  19.    Element.IsCalculated:= False;
  20. end;
  21.  
  22.  

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 :)
Lazarus: 2.0.12 x86_64-win64-win32/win64
Compiler Version: 3.2.0

PascalDragon

  • Hero Member
  • *****
  • Posts: 3518
  • Compiler Developer
Re: TSQLQuery.Open is Destroying my Objects ?
« Reply #7 on: September 14, 2021, 08:57:53 am »
temp.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.

Its 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.

 

TinyPortal © 2005-2018