Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I covert a string (memo text) to an erray?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How do I covert a string (memo text) to an erray?

var
calc:array[1..6000] of byte;
begin
calc:=memo1.text;
end;
 
May I ask what you want to do with it once in an array ? as you may be better to put the lines in a stream.

lou
 
I want to make an CALCULATOR.
In that memo I will put:
10+50+30/50*30
I need to read each byte, and then calc the result. Simple!
 
One can access each character in a string individually, so why not something like:-

line : string;
//NB use Square brackets in code for the i index

for i := 0 to memo1.lines.count-1 do
begin
line := memo1.lines(i);
Answer := CalculateLine(Line);
end;

function CalculateLine(Line:string) : Double;
begin
for i := 1 to length(line) do
begin
if line(i) in ['0'..'9'] then
:
if line(i) = '/' then
: etc
end
end

This is the sort of route I would take.

lou
 
Note that Delphi Strings objects, like the Memo.Lines, have a CommaText property, which returns the whole contents of the object in one go:
Code:
var calc: string;
begin
    calc := Memo1.Lines.CommaText;
end;
, then as weez says, access individual characters within calc with
Code:
calc[i]
, to get the i'th character, where the first character has the index of 1, not 0.

Weez, if you wrap your code in [ignore]
Code:
[/ignore] tags, your [ignore][/ignore]'s will come out the way you want. :) -- Doug Burbidge mailto:doug@ultrazone.com
 
Thanks Doug! I didn't know about that CommaText thingy aswell as the tag wrapper.

many thanks
lou
 
Hi, Solve !
I would like to have a look at your calculator programm ! Especially I am interested in the way you deal with operator priorities !?!? Can you send me a copy of your source code, please ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top