Discussion:
const functions would be nice.
(too old to reply)
Skybuck Flying
2014-04-30 15:05:29 UTC
Permalink
Following code does not compile:

const function Region( ParaX, ParaY, ParaWidth, ParaHeight : integer ) :
TRegion;
begin
result.mX := ParaX;
result.mY := ParaY;
result.mWidth := ParaWidth;
result.mHeight := ParaHeight;
end;

const
RegionGameLoginScreen = Region(610,670,60,37);
RegionGameLoginError = Region(503,341,158,47);

"
[dcc32 Error] unit_TDiliNewSwitcher_version_017.pas(132): E2026 Constant
expression expected
"

Would be nice if constant functions were supported to be able to initialize
"constant structures/variables".

Bye,
Skybuck.
Maynard A. Philbrook Jr.
2014-04-30 20:59:44 UTC
Permalink
Post by Skybuck Flying
TRegion;
begin
result.mX := ParaX;
result.mY := ParaY;
result.mWidth := ParaWidth;
result.mHeight := ParaHeight;
end;
const
RegionGameLoginScreen = Region(610,670,60,37);
RegionGameLoginError = Region(503,341,158,47);
"
[dcc32 Error] unit_TDiliNewSwitcher_version_017.pas(132): E2026 Constant
expression expected
"
Would be nice if constant functions were supported to be able to initialize
"constant structures/variables".
Bye,
Skybuck.
Yo u are so far out of left field it isn't funny..

You can use a type record to directly define a constant that
gets filled in at compile time, as long as the paramsa are not
dynamic.

Const
WhatEverRegionType:TRegion = Tregion(mx:??, my:??? etc)


of course you have to use a switch to make that a writable constant
in case you want to change that dynamically...

Jamie
Skybuck Flying
2014-04-30 22:55:34 UTC
Permalink
Post by Skybuck Flying
TRegion;
begin
result.mX := ParaX;
result.mY := ParaY;
result.mWidth := ParaWidth;
result.mHeight := ParaHeight;
end;
const
RegionGameLoginScreen = Region(610,670,60,37);
RegionGameLoginError = Region(503,341,158,47);
"
[dcc32 Error] unit_TDiliNewSwitcher_version_017.pas(132): E2026 Constant
expression expected
"
Would be nice if constant functions were supported to be able to initialize
"constant structures/variables".
Bye,
Skybuck.
"
Yo u are so far out of left field it isn't funny..

You can use a type record to directly define a constant that
gets filled in at compile time, as long as the paramsa are not
dynamic.

Const
WhatEverRegionType:TRegion = Tregion(mx:??, my:??? etc)


of course you have to use a switch to make that a writable constant
in case you want to change that dynamically...

Jamie
"

I know that kind of code, it's very unhandy.

It requires much more typing, since those fields have to be re-declared
constantly.

With the function approach only parameters have to be passed.

So it's a typing-efficiency thing.

It's probably also more "other language friendly".

Bye,
Skybuck.

Loading...