Forum > General

Error: Class type expected, but got "THash$2.

(1/2) > >>

deadserious:
I am getting another error compiling generics (or the combination of generics with class helpers maybe), this time stating Class Type Expected.

The code errors on this line:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    if AllowOverwrite then      TInterlocked.Exchange<V>(p^.Value,Value)           
TInterlocked.Exchange is a method of a class helper for TInterlocked defined as:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  TInterlockedHelper = class helper for TInterlocked  public    class function Exchange<T>(var Target: T; Value: T): T; overload;  end; 
The type being passed into the method as type V is from this class definition:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  THash<K,V> = class(TInterfacedObject, IHash<K,V>)       ......  end; 
This is set to DELPHIUNICODE mode

Thoughts?

Thaddy:
Why do you not use the lock exchange primitives from system? These are also portable as a bonus.
https://www.freepascal.org/docs-html/rtl/system/index.html
Scroll to Ixxx.
In trunk there are even more for delphi compatibility. (Aliases to the already declared functions)
You probably need InterlockedCompareExchangePointer, which takes into account the pointer size for different paltforms/cpu's. There's also readbarrier/readwritebarrier/writebarrier which is useful for thread programming.

deadserious:

--- Quote from: Thaddy on May 13, 2024, 02:24:52 pm ---Why do you not use the lock exchange primitives from system? These are also portable as a bonus.
https://www.freepascal.org/docs-html/rtl/system/index.html
Scroll to Ixxx.
In trunk there are even more for delphi compatibility. (Aliases to the already declared functions)

--- End quote ---
This helper implements missing ones I need for delphi and i'm porting my library over to FPC. I didn't see a generic atomic compare and swap in FPC.


--- Quote ---You probably need InterlockedCompareExchangePointer, which takes into account the pointer size for different paltforms/cpu's. There's also readbarrier/readwritebarrier/writebarrier which is useful for thread programming.

--- End quote ---

I can probably use that in the implementation of this one, but to keep code as compatible as possible between delphi and FPC I'd rather keep the IFDEFS at the implementation level instead of the interface.

Thaddy:
What I suggested is 100% Delphi compatible. At least later versions. NOT D7 and the likes.

PascalDragon:

--- Quote from: deadserious on May 13, 2024, 01:39:18 pm ---I am getting another error compiling generics (or the combination of generics with class helpers maybe), this time stating Class Type Expected.
--- End quote ---

Please provide full, standalone yet small examples that demonstrate your issue, not just mere snippets.

Navigation

[0] Message Index

[#] Next page

Go to full version