📄 flyingmain.pas
字号:
unit FlyingMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, cxSSheet, cxControls, ExtCtrls, StdCtrls,
ComCtrls, Jpeg, Menus, cxssPainters;
type
TFlyingMainForm = class(TForm)
cxSpread: TcxSpreadSheetBook;
Image1: TImage;
StatusBar1: TStatusBar;
Pb: TPaintBox;
Image2: TImage;
ssPm: TPopupMenu;
pmoFormat: TMenuItem;
MainMenu1: TMainMenu;
File1: TMenuItem;
mmAircraft: TMenuItem;
mmExit: TMenuItem;
mmOptions: TMenuItem;
moToday: TMenuItem;
moFuelTabs: TMenuItem;
Bevel1: TBevel;
pmWizard: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure cxSpread1SetSelection(Sender: TObject;
ASheet: TcxSSBookSheet);
procedure PbPaint(Sender: TObject);
procedure cxSpread1SheetPopupMenu(Sender: TObject; X, Y: integer);
procedure pmoFormatClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure mmExitClick(Sender: TObject);
procedure moTodayClick(Sender: TObject);
procedure moFuelTabsClick(Sender: TObject);
procedure pmWizardClick(Sender: TObject);
procedure cxSpreadTopLeftChanging(Sender: TcxSSBookSheet;
var ATopLeft: TPoint);
procedure cxSpreadAfterCalculation(Sender: TObject);
procedure cxSpreadActiveCellChanging(Sender: TcxSSBookSheet;
const ActiveCell: TPoint; var CanSelect: Boolean);
private
fMenuItems: array of TMenuItem;
fDepCofGColour: TColor;
fArrCofGColour: TColor;
fPlaneReg: string;
fPlaneCofgBitmap: string;
fPlanePhoto: string;
fWeightUnits: string;
fMaxPersons: integer;
fMaxTakeOffWt: double;
fMaxLandingWt: double;
fMaxBaggageWt: double;
fMaxBaggageWt2: double;
fMaxFuelCapacity: double;
fTabsFuel: double;
fMinAftCofG: double;
fMaxAftCofG: double;
fCofGAxisStarts: double;
fCofgStep: double;
fWtStep: double;
fCofgMultiplier: double;
fCofGAxis: integer;
fCofGWeightMin: double;
fCofGWeightAxis: integer;
fEnvelopeSize: integer;
fNormalCellColour: integer;
fErrorCellColour: Integer;
fCofGEnvelope: array of TPoint;
procedure moSelectPlaneClick(Sender: TObject);
function GetCellDouble(const aCol, aRow: integer): double;
function GetCellString(const aCol, aRow: integer): string;
function GetCellInt(const aCol, aRow: integer): integer;
function GetCellColour(const aCol, aRow: integer): integer;
procedure SetCellMessage(const aCol, aRow: integer;
const aMessage: string; const aBackgroundColour,
aFontColour: Word);
function GetCellTColour(const aCol, aRow: integer): TColor;
procedure CheckFigures;
procedure LoadImage(const aResJpg: string; AnImage: TImage);
procedure LoadPlaneVars;
procedure SetupPlane;
public
procedure UpdateCofG;
{ Public declarations }
end;
type
THelpIds = array[0..20, 0..3] of integer;
// An array that provides a HelpId for each cell on the
// input sheet. Here these are mapped to a static string
// array, it would be simple to map these to ID's in a
// help file
const // A B C D
HelpIds: THelpIds = ((0, 0, 1, 0), // 1
(0, 0, 0, 0), // 2
(0, 0, 0, 0), // 3
(0, 0, 2, 0), // 4
(0, 0, 0, 0), // 5
(0, 0, 0, 0), // 6
(0, 0, 0, 0), // 7
(0, 0, 0, 0), // 8
(0, 0, 0, 3), // 9
(0, 0, 0, 4), // 10
(0, 0, 0, 0), // 11
(0, 0, 0, 0), // 12
(0, 0, 0, 0), // 13
(0, 0, 0, 0), // 14
(0, 5, 0, 0), // 15
(0, 5, 0, 0), // 16
(0, 6, 0, 0), // 17
(0, 0, 7, 0), // 18
(0, 0, 0, 0), // 19
(0, 0, 8, 0), // 20
(0, 0, 0, 0)); // 21
// Test strings for Cell Help
const
HelpText: array[1..9] of string = ('The date the flight is being made',
'Flight duration in Hrs (ie 210 Nm @ 95 Knts Enter = 210 / 95 or 2.21)',
'The minimum required fuel for the flight',
'The actual fuel onboard the aircraft on departure',
'Wt of seat occupants (Right click for a Wizard)',
'Total weight of those items in the baggage compartment 1',
'The C of G on Take-off',
'The C of G on Landing',
'Total weight of those items in the baggage compartment 2'
);
var
FlyingMainForm: TFlyingMainForm;
implementation
{$R *.dfm}
//{$R DEFAULT.RES}
uses
FlyingSeatCalc;
procedure TFlyingMainForm.FormCreate(Sender: TObject);
var
Rs : TResourceStream; // Resource Stream
I, Mi : integer; // Local Int Vars
begin
Rs := TResourceStream.Create(hInstance,
'DEFAULTSHEET',
RT_RCDATA); // Load the Spreadsheet into a resource stream
try
cxSpread.LoadFromStream(Rs); // Load the sheet from the resource stream
cxSpread.ShowHeaders := False; // No Headers
cxSpread.ShowGrid := False; // No Grid
finally
Rs.Free; // Free the Resource stream
end;
Mi := cxSpread.PageCount; // Get the number of pages in the book
SetLength(fMenuItems, Mi); // Set the dynamic array up
for I := 0 to Mi - 1 do // For each Page
begin
fMenuItems[I] := TMenuItem.Create(nil); // Create the menu item
with fMenuItems[I] do // With the new item
begin
Caption := cxSpread.Pages[I].Caption;; // Set the caption
Tag := I; // Set the tag
OnClick := moSelectPlaneClick; // Set the event
end;
mmAircraft.Add(fMenuItems[I]); // Now add the menu item to the aircraft menu
end;
fDepCofGColour := clRed; // Set default departure C of G Colour
fArrCofGColour := clYellow; // Set default arrival C of G Colour
fNormalCellColour := GetCellColour(0, 0); // Get the normal cell colour
fErrorCellColour := GetCellColour(2, 17); // Get the error cell colour
SetupPlane; // Read the variables for this plane
end;
procedure TFlyingMainForm.FormShow(Sender: TObject); // For is being shown
begin
moTodayClick(Sender); // Set today's date
cxSpread.ActiveCell := Point(2, 3); // Set the active cell
cxSpread1SetSelection(Sender, cxSpread.ActiveSheet); // Trigger the display of cell hints
end;
// Helpers
procedure TFlyingMainForm.LoadImage(const aResJpg: string;
AnImage: TImage); // Load an JPG image from a resource
var
Rs: TResourceStream; // Resource Stream
Jpi: TJpegImage; // Jpeg Image
begin
Jpi := TJpegImage.Create; // Create the Jpeg
Rs := TResourceStream.Create(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
Jpi.Free; // Free the Jpeg
Rs.Free; // Free the resource stream
end;
end;
procedure TFlyingMainForm.SetCellMessage(const aCol, aRow: integer; // Display a message in cell at row, col
const aMessage: string; // The message
const aBackgroundColour: Word; // The background color
const aFontColour: Word); // The font color
begin
with cxSpread.ActiveSheet.GetCellObject(aCol, aRow) do // Get the cell object
try
try
Style.Brush.BackgroundColor := aBackgroundColour; // Set the background colour
Style.Font.FontColor := aFontColour; // set the font colour
Text := aMessage; // Set the text
except
end;
finally
Free; // Free the Cell object
end;
end;
function TFlyingMainForm.GetCellTColour(const aCol,
aRow: integer): TColor; // Get a cell Colour
begin
with cxSpread.ActiveSheet.GetCellObject(aCol, aRow) do // Get the Cell object
try
try
Result := cxSpread.Palette[Style.Brush.BackgroundColor]; // Return the colour
except
Result := 0; // JIC
end;
finally
Free; // Free the cell object
end;
end;
function TFlyingMainForm.GetCellColour(const aCol,
aRow: integer): integer; // Get the Cell colour as a plaette entry
begin
with cxSpread.ActiveSheet.GetCellObject(aCol, aRow) do // Get the cell object
try
try
Result := Style.Brush.BackgroundColor; // Return the entry
except
Result := 0; // JIC
end;
finally
Free; // Free the cell object
end;
end;
function TFlyingMainForm.GetCellString(const aCol,
aRow: integer): string; // Get a string from a cell
begin
with cxSpread.ActiveSheet.GetCellObject(aCol, aRow) do // Get the Cell Object
try
try
Result := DisplayText; // Get the Text
except
Result := ''; // JIC
end;
finally
Free; // Free the cell object
end;
end;
function TFlyingMainForm.GetCellInt(const aCol,
aRow: integer): integer; // Get the value of a cell as an integer
begin
with cxSpread.ActiveSheet.GetCellObject(aCol, aRow) do // Get the cell object
try
try
Result := CellValue; // Get the Display text (not the formula) and convert
except
Result := 0; // JIC
end;
finally
Free; // Free the cell object
end;
end;
function TFlyingMainForm.GetCellDouble(const aCol,
aRow: integer): double; // Get the value of a cell as a double
begin
with cxSpread.ActiveSheet.GetCellObject(aCol, aRow) do // Get the cell object
try
try
Result := CellValue; // Get the display text (not the formula) and convert
except
Result := 0.0; // JIC
end;
finally
Free; // Free the cell object
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -