Topic: Let's have some fun with functions and procedure

Hello Dmitry and all MVD fans,


Let's have some fun, shall we ? :-)


I would like to know how (if possible) I can propagate variables.


Let's say I have this :


function DoSomething1(Data1 : String) : String;
begin
     Result := DoSomething1;
end;

function DoSomething2(Data2 : String) : String;
begin
     Result := DoSomething2;
end;
...
function DoSomethingN(DataN : String) : String;
begin
     Result := DoSomethingN;
end;

and making use of the fuctions, the following procedure :


procedure1...
var
     text1, text2... textN : String;
begin
     text1 := DoSomething1(Data1);
     test2 := DoSomething2(Data2);
     ...
     textN := DoSomethingN(DataN);
end;

Procedure1 is so long that I want to terminate it and continue the logical code in another procedure.


How could I do something like :

procedure 2...
var
     info1, info2... infoN : String;
begin
     info1 := text1;
     info2 := text2;
     ...
     infoN := textN;
end;

In other words, is it possible to propagate variables through procedures, and if yes, how ?


Wish you all a good day, it's good to be back !!


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Let's have some fun with functions and procedure

mathmathou !
Thank You Much For Share Knowledge
I Send Code to My Student Read ...

My Visual Database : I Love You
Easy For Beginner Student For Me

Re: Let's have some fun with functions and procedure

Hello prahousefamily,

Don't give that to your students, this is a question I ask, not a solution I give :-)

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Let's have some fun with functions and procedure

mathmathou
Yes, you can, using global variables, example


var
   text1, text2... textN : String;


procedure1...
begin
     text1 := DoSomething1(Data1);
     test2 := DoSomething2(Data2);
     ...
     textN := DoSomethingN(DataN);
end;

procedure 2...
var
     info1, info2... infoN : String;
begin
     info1 := text1;
     info2 := text2;
     ...
     infoN := textN;
end;

begin
end.

but often using global variables not good programming style.

Dmitry.

Re: Let's have some fun with functions and procedure

Thanks Dmitry,


I'll try you method just to see if I can implement it.


I'm aware global variables are not recommended, but I think my code and process is so long that if anything goes wrong, I might loose the result of the beginning of the logical treatment.


Could you give us a head-up on exception handling ?

I saw some try/catch/except somewhere on the forum, but did not quite succeed in using it :-(


Cheers



Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Let's have some fun with functions and procedure

I m think same mathmathou

I'm aware global variables are not recommended, but I think my code and process is so long that if anything goes wrong, I might loose the result of the beginning of the logical treatment.

Um because me and my student start learn code it easy when  read very long code and fix bug ...
Thanks Dmitry and Mathias For Good Think And Comment..

My Visual Database : I Love You
Easy For Beginner Student For Me