Recent

Author Topic: Objects causes "Create" to become Invalid.  (Read 1026 times)

dgrhoads

  • New Member
  • *
  • Posts: 48
Objects causes "Create" to become Invalid.
« on: July 01, 2023, 05:56:43 am »
When "Objects" is included in the Uses list, I find that commands that attempt to Create a variable no longer work.  "Create" is not found as an acceptable modifier.  For example

  S := TStringList.Create;

is described by the compiler as "Error idents no member "Create" and
Fata.  Syntax Error, ";" expected but "Create" found.

The attached program (for compiling only) compiles successfully when Objects is not in the Uses section.  However it does not compile successfully when Objects is present.  My example uses TStringList, but I have observed it with other items that need creation as well.

Am I missing something so that this is correct behavior?

Awkward

  • Full Member
  • ***
  • Posts: 154
Re: Objects causes "Create" to become Invalid.
« Reply #1 on: July 01, 2023, 06:30:35 am »
why you so wondering? "Objects" unit uses another object model base on "object", not "class". it can have similar (same name) objects but another methods, especially constructor/destructor. Really, it WILL have anothers.

if you want to use standard modern model, you must use TStringList from "Classes" unit

Handoko

  • Hero Member
  • *****
  • Posts: 5513
  • My goal: build my own game engine using Lazarus
Re: Objects causes "Create" to become Invalid.
« Reply #2 on: July 01, 2023, 06:36:28 am »
@dgrhoads

Because TStringList also is provided by Objects unit (see the attached screenshot), you need to tell the compiler if you wish to use TStringList from Classes unit:

Code: Pascal  [Select][+][-]
  1. var
  2.   sList : Classes.TStringList;
  3. begin
  4.   sList := Classes.TStringList.Create;
  5. end;
« Last Edit: July 01, 2023, 06:39:36 am by Handoko »

paweld

  • Hero Member
  • *****
  • Posts: 1561
Re: Objects causes "Create" to become Invalid.
« Reply #3 on: July 01, 2023, 07:44:49 am »
or set Objects unit at first place in uses section
Best regards / Pozdrawiam
paweld

dgrhoads

  • New Member
  • *
  • Posts: 48
Re: Objects causes "Create" to become Invalid.
« Reply #4 on: July 02, 2023, 05:16:10 am »
Thanks.  The change in order in the Uses list worked.

I was unaware that TStringList occurred in both Objects and Classes.  Now I see how to discern that:  two entries for TStringList in the list of Lazarus objects, one for Objects and one for Classes.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6267
  • Compiler Developer
Re: Objects causes "Create" to become Invalid.
« Reply #5 on: July 02, 2023, 08:17:38 pm »
I was unaware that TStringList occurred in both Objects and Classes.  Now I see how to discern that:  two entries for TStringList in the list of Lazarus objects, one for Objects and one for Classes.

The Objects unit is for TP-style object types and the Classes unit is for Delphi-style class types. If you only use the later then there is no reason for you to use the Objects unit.

 

TinyPortal © 2005-2018