Solved

Procedure returns

Posted on 2000-05-12
10
163 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 5

Expert Comment

by:TheNeil
ID: 2804846
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
ID: 2804850
or returning a TStringList

Gl
Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2804873
? 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
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!

 
LVL 5

Expert Comment

by:TheNeil
ID: 2804874
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
ID: 2804877
yup, theneil, thought also on this ;-)
0
 
LVL 3

Author Comment

by:smurff
ID: 2804958
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
ID: 2804989
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
ID: 2805027
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
ID: 2805153
>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
ID: 2809866
Again, thanks for everybodys help. This was really sending me crazy.
Cheers.
Smurff
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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