I'm writing a calculator program that receives a string and returns the result (everything in console mode), using Delphi 6. I use a FOR to advance and evaluate the sub-expressions, but the compiler leaves the FOR without reason (I mean that Delphi does not give me any warnings or errors, it simply skips the rest of the FOR begin-end sentence).

I'd like to know if I can edit the debugger options to prevent this kind of behaviour.

What does your for loop code look like? The compiler obviously has a reason to skip!

What does your for loop code look like? The compiler obviously has a reason to skip!

Thanks!
This is the FOR:

for j:=1 to cant_op do
begin
sub_expres:=extract_str(expres,alfa);
lambda:=length(sub_expres)+2;
number:=op_entre_term(sub_expres);
delete(expres,alfa,lambda);
insert(floattostr(number),expres,alfa);
end;

"cant_op" counts how many times the program evaluates a mathematical sub_expression. its minimum value is 1, so the for executes at least once.

"extract_sub" takes a long expression and copies the first level of parenthesis into sub_expres

"alfa" and "lambda" are used later so that the sub_expression is deleted from the main string appropriately

"op_entre_term" is a custom function; it works properly but never returns its result into "number" (they are of the same type, real). the bold line is the last one the compiler reads before skipping into the next sentence, thus quitting the FOR sentence.

any clues? :)

Can you temporarily add a few write statements to your code to display and follow the value of cant_op?

sorry for asking the obvious but what happens if you put in a breakpoint and step into (f7): number:=op_entre_term(sub_expres);

do you have error trapping? i'd put a watch on each of the variables you're dealing with too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.