Recent

Author Topic: What does this error mean and how do I fix?  (Read 1069 times)

VinDerKlaus

  • New Member
  • *
  • Posts: 27
What does this error mean and how do I fix?
« on: February 25, 2020, 01:15:55 am »
Hello Friends,

My Form's caption is "[Tool Window] PATH". I try to get PATH part using GetPart function and assign result to string:

Code: Pascal  [Select][+][-]
  1. PathStr := GetPart(['] '], [], Form1.Caption, false, false);

The output should be "PATH", but instead, I get error message:

Can't take address of constant expressions

How to repair this?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: What does this error mean and how do I fix?
« Reply #1 on: February 25, 2020, 01:23:44 am »
Hi!

Use an intermediate string:

Code: Pascal  [Select][+][-]
  1. var
  2. s : String;
  3. ....
  4. s := Form1.Caption;
  5. PathStr := GetPart(['] '], [], s, false, false);
  6.  
  7.  
Winni

VinDerKlaus

  • New Member
  • *
  • Posts: 27
Re: What does this error mean and how do I fix?
« Reply #2 on: February 25, 2020, 01:28:48 am »
Many thank you winni,

It works now.
I wonder why it does this?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: What does this error mean and how do I fix?
« Reply #3 on: February 25, 2020, 01:45:54 am »
Hi!

The string in getPart is a var parameter.

You are not allowed  to pass properties as var parameter.

Form.Caption is a property.
So copy it intermediate to a string.
Then you can pass the string as var parameter.

Not so nice but that's the (today) syntax.

Winni

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: What does this error mean and how do I fix?
« Reply #4 on: March 24, 2020, 11:34:40 pm »
Many thank you winni,

It works now.
I wonder why it does this?
It traces waaaaay back to more than 10 years ago: https://wiki.freepascal.org/User_Changes_2.4.0#Treating_direct-mapped_properties_as_regular_fields

 

TinyPortal © 2005-2018