Borland C++, event functions
Can anyone tell me how do I display the calculation in the TLabelEdit
and why can't I do the mathematics calculation? I have included <math.h>
.
void __fastcall TForm1::LabelEdit1(TObject *Sender)
{
float h;
if (yRed == 90) {
h =开发者_Python百科 160*4.4/(2*xRed*tan39 - 160*tan39 + 160*tan40) //cannot compile due to error
Height->SubLabel( h ); //Is this how you write it??????
}
}
Please advice.
tan
is a function in math.h
. You call it like any other function. You don't just put the number after the name.
Also keep in mind that tan works on radians, not degrees, so you probably don't want the values 39 and 40 anyway.
(Also, strongly consider moving from Turbo-C++ -- it is an extremely old and poorly supported compiler)
As said in the other answer tan
is function from math.h
so you need to #include
it and call it as function so tan(angle)
. Beware the angle is in radians [rad]
so you need to convert from degrees !!!
There are 2 option how to write stuff to visual components. Using Caption
and Text
properties. Labels,buttons,Forms etc have Caption
, Edit boxes, memos, etc... have Text
. They are strings so you need to print your number to string (you can directly assign int,float,double,...
to it but sprintf
is better as you can control the formatting). Here is how I see it should look like:
#include <math.h>
const float deg=M_PI/180.0;
const int xRed=???;
const int yRed=???;
void __fastcall TForm1::LabelEdit1(TObject *Sender)
{
float h;
if (yRed == 90)
{
h = (160.0*4.4*tan(39.0*deg)/(2.0*float(xRed)))
- (160.0*tan(39.0*deg))
+ (160.0*tan(40.0*deg));
LabelEdit1->Caption=AnsiString().sprintf("h = %.3f",h);
}
}
btw. for visual components with Canvas
(Like Form,PaintBox,...) you can write text directly using:
Canvas->TextOutA(x,y,"text");
精彩评论