 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Michael Brown Guest
|
Posted: Fri Aug 29, 2003 10:18 am Post subject: Re: Function scope and acting on variables |
|
|
"Dean" <dean[no-spam]@weany.com> wrote
| Quote: | Hi,
I'm getting myself a little confused with a function call I'm trying to
build.
I need a function that returns a bool result and is capable of acting on
"S", a string, which is defined as a variable under the If.....then
procedure (not the function). i.e. the whole thing looks kind of like this
(I've cut straight down to the relevant bits):-
procedure TForm1.IncomingPacket;
S : String; <----- variable "S" is under this procedures scope
begin
If ReadStringFromPacket(S) then StringList.Add(S) else exit;
end;
function ReadStringFromPacket(Str : String) : Bool;
begin
//just testing
Str := "test";
Result := false;
end;
OK, now this doesn't work, as "S" is still left as ''. Question is, do I
have to set S as a global variable and always use that global variable
within whatever string functions I need, or is there a neater way of
linking
the calling procedures variable scope to the receiving functions scope?
|
Just define "str" to be a var parameter:
function ReadStringFromPacket(var Str : String) : Bool;
--
Michael Brown
www.emboss.co.nz : OOS/RSI software and more
Add michael@ to emboss.co.nz - My inbox is always open
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|