Solved

Parameters

Posted on 2002-05-20
4
166 Views
Last Modified: 2010-04-04
I have a function which accepts two string and two integer parameters. when i trace through the program the two strings and one of the integers is working properly however the last integer seems to be reset before passing back. so for example i am passing it one large string

passstring:='Tank 1 has 27 Litres'

I am spliting the string into two one passing 'Tank' and the other 'Litres'
i am passing back the tank number '1' as an integer but when i pass the result of 27 back the function deletes it before passing back. I have followed every step with watches and have even added a line v(set as a temp integer) = 27 and tried to pass it back but as soon as the code gets to total:=v the watch not only  declaires total as empty but also the variable v (i have declaired var total :integer in the function). Can anyone help  

PS i am using Delphi 5 and Windows 98
0
Comment
Question by:alshepstone
[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
4 Comments
 
LVL 1

Expert Comment

by:MBo
ID: 7021595
some code required...
0
 
LVL 8

Accepted Solution

by:
Cesario earned 50 total points
ID: 7021705
Ok try this function :

Procedure ParseString(S:String; Var S1,S2:String; VAR Int1,int2:Integer);
VAR
 ms: TMemoryStream;
begin

  ms := tMemoryStream.Create;
  ms.Write ( s[1],Length(s));
  ms.position :=0;

  With tParser.Create ( ms ) DO
  Try
    S1 := TokenString;
    NextToken;
    Int1 := TokenInt;
    NextToken;
    S2 := TokenString;
    NextToken;
    Int2 := TokenInt;
  Finally
    free;
  End;

end;


procedure TForm1.Button1Click(Sender: TObject);
VAR
  s1,s2: String;
  v1,V2: Integer;
begin
  ParseString ( 'Tank 1 has 27 Litres',s1,s2,v1,v2);
  ShowMessage ( S1+#13+IntToStr(v1)+#13+S2+#13+IntTostr(v2));
end;
0
 
LVL 1

Expert Comment

by:Dumani
ID: 7023402
procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  with TStringList.Create do
  try
    Text := StringReplace('Tank 1 has 27 Litres', '', #13#10, [rfReplaceAll]);
    for i := 0 to Count - 1 do
    begin
{
      Strings[i] := Trim(Strings[i]);
      you can also use this to trim before you check...

      Strings[0] is Tank
      Strings[1] is 1
      Strings[2] is has
      Strings[3] is 27
      Strings[4] is Litres
}
    end;
  finally
    Free;
  end;
end;
0
 
LVL 4

Expert Comment

by:jsweby
ID: 7026504
Is it possible that there is a call inside your function to another procedure or function that could be changing the value of the passed parameter v?

As MBo said, this would be much easier with the code of your function.

J.
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

695 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