[fpc-pascal] TFPGObjectList error

Michalis Kamburelis michalis.kambi at gmail.com
Sun Jul 1 04:14:07 CEST 2018


 2018-07-01 4:01 GMT+02:00 Vojtěch Čihák <vojtech.cihak at atlas.cz>:
> this seems to be misleading error message. TFPGObjectList works well for
> objects (classes). When I tried to push record to it, I got the same error
> message. TVec3 is not class, right?

Indeed, it's a misleading message. The message

   ...identifier idents no member "Free"

doesn't talk about the line

    list.Free;

(which is fine, "list" is an instance of a class). It talks most
likely about the "Free" call inside FGL implementation in

"""
procedure TFPGObjectList.Deref(Item: Pointer);
begin
  if FFreeObjects then
    T(Item^).Free;
end;
"""

If you look inside the FGL unit sources of your FPC version, you will
likely find this to be at line 992 :)

Short explanation:Since your TVec3 is probably not a class, you cannot
do "Free" on it.

The solution is to use TFPGList instead of TFPGObjectList. You should
also define an equality operator if TVec3 is a record. See e.g. my
example in https://castle-engine.io/modern_pascal_introduction.html#_operator_overloading
(scroll to the example with TMyRecordList).

Or you could use Generics.Collections unit with generic TList for
records. It by default compares records by comparing memory contents.

Regards,
Michalis



More information about the fpc-pascal mailing list