SRL Archive - OSR Help

TVariantArray problems


bud_wis_er_420

2013-02-19 13:34:48

How do I get this to work I keep getting a Type Type Mismatch error. I need the ItemArray to stay a TVariantArray or I could make it a TStringArray but I will need to change it to a TVariantArray later for use with the WaitFuncEx() Function. I'm new to TVariantArray's but I found two tuts on them and from what I gathered this should work.

Edit:
Sry bout the Title, Don't know what happend. Was suppose to say "TVariantArray problems"
EndEdit


program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}

type
MSObject = record
ItemArray: TVariantArray;
end;

var
TSAItem: TStringArray;
Item: MSObject;

procedure LoadObj;
begin
with Item do
begin
ItemArray := ['shark', 'aw sha', 'hark'];
end;
end;

begin
SetUpSRL;
LoadObj;
TSAItem := Item.ItemArray;
IsUpTextMultiCustom(TSAItem)
End.

masterBB

2013-02-19 14:11:40

Uhm, good question. If you are using Lape you can use:

[INDENT]TSAItem := TStringArray(Item.ItemArray);[/INDENT]

But since it is pascalscript(I assume), the following would be the solution:

[INDENT]TSAItem := Item.ItemArray as TStringArray;[/INDENT]

However, it can't be converted, So I think you can only do it manual by looping through the array.

bud_wis_er_420

2013-02-19 14:26:13

Lape hmm, never heard of it, will look into it tho. But ok I can loop it threw then. Just thought there would be a quicker way. Like; TVar:=ConvArray(TVA, ' '); or something. Thx tho.

masterBB

2013-02-19 14:36:44

{*
* TVAToTSA
*
* Converts a TVariantArray to TStringArray. Note that errors aren't handled.
}
function TVAToTSA(const params: TVariantArray): TStringArray;
var
I: Integer;
begin
SetLength(Result, Length(params));

for I := High(params) downto 0 do
Result[I] := params[I];
//can also be Result[I] := ToStr(params[I]) if you want to be sure there are no errors
end;

Quickly written.

Hobbit

2013-02-19 14:43:30

Fixed title

bud_wis_er_420

2013-02-21 01:53:27

Thx Hobbit.

I been busy with work so haven't had time to work on this till now, but I'm still having problems with this.
I guess I should have used this example first because the waitfunc is the function I'm trying to get working. I still keep getting this error: Error: Exception: Invalid parameter at line 267. And it opens the srl timing include.

program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}

var
TVA: TVariantArray;


Begin
SetUpSRL;
TVA:= ['shark', 'aw sha', 'hark'];
WaitFuncEx('IsUpTextMultiCustom', TVA, 100, 1000)
End.

i luffs yeww

2013-02-21 02:08:38

From: bud_wis_er_420
Thx Hobbit.

I been busy with work so haven't had time to work on this till now, but I'm still having problems with this.
I guess I should have used this example first because the waitfunc is the function I'm trying to get working. I still keep getting this error: Error: Exception: Invalid parameter at line 267. And it opens the srl timing include.

program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}

var
TVA: TVariantArray;


Begin
SetUpSRL;
TVA:= ['shark', 'aw sha', 'hark'];
WaitFuncEx('IsUpTextMultiCustom', TVA, 100, 1000)
End.


IsUpTextMultiCustom is expecting a TStringArray, not three strings, which is what you're giving it. And since WaitFuncEx needs a TVariantArray, you have a TStringArray in your TVariantArray, like so:


{$i SRL/SRL.simba}

var
TVA: TVariantArray;
TSA: TStringArray;

begin
SetUpSRL;
TSA := ['shark', 'aw sha', 'hark'];
TVA := [TSA];
WaitFuncEx('IsUpTextMultiCustom', TVA, 100, 1000);
end.

bud_wis_er_420

2013-02-21 02:13:52

lol was just about to post with this saying I figured it out finally. Thx tho

program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}

var
TVA: TVariantArray;
TSA: TStringArray;



Begin
SetUpSRL;
TSA := ['shark', 'aw sha', 'hark'];
TVA:= [TSA];
WaitFuncEx('IsUpTextMultiCustom', TVA, 100, 1000)

End.