Solved

Procedure returns

Posted on 2000-05-12
10
155 Views
Last Modified: 2010-04-04
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
Comment
Question by:smurff
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 5

Expert Comment

by:TheNeil
Comment Utility
By defining a parameter list eg:

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

The Neil =:)
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
or returning a TStringList

Gl
Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
? 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
 
LVL 5

Expert Comment

by:TheNeil
Comment Utility
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
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
yup, theneil, thought also on this ;-)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 3

Author Comment

by:smurff
Comment Utility
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
 
LVL 20

Accepted Solution

by:
Madshi earned 20 total points
Comment Utility
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
 
LVL 11

Expert Comment

by:robert_marquardt
Comment Utility
BTW you can declare a method procedure and implement function and D4 compiles happily without error. D3 throws the deserved error.
0
 
LVL 15

Expert Comment

by:simonet
Comment Utility
>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
 
LVL 3

Author Comment

by:smurff
Comment Utility
Again, thanks for everybodys help. This was really sending me crazy.
Cheers.
Smurff
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now