SRL Archive - Reflection Help

Pass Integers to R_GetNpcsMulti


Bixby Sayz

2011-09-07 20:20:43

Having trouble passing a list of integers into R_GetNpcsMulti.

Consider this code:
program new;

{$i srl\srl\misc\smart.scar}
{$i srl\srl.scar}
{$i reflection\reflection.simba}

var
SomeIntegerArray: TIntegerArray;
SomeVariantArray: TVariantArray;

begin
Smart_Server := 1;
ClearDebug;
SetupReflection;

// This is valid...
R_GetNPCsMulti([0, 1, 2], FALSE);

// As is this...
SomeVariantArray := [0, 1, 2];
R_GetNPCsMulti(SomeVariantArray, FALSE);

// But this is not...
SomeIntegerArray := [0, 1, 2];
R_GetNPCsMulti(SomeIntegerArray, FALSE);

// Nor is this...
SomeIntegerArray := [0, 1, 2];
SomeVariantArray := SomeIntegerArray;
R_GetNPCsMulti(SomeVariantArray, FALSE);

end.
It generates the error:
Error: Type Mismatch at line 25
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap]

Which means I have to replace all my TIntegerArrays with TVariantArrays? Say it ain't so!

TomTuff

2011-09-07 20:29:51

'Tis so, sorry.

Alternatively, create a function that turns a TIntegerArray into a TVariantArray.

Bixby Sayz

2011-09-07 21:19:10

From: TomTuff
Alternatively, create a function that turns a TIntegerArray into a TVariantArray.

For the sake a few ms not worth it. Just feels dirty using variants.

mormonman

2011-09-07 23:47:57

From: Bixby Sayz
For the sake a few ms not worth it. Just feels dirty using variants.


Why does it feel dirty? Variants are kind of a PS hack-a-round.

Nava2

2011-09-08 00:18:50

Variants are cool, and they work. But in this case, I see your frustration. Frankly, you will have to deal with it though. This makes the most sense by far!

Bixby Sayz

2011-09-08 08:51:26

From: mormonman
Why does it feel dirty? Variants are kind of a PS hack-a-round.

Back in the day in my previous life as a Delphi programmer (yes I am older than dirt compared to you young whippersnappers) I initially loved variants: soooo flexible.

Then I realized my sluggish code ran 5 times faster without them and users stopped complained about how freaking slow the program was. Since then I avoid variants at all costs unless absolutely no choice there is no other way necessary.