Nice Easy Function Question

Hi Guys/Girls,
Straight forward one this, I have a function that passes back a string value which contains 2 seperate strings with a ^ seperator, ie

Result := 'My'+'^'+'String';

I then parser the result to obtain my two values,. Is there any way I can pass back more than one string in a function, for example

Function GetUserInf(UserCode : Integer) : String1, String2;
Begin
 Password.Locate('Key',UserCode,[]);
 String1 := Password.FieldByName('UserName').AsString;
 String2 := Password.FieldByName('PASSWORD').AsString;
End;

cheers in advance

Win95, Delphi professional 5

Stu
StuartB_99Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
MotazConnect With a Mentor Commented:
Yes you can return two values but you can not use the result of function, instead use passing parameters by reference:

Example:

procedure GetUserInf(UserCode : Integer; var String1, String2: string);
Begin
 Password.Locate('Key',UserCode,[]);
 String1 := Password.FieldByName('UserName').AsString;
 String2 := Password.FieldByName('PASSWORD').AsString;
End;

Motaz
0
 
kretzschmarCommented:
hi,

another way

Type TDualString = Record
                      String1 : String;
                      String2 : String;
                   end;

Function GetUserInf(UserCode : Integer) : TDualString;
Begin
 Password.Locate('Key',UserCode,[]);
 Result.String1 := Password.FieldByName('UserName').AsString;
 Result.String2 := Password.FieldByName('PASSWORD').AsString;
End

meikl
0
 
StuartB_99Author Commented:
Thanx Motaz, I was getting a bit sick of writing massive parser units just to format a massive result from a function, you truly have made my life a lot easier and also made my exe about 15MB smaller !!!!!! ;-)

Cheers

Stu
0
All Courses

From novice to tech pro — start learning today.