Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Procedure returns

Posted on 2000-05-12
10
Medium Priority
?
165 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
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.

 
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 80 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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