Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

Procedure returns

How do I have a procedure return more than one string, e.g

Procedure Get3answers;
Begin
result := 'blue';
result2 := 'yellow';
result3 := 'red';
end;

Main:
Get3answers(result) := edit1.text
Get3answers(result2) := edit2.text
Get3answers(result3) := edit3.text

Thanks
0
smurff
Asked:
smurff
  • 2
  • 2
  • 2
  • +4
1 Solution
 
TheNeilCommented:
By defining a parameter list eg:

PROCEDURE Get3Answers(VAR Ans1, Ans2, Ans3 : STRING);
BEGIN
  Ans1 := 'Blue';
  Ans2 := 'Yellow';
  Ans3 := 'Red';
END;

The Neil =:)
0
 
edeyCommented:
or returning a TStringList

Gl
Mike
0
 
kretzschmarCommented:
? never seen something like this (a procedure with results)

try this

Type TAnswers = Record
                                Result1 : String[50];
                                Result2 : String[50];
                                Result3 : String[50];
                            end;

Function Get3Answers : TAnswers;
begin
  Result.Result1 := 'Blue';
  Result.result2 := 'yellow';
  Result.result3 := 'red';
end;

Main:
Var Answers : TAnswers;
begin
  Answers := Get3Answers;
  Edit1.Text := Answers.Result1;
  Edit2.Text := Answers.Result2;
  Edit3.Text := Answers.Result3;
end;


something mixed in your q, hoping i'm on the right path

meikl
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
TheNeilCommented:
Sorry, in your case you'd have to call the routine with a set of simple String variables and then assign them OR define the parameter list to take the edit boxes themselves (as you can't specify the Text property of your edit boxes as string parameters) eg:

PROCEDURE Get3Answers(edt1, edt2, edt3 : TEdit);
BEGIN
  edt1.Text := 'Blue';
  edt2.Text := 'Yellow';
  edt3.Text := 'Red';
END;

The Neil =:(


0
 
kretzschmarCommented:
yup, theneil, thought also on this ;-)
0
 
smurffAuthor Commented:
Thanks for all your replies, Ill try and explain it. Ive created a DLL that when called goes away and gets 3 string answers. I want the App that called the DLL to use the 3 answers.
Sorry about all this, ive been working on this all day and I feel stupid :)
0
 
MadshiCommented:
A side note: If you want to transport a (long) string (or 2 or 3) from a DLL to an application or vice versa, you have to use ShareMem. One way out is using short strings (like string[50]).

If you have D4 or D5, you can also use this one (needs ShareMem again):

var TDAString = array of string;

function Get3Answers : TDAStrings;
begin
  SetLength(result, 3);
  result[0] := 'blue';
  result[1] := 'yellow';
  result[2] := 'red';
end;

Then in your app you can do this:

var strArr : TDAStrings;
begin
  strArr := Get3Answers;
  edit1.Text := strArr[0];
  edit2.Text := strArr[1];
  edit3.Text := strArr[2];
end;

This way you can even give back a variable number of strings...   :-)

Regards, Madshi.
0
 
robert_marquardtCommented:
BTW you can declare a method procedure and implement function and D4 compiles happily without error. D3 throws the deserved error.
0
 
simonetCommented:
>One way out is using short strings (like string[50]).

BEtter yet to use pchars, since they don't impose a limit on the size of the string.

Also, instead of using something like "String[50]", just disable the Huge string support in the linker/compiler options of the project.

Alex
0
 
smurffAuthor Commented:
Again, thanks for everybodys help. This was really sending me crazy.
Cheers.
Smurff
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now