Recent

Author Topic: About Code Template  (Read 475 times)

yinhuajian

  • New Member
  • *
  • Posts: 10
About Code Template
« on: September 24, 2025, 06:55:53 am »
I created the following code snippet:

[myTest | myTest]
$(AttributesStart)
EnableMakros=true
$(AttributesEnd)
$Param(test1,Sync=1)
$Param(test2,Sync=2)
$Param(test1,Sync=1)
$Param(test2,Sync=2)

When I use myTest, it automatically generates:

test1
test1
test2
test2

And when I modify test1 or test2, the corresponding instances update synchronously.
However, if I change the template to:

[myTest | myTest]
$(AttributesStart)
EnableMakros=true
$(AttributesEnd)
$Param(test1,Sync=1)
$Param(test1,Sync=1)
$Param(test2,Sync=2)
$Param(test2,Sync=2)

Using myTest now generates:

test1
test1
test1
test1

Why is this happening?

n7800

  • Hero Member
  • *****
  • Posts: 554
  • Lazarus IDE contributor
    • GitLab profile
Re: About Code Template
« Reply #1 on: September 24, 2025, 08:22:34 am »
What version of Lazarus are you using? When I call the template (for trunk and 3.8), I get:

Template 1:

Code: [Select]
test1
test2
test1
test2

Template 2:

Code: [Select]
test1
test1
test1
test1

yinhuajian

  • New Member
  • *
  • Posts: 10
Re: About Code Template
« Reply #2 on: September 24, 2025, 03:34:01 pm »
Lazarus:3,6
FPC:3.3.1

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11817
  • Debugger - SynEdit - and more
    • wiki
Re: About Code Template
« Reply #3 on: October 12, 2025, 11:24:13 am »
You want the 2nd example to be
Code: Text  [Select][+][-]
  1. $Param(test1,Sync=1)
  2. $Param(test1,Sync=1)
  3. $Param(test2,Sync=3)
  4. $Param(test2,Sync=3)

or
Code: Text  [Select][+][-]
  1. $Param(test1)
  2. $Param(test1,Sync=1)
  3. $Param(test2)
  4. $Param(test2,Sync=3)

You got 4 times "$Param". They are numbered from 1 to 4.

So you want the last (4th "Param") to link to the 3rd.

From the help (if you click "insert macro")
Quote
  if param("foo") > 0 and param("foo",sync=1) < 99 then
Inserts 2 linked cells, editing either one, will change the other one too.
The value "1" refers to the position of the other "param()", so if there are more params:
  if param("bar") and param(foo) > 0 and param(foo,sync=2) < 99 then
The 2nd and third are linked (the 3rd refers to "2").



 

TinyPortal © 2005-2018