⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flyingmain.cpp

📁 DevExpress公司出品的Borland Delphi和C++ Builder的控件(包含完整源代码)。 ExpressSpreadSheet:交叉数据表格控件。 一款Delphi
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    cxSheetBook->ActiveCell = Point(2, 3);                       // Set the Fuel cell
  }
  catch (Exception &err) {}
  moTodayClick(this);                                            // Set toadys date
}

void __fastcall TFlyingMainForm::LoadPlaneVars()
{
  fPlaneReg        = GetCellString(1, 23);                      // Read the Plane callsign
  fPlaneCofgBitmap = GetCellString(1, 24);                      // Get the name of the C of G bitmap
  fPlanePhoto      = GetCellString(1, 25);                      // Get the name of the plane photo
  fMaxPersons      = GetCellInt(1, 26);                         // Get the max persons this plane can carry
  fMaxBaggageWt    = GetCellDouble(1, 27);                      // Get the Max baggage weight in compartment 1
  fMaxBaggageWt2   = GetCellDouble(1, 28);                      // Get the Max baggage weight in compartment 2
  fMaxTakeOffWt    = GetCellDouble(1, 29);                      // Get maximum takeoff weight
  fMaxLandingWt    = GetCellDouble(1, 30);                      // Get maximum landing weight
  fMinAftCofG      = GetCellDouble(1, 31);                      // Get Minimum aft C of G
  fMaxAftCofG      = GetCellDouble(1, 32);                      // Get Max Atf C of G
  fMaxFuelCapacity = GetCellDouble(1, 33);                      // Get Maximum fuel capacity
  fTabsFuel        = GetCellDouble(1, 34);                      // Get fuel when filled to the 'tabs'
  fWeightUnits     = GetCellString(1, 35);                      // Get units for weights
  fCofGAxisStarts  = GetCellDouble(1, 36);                      // Get the C of G at the left edge of the graph
  fCofGAxis        = GetCellInt(1, 37);                         // Get the position on the graph where the CofG axis starts (from top)
  fCofGWeightMin   = GetCellDouble(1, 38);                      // Get the minimum Weight on the weight axis
  fCofGWeightAxis  = GetCellInt(1, 39);                         // Get the position of the weight axis from the left hand edge of the graph
  fCofgStep        = GetCellDouble(1, 40);                      // Get the units between each C of G tick
  fWtStep          = GetCellDouble(1, 41);                      // Get the units between weight ticks
  fCofgMultiplier  = GetCellDouble(1, 42);                      // Get the C of G Multiplier
  fEnvelopeSize    = GetCellInt(1, 43);                         // Get the number of 'points' that comprise the C of G safety envelope
  if (fCofGEnvelope != NULL) {
    delete [] fCofGEnvelope;
    fCofGEnvelope = NULL;
  }
  fCofGEnvelope = new TPoint[fEnvelopeSize];                    // Set the Dynamic array length
  for (int i = 0; i < fEnvelopeSize; i++) {                              // For each of the 'points'
    fCofGEnvelope[i].x = GetCellInt(1, 44 + i);                 // Get X
    fCofGEnvelope[i].y = GetCellInt(2, 44 + i);                 // Get Y
  }
}

void __fastcall TFlyingMainForm::LoadImage(String const aResJpg,
                           TImage *AnImage)                    // Load an JPG image from a resource
{
  TJPEGImage *Jpi = new TJPEGImage();                          // Jpeg Image
  TResourceStream *Rs = new TResourceStream((int)HInstance,
                               aResJpg, RT_RCDATA);            // Load the Image
  try {
    Jpi->LoadFromStream(Rs);                                   // Load from the resource string
    AnImage->Picture->Bitmap->Assign(Jpi);                     // Assign to the image control
  }
  __finally {
    delete Jpi;                                                // Free the Jpeg
    delete Rs;                                                 // Free the resource stream
  }
}

double __fastcall TFlyingMainForm::GetCellDouble(const int aCol, const int aRow)
{
  TcxSSCellObject *CellObject = cxSheetBook->ActiveSheet->GetCellObject(aCol, aRow);
  double res;
  try {
    try {
      res = VarAsType(CellObject->CellValue, varDouble);       // Get the display text (not the formula) and convert
    }
    catch (Exception &err) {
      res = 0.0;                                               // JIC
    }
  }
  __finally {
    delete CellObject;                                         // Free the cell object
  }
  return res;
}

String __fastcall TFlyingMainForm::GetCellString(const int aCol, const int aRow)
{
  TcxSSCellObject *CellObject = cxSheetBook->ActiveSheet->GetCellObject(aCol, aRow);  // Get the Cell Object
  String res;
  try {
    try {
      res = CellObject->DisplayText;                           // Get the Text
    }
    catch (Exception &err) {
      res = "";                                                // JIC
    }
  }
  __finally {
    delete CellObject;                                         // Free the cell object
  }
  return res;
}

int __fastcall TFlyingMainForm::GetCellInt(const int aCol, const int aRow)
{
  TcxSSCellObject *CellObject = cxSheetBook->ActiveSheet->GetCellObject(aCol, aRow);  // Get the Cell Object
  int res;
  try {
    try {
      res = VarAsType(CellObject->CellValue, varInteger);      // Get the Display text (not the formula) and convert
    }
    catch (Exception &err) {
      res = 0;                                                 // JIC
    }
  }
  __finally {
    delete CellObject;                                         // Free the cell object
  }
  return res;
}

Word __fastcall TFlyingMainForm::GetCellColour(const int aCol, const int aRow)
{
  TcxSSCellObject *CellObject = cxSheetBook->ActiveSheet->GetCellObject(aCol, aRow);  // Get the Cell Object
  Word res;
  try {
    try {
      res = VarAsType(CellObject->Style->Brush->BackgroundColor, varInteger);         // Return the entry
    }
    catch (Exception &err) {
      res = 0;                                                 // JIC
    }
  }
  __finally {
    delete CellObject;                                         // Free the cell object
  }
  return res;
}

void __fastcall TFlyingMainForm::SetCellMessage(const int aCol, const int aRow, // Display a message in  cell at row, col
  const String aMessage,                                       // The message
  const Word aBackgroundColour,                                // The background color
  const Word aFontColour)                                      // The font color
{
  TcxSSCellObject *CellObject = cxSheetBook->ActiveSheet->GetCellObject(aCol, aRow);  // Get the Cell Object
  try {
    try {
      CellObject->Style->Brush->BackgroundColor = aBackgroundColour;  // Set the background colour
      CellObject->Style->Font->FontColor = aFontColour;        // set the font colour
      CellObject->Text = aMessage;                             // Set the text
    }
    catch (Exception &err) {}
  }
  __finally {
    delete CellObject;
  }
}


void __fastcall TFlyingMainForm::mmExitClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------

void __fastcall TFlyingMainForm::moFuelTabsClick(TObject *Sender)
{
  moFuelTabs->Enabled = false;
  TcxSSCellObject *CellObject = cxSheetBook->ActiveSheet->GetCellObject(3, 9); // Get the Cell object
  try {
    CellObject->Text = Format("%0.2f", ARRAYOFCONST((fTabsFuel)));                // Set the fuel
  }
  __finally {
    delete CellObject;                                         // Free the cell object
  }
  cxSheetBook->Recalc();                                     // Recalc
  Pb->Repaint();                                             // Update the graph
  CheckFigures();                                            // Check figures for validity
}
//---------------------------------------------------------------------------

void __fastcall TFlyingMainForm::pmWizardClick(TObject *Sender)
{
  TFlyingSeatCalcForm *FlyingSeatCalcForm = new TFlyingSeatCalcForm(this);   // Create the wizard
  TcxSSCellObject *CellObject;
  try {
    FlyingSeatCalcForm->CallSign = fPlaneReg;                                // Set the Aircraft callsign
    FlyingSeatCalcForm->ResultInKgs = UpperCase(fWeightUnits) == "KGS";      // Set which units we require the result in
    FlyingSeatCalcForm->ShowModal();
    if (FlyingSeatCalcForm->ModalResult == mrOk) {                           // Run the wizard and if they selected OK
      TPoint fCell = cxSheetBook->ActiveSheet->ActiveCell;                   // Get the active Cell
      CellObject = cxSheetBook->ActiveSheet->GetCellObject(fCell.x, fCell.y);
        try {
          CellObject->Text = FlyingSeatCalcForm->efFormula->Text;            // Copy the forumla in
        }
        __finally {
          delete CellObject;                                   // Free the cell object
        }
        cxSheetBook->Recalc();                               // recalc the sheet
        Pb->Repaint();                                       // Update the graph
        CheckFigures();                                      // Check figures for validity
    }
  }
  __finally {
    delete FlyingSeatCalcForm;                                 // Free the wizard
  }
}
//---------------------------------------------------------------------------

void __fastcall TFlyingMainForm::pmoFormatClick(TObject *Sender)
{
  cxSheetBook->ActiveSheet->FormatCells(cxSheetBook->SelectionRect); // Format
  fDepCofGColour = GetCellTColour(2, 17);                      // Get new colour JIC it changed
  fArrCofGColour = GetCellTColour(2, 19);                      // Get new colour JIC it changed
  Pb->Refresh();                                               // repaint the graph
}
//---------------------------------------------------------------------------
TColor __fastcall TFlyingMainForm::GetCellTColour(const int aCol, const int aRow) // Get a cell Colour
{
  TcxSSCellObject *CellObject = cxSheetBook->ActiveSheet->GetCellObject(aCol, aRow); // Get the Cell object
  TColor res;
  try {
    try {
      res = cxSheetBook->Palette[CellObject->Style->Brush->BackgroundColor]; // Return the colour
    }
    catch (Exception &err) {
      res = (TColor)0;                                         // JIC
    }
  }
  __finally {
    delete CellObject;                                         // Free the cell object
  }
  return res;
}

void __fastcall TFlyingMainForm::PlotPoint(const double aWt, const double aCofG,
                    const TColor aColour)                      // Plot a point with axis
{
  int y = Round(((aCofG * fCofgMultiplier) -
               fCofGAxisStarts) * fWtStep);                    // Get Y
  int x = fCofGAxis - Round((aWt - fCofGWeightMin) *
                   fCofgStep);                                 // Get X
                                                               // Draw on the canvas
    Pb->Canvas->Brush->Color = aColour;                        // Use the supplied colour
    Pb->Canvas->FillRect(Rect(y - 5, x - 5, y + 5, x + 5));    // Draw a 5 pixel square around the point
    Pb->Canvas->Pen->Color = aColour;                          // Set the pen colour
    Pb->Canvas->Pen->Width = 3;                                // 3 pixles wide
    Pb->Canvas->MoveTo(y, fCofGAxis - 1);                      // Set origin
    Pb->Canvas->LineTo(y, x - 1);                              // Draw to Axis
    Pb->Canvas->MoveTo(fCofGWeightAxis - 1, x);                // Move to axis
    Pb->Canvas->LineTo(y - 1, x);                              // Draw to X
}

void __fastcall TFlyingMainForm::PbPaint(TObject *Sender)
{
  double DepWt = GetCellDouble(1, 17);                          // Get the departure Weight
  double DepCg = GetCellDouble(2, 17);                          // Get the departure C of G
  double ArrWt = GetCellDouble(1, 19);                          // Get the arrival Weight
  double ArrCg = GetCellDouble(2, 19);                          // Get the arrival C of G
  PlotPoint(DepWt, DepCg, fDepCofGColour);                      // Plot departure
  PlotPoint(ArrWt, ArrCg, fArrCofGColour);                      // Plot arrival
}
//---------------------------------------------------------------------------

void __fastcall TFlyingMainForm::cxSheetBookActiveCellChanging(
      TcxSSBookSheet *Sender, const TPoint &ActiveCell, bool &CanSelect)
{
  CanSelect = false;
  if ((ActiveCell.x <= 3)&&(ActiveCell.y <= 20))
    CanSelect = true;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -