Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Thread Tools Display Modes
Old 04-06-2018, 05:45 AM
ShaunVW ShaunVW is offline
Join Date: Feb 2012
Posts: 47
Default Variant array to hold strings + stringlists

Hello, please can someone advise me.
I am trying to create an array that holds both strings and stringlists. Is this possible? This is what I have tried already, but on compile it throws an error "Incompatible types: Variant and TStringList"
The reason I am doing this is to hold all the parts needed to be emailed.

Function TMainForm.SendMail(rec1, rec2, rec3, subj: String; emailBody: TStringList): Boolean;
 emailVariantArray : Array[1..10, 1..5] of Variant;
 emailVariantArray[1, 1] := rec1;
 emailVariantArray[1, 2] := rec2;
 emailVariantArray[1, 3] := rec3;
 emailVariantArray[1, 4] := subj;
 emailVariantArray[1, 5] := emailBody;
Thank you.
Reply With Quote
Old 04-06-2018, 07:52 AM
Norrit Norrit is offline
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,335

Why store this in an anonymous type like VarArray?
You could easily build a class to hold these properties, and then have a T(Object)List instead of the base array (max 10 items)

But if you want to stick to the array, there are some hacks you could do.
#1: very dirty, and is very risky:
emailVariantArray[1, 5] := TObject(@emailBody);
This should store the pointer to the list, but when the list gets out of scope this will crash and burn

#2: easiest and safest:
emailVariantArray[1, 5] := emailBody.DelimitedText;

But in both solutions you'll have to cast it back to a TStringList when using.
Reply With Quote
Old 04-06-2018, 08:56 AM
ShaunVW ShaunVW is offline
Join Date: Feb 2012
Posts: 47

Thanks Norrit for the response, I'll try the 2nd option.
Easy enough to cast back to StringList.

Reply With Quote
Old 04-20-2018, 02:30 AM
lex lex is offline
Junior Member
Join Date: Feb 2012
Posts: 27

Norrit's idea is good so do not reject it

Another option if you like
Set as side a number of items in your stringlist for your arrays
And add to the stringlist starting from a known count number as you need it

what ever way you like to manage your data
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT. The time now is 04:57 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.