Re:TTrackBar woes, BCB6
Okay, I got it figured out (if anyone was interested or paying any
attention).
I'm posting my solution for critique by you Pros out there. I had to cut
out the proprietary routines, and I had to make the variables generic.
Also, I did not test the code after making these changes, so there could be
a typos...
/**********************************************************/
typedef struct _ENGINEPARAMS {
double res; // resolution
double max; // maximum
double min; // minimum
double ofs; // offset
double val; // value read
char pUnit[9]; // string for the Units display
int xER; // multipliER
} Tparams;
/**********************************************************/
Tparams pms[10000];
/**********************************************************/
/**********************************************************/
// To Set:
void __fastcall TForm1::ComboBox1_OnChange(TObject *Sender)
{
int i;
pms[i].ofs = pms[i].min;
if (pms[i].min < 0)
{
pms[i].max -= pms[i].min; // minus a negative = addition
pms[i].min = 0;
}
pms[i].xER = MaxInt / pms[i].max; // MaxInt = 32,767
pms[i].max *= pms[i].xER;
pms[i].res *= pms[i].xER;
TrackBar1->Frequency = pms[i].max / 10;
TrackBar1->Max = pms[i].max;
TrackBar1->LineSize = pms[i].res;
if (pms[i].res < 1)
{
TrackBar1->LineSize = pms[i].res + pms[i].res;
}
TrackBar1->Min = pms[i].min;
TrackBar1->Position = pms[i].val;
lblDescription->Caption = pms[i].desc;
str.printf("%5.2f %s", pms[i].ofs, pms[i].pUnit);
lblSpnMin->Caption = str;
double TrueValue;
TrueValue = (pms[i].max / pms[i].xER) + pms[i].ofs;
str.printf("%5.2f %s", TrueValue, pms[i].pUnit);
lblSpnMax->Caption = str;
}
/**********************************************************/
/**********************************************************/
// To Get:
void __fastcall TForm1::TrackBar1_OnChange(TObject *Sender)
{
pms[i].val = TrackBar1->Position;
double TrueValue = (pms[i].val / pms[i].xER) + pms[i].ofs;
AnsiString str;
str.printf("= %5.2f %s", TrueValue, pms[i].pUnit);
lblSpnNewValue->Caption = str;
}
/**********************************************************/
/**********************************************************/
// End Of Code
If anyone sees any part that is inefficient or could be otherwise done
better, please share your information!
Bonus question: Why did I elect to call the structure variables pms? :)
Happy Halloween!