SRL Archive - SRL Archives

InArr();


noidea

2009-08-21 00:25:44

well, for those lazy people who dont want to use a certain type of InBlankArr(), here :p


Rounds two: THanks to Naum :)
function InArrEx(Arr: TVariantArray; Any: Variant; Var Place : Integer): Boolean;
var
i: Integer;
begin
for i := 0 to high(Arr) do
try
result := Arr[i] = Any;
if result then
begin
Place := I;
Exit;
end;
except
end;
end;

Function InArr(Arr: TVariantArray; Any: Variant): Boolean;
var
spot: Integer;
begin
result := InArrEx(Arr, Any, spot);
end;


Original:
function InArr(Arr: TVariantArray; Any: Variant): Boolean;
var
i: Integer;
begin
for i := 0 to high(Arr) do
try
result := Arr[i] = Any;
if result then exit;
except
end;
end;

I was reading Naums tut and thought "Oh no one has made just a general 'InArr'?"

So I thought I'd try :D
Took about two minutes.

Example : writeln(InArr(['wat', 2, 'haf', 244, true], 2));

Naum

2009-08-21 00:39:05

Also have an InArrEx:

function InArrEx(Arr: TVariantArray; Any: Variant; Var Place : Integer): Boolean;
var
i: Integer;
begin
for i := 0 to high(Arr) do
try
result := Arr[i] = Any;
if result then
begin
Place := I;
Exit;
end;
except
end;
end;

noidea

2009-08-21 00:44:01

Done ^.^

Gu3st...

2009-08-21 00:58:41

I don't like the use of try except, does anyone know if it affects the speed/cpu usage/ram usage?
I am sure there is some way to remove the try except :)

Other than that: good job :)

ian.

2009-08-21 01:19:39

Ermm, try except and the other one (unless I think?) are all very low level functions, from what I remember. Like or/xor/not/blah blah blah. :) Not entirely sure, though.

noidea

2009-08-21 01:33:07

From: ian.
Ermm, try except and the other one (unless I think?) are all very low level functions, from what I remember. Like or/xor/not/blah blah blah. :) Not entirely sure, though.


the try and except are for runtime errors.

If you're Any is an Integer, and there is a string in the Arr, then it will produce a runtime error.

ian.

2009-08-21 01:41:19

I know what they're for.. >_> :) He said that they're slow. I'm saying they're low level and aren't slow/don't use much RAM/anything like that. :)

noidea

2009-08-21 01:48:59

From: ian.
I know what they're for.. >_> :) He said that they're slow. I'm saying they're low level and aren't slow/don't use much RAM/anything like that. :)


oh, sorry :x

bullzeye95

2009-08-21 02:55:48

From: ian.
I know what they're for.. >_> :) He said that they're slow. I'm saying they're low level and aren't slow/don't use much RAM/anything like that. :)


I don't know what you mean by "they're low level," but they're almost twice as slow as regular begin..end blocks.

ian.

2009-08-21 03:07:49

From: bullzeye95
I don't know what you mean by "they're low level," but they're almost twice as slow as regular begin..end blocks.


I didn't wanna say low level functions/procedures, because I don't know the real name for them. And are begin..end blocks slow? :p I'm just trying to tell Zyt3x that try except isn't very slow. =X

bullzeye95

2009-08-21 03:26:30

From: ian.
I didn't wanna say low level functions/procedures, because I don't know the real name for them. And are begin..end blocks slow? :p I'm just trying to tell Zyt3x that try except isn't very slow. =X


I'm not really sure if it's possible to test the speed of begin..end blocks :\

ian.

2009-08-21 04:48:17

Well in general you should be able to figure out if they're slow or fast.. I'd think.. :p

bullzeye95

2009-08-21 05:31:40

Well, if you tell me how, I'll test it :rolleyes:

noidea

2009-08-21 06:07:25

Sooo, has any one experienced problems with the function?

ian.

2009-08-21 06:55:49

Works good. ^^ I couldn't find any problems.

Naum

2009-08-21 12:03:19

I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like noidea's stuff :)

ian.

2009-08-21 12:09:30

From: NaumanAkhlaQ
I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like ian's stuff :)


lolwut? =X

Naum

2009-08-21 12:28:30

From: ian.
lolwut? =X


Because I luff you ;). Changed

noidea

2009-08-22 22:28:24

From: NaumanAkhlaQ
I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like noidea's stuff :)


omfg <3 that would be like a wet dream.

bullzeye95

2009-08-22 22:54:18

From: NaumanAkhlaQ
I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like noidea's stuff :)


Because as far as I can tell, you can only pass TVariantArrays. You can't even typecast other array types to a TVariantArray; it will still give a runtime error.

Naum

2009-08-23 00:02:25

From: bullzeye95
Because as far as I can tell, you can only pass TVariantArrays. You can't even typecast other array types to a TVariantArray; it will still give a runtime error.


I'll test it first, btw I dig your sig.

ZephyrsFury

2009-08-23 07:27:07

If the parameter requires a TVariantArray wouldn't trying to give a var defined as a TintegerArray or TStringArray for example result in a type mismatch error?

senrath

2009-08-23 07:48:13

From: ZephyrsFury
If the parameter requires a TVariantArray wouldn't trying to give a var defined as a TintegerArray or TStringArray for example result in a type mismatch error?

That is correct.

noidea

2009-08-23 07:50:25

I just tested, and and it looks like it =\
One could always change that TIntegerArray to a TVariant array :D
but that could cause other problems in the long run =\

ZephyrsFury

2009-08-23 09:31:19

You could always ask Freddy to make an InArr function. I'm not sure how but using delphi you can make functions take undefined types (similar to how Swap() can swap any two variables as long as the types are the same). Perhaps you could do it in a plugin too although I'm not too sure.

bullzeye95

2009-08-23 09:34:37

From: ZephyrsFury
You could always ask Freddy to make an InArr function. I'm not sure how but using delphi you can make functions take undefined types (similar to how Swap() can swap any two variables as long as the types are the same). Perhaps you could do it in a plugin too although I'm not too sure.


To accept untyped variables, do something like:
procedure lulz(const mudkipz);
begin
end;

I tried making an InArr in a plugin, but I kept getting access violations and runtime errors. Maybe it's possible and I just didn't try long enough though.

senrath

2009-08-23 20:30:32

I have one that I made, but it only accepts TIntegerArrays, TStringArrays, TExtendedArrays, and TVariantArrays.

Edit: Nevermind. Apparently SCAR can't handle overloaded functions in plugins.

Naum

2009-08-23 21:23:34

From: senrath
I have one that I made, but it only accepts TIntegerArrays, TStringArrays, TExtendedArrays, and TVariantArrays.

Edit: Nevermind. Apparently SCAR can't handle overloaded functions in plugins.


Yeah, I found out the same lol. Just a suggestion for InStrArr to be put into WizzyPlugin or SCAR since it eats up speed in Text.Scar.