Log in

View Full Version : TstringArray to TIntegerArray



sm0k3
04-25-2011, 07:39 PM
Ihave a value in a TstringArray like this

The TStringArray is OBST
so

OBST[i][0] has a value from an ini of: 3235182,3244322 and are colours
how can i turn this into the TIntegerArray that FindColorEx expects ? :)

Sex
04-25-2011, 07:43 PM
Why don't you just declare it a TIntegerArray from the start and populate it using StrToInt? :P

You'll have to create a whole new one for this.
var
OldArr : TStringArray;
NewArr : TIntegerArray;
i, h : integer;
begin
OldArr := ['12', '34', '56', '78'];
h := high(OldArr);
SetArrayLength(NewArr, h + 1);
for i := 0 to h do
NewArr[i] := StrToIntDef(OldArr[i], -1);
OldArr := [];
end.

sm0k3
04-25-2011, 09:33 PM
Perfect thanks

Home
04-26-2011, 09:36 AM
Can't you use TVariantArray for this?

~Home

Iamadam
04-26-2011, 09:41 AM
Variants have types. So it remains as a string. (unless I'm mistaken)
Best thing to do would be read it in using intToStr straight away, and bypass the string array completely (as sex said).

Home
04-26-2011, 10:00 AM
Variants have types. So it remains as a string. (unless I'm mistaken)
Best thing to do would be read it in using intToStr straight away, and bypass the string array completely (as sex said).

program new;
var
ReqArr : TVariantArray;
i, h : integer;
begin
ReqArr := [12, 34, 56, 78];
For i := 0 to High(ReqArr) do
Writeln(ReqArr[i]);
end.

Tell me if i'm totally off road :P

~Home

Iamadam
04-26-2011, 11:09 AM
Ah look at that it does work :) How awesome!

program new;
var
ReqArr : TVariantArray;
i, h : integer;
begin
ReqArr := ['123', '343', '563', '78'];
For i := 0 to High(ReqArr) do
Writeln(toStr(ReqArr[i] + 1));
end.
I was thinking Java. You can store anything in an 'Object' (equivalent of Variant), but it keeps its type (so you can't add strings to ints or anything).

Useful.