Recent

Author Topic: How to make an alias for generic advanced record?  (Read 1195 times)

alpine

  • Hero Member
  • *****
  • Posts: 1412
How to make an alias for generic advanced record?
« on: September 14, 2022, 07:20:18 pm »
Help!
Does anybody know how to create an alias for this one:
Code: Pascal  [Select][+][-]
  1. generic TSmartPointer<T: class> = record {...} end;

I want to use it under the name of, say:
Code: Pascal  [Select][+][-]
  1. generic TAuto<T: class> = record {...} end;
But I can't figure out how to do it...
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

PascalDragon

  • Hero Member
  • *****
  • Posts: 6395
  • Compiler Developer
Re: How to make an alias for generic advanced record?
« Reply #1 on: September 15, 2022, 09:28:17 am »
You can't. Simple as that.

Thaddy

  • Hero Member
  • *****
  • Posts: 19165
  • Glad to be alive.
Re: How to make an alias for generic advanced record?
« Reply #2 on: September 15, 2022, 09:41:02 am »
You can with a macro.
{$macro on}{$define Tauto:=TSmartpointer}

This can maybe have side effects, though.
objects are fine constructs. You can even initialize them with constructors.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8572
Re: How to make an alias for generic advanced record?
« Reply #3 on: September 15, 2022, 10:09:08 am »
You can with a macro.
{$macro on}{$define Tauto:=TSmartpointer}

This can maybe have side effects, though.

Noting PascalDragon's comment of a few days ago that "Macros are only matched on a full token.", i.e. there's no risk of a substring match.

They can be very useful indeed, particularly since (unlike C macros) they can be multi-line. It's unfortunate that they can't take parameters, but TBH I can't think of a single macro-expansion preprocessor that is neither embarrassingly primitive nor impenetrably esoteric.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: How to make an alias for generic advanced record?
« Reply #4 on: September 15, 2022, 03:13:23 pm »
You can't. Simple as that.
Thanks! It is good to know there is no way.

You can with a macro.
{$macro on}{$define Tauto:=TSmartpointer}

This can maybe have side effects, though.
It came up into my mind, but there are several source files to include into. I'd better refactor.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

 

TinyPortal © 2005-2018