BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Function scope and acting on variables

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Michael Brown
Guest





PostPosted: Fri Aug 29, 2003 10:18 am    Post subject: Re: Function scope and acting on variables Reply with quote



"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 Smile
Add michael@ to emboss.co.nz - My inbox is always open



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.