Loading - reading - Showing ( memory )

Heya guyz... very easy... well not to me :P

I created a .txt with the number 5 inside... close it...

1 - I want to load the .txt file and save it into a MemoryStream
2 - Read this memory and, since its a number, save the value into a var ( integer type )
3 - use the integer var like showmessage(inttostr(intvar+5));
4 - get my 10 :P
5 - release the memory


ty in advance
LVL 7
furmigaAsked:
Who is Participating?
 
paulb1989Connect With a Mentor Commented:
OR this one uses the unit exeMod (http://www.geocities.com/gacarpenter386/)

var
  MS: TMemoryStream;
  StrVar: String;
  IntVar: Integer;
begin
  MS := TMemoryStream.Create;

  try
    MS.LoadFromFile('myfile.txt');
    Stream2String(MS, StrVar);
    IntVar := StrToInt(StrVar);
    ShowMessage(IntToStr(IntVar + 5));
  finally
    MS.Free;
  end;
end;
0
 
paulb1989Commented:
var
  IntVar: Integer;
  F: TStringList;
begin
  F := TStringList.Create;

  try
    F.LoadFromFile('myfile.txt');
    IntVar := StrToInt(F[0]); // First Line
    ShowMessage(IntToStr(IntVar + 5));
  finally
    F.Free;
  end;
end;
0
 
furmigaAuthor Commented:
Heyz man.. tx a lot :)
0
All Courses

From novice to tech pro — start learning today.