Solved

Procedure returns

Posted on 2000-05-12
10
157 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 46
Is anyone willing to have a look through this code and help debug? 25 61
Find and Replace Stream with 0s 8 57
Delphi inherited method 6 63
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

22 Experts available now in Live!

Get 1:1 Help Now