1
0

Add chemCollection example program

This commit is contained in:
Timothy Warren 2021-10-21 16:13:43 -04:00
parent 32efe43002
commit d57f308802
5 changed files with 227 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="chemCollection"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="RunTimeTypeInfoControls"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="chemCollection.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="mainchemform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="ChemForm"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="mainChemForm"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="chemCollection"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,22 @@
program chemCollection;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, runtimetypeinfocontrols, mainChemForm
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TChemForm, ChemForm);
Application.Run;
end.

View File

@ -0,0 +1,23 @@
object ChemForm: TChemForm
Left = 604
Height = 240
Top = 270
Width = 320
Caption = 'ChemForm'
ClientHeight = 240
ClientWidth = 320
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '2.0.12.0'
object chemGrid: TTIGrid
Left = 162
Height = 100
Top = 110
Width = 200
Color = clWindow
Filter = [tkInteger, tkChar, tkEnumeration, tkFloat, tkSString, tkLString, tkAString, tkWString, tkVariant, tkWChar, tkBool, tkInt64, tkQWord]
ParentColor = False
TabOrder = 0
TIOptions = []
end
end

View File

@ -0,0 +1,99 @@
unit mainChemForm;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, RTTIGrids, grids;
type
TElementItem = class(TCollectionItem)
private
FNumber: cardinal;
FName: string;
FSymbol: string;
FGroup: string;
published
property AtomicNo: cardinal read FNumber write FNumber;
property Name: string read FName write FName;
property Symbol: string read FSymbol write FSymbol;
property Group: string read FGroup write FGroup;
end;
{ TChemForm }
TChemForm = class(TForm)
chemGrid: TTIGrid;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
Felements: TCollection;
procedure SetupChemGrid;
end;
var
ChemForm: TChemForm;
implementation
{$R *.lfm}
{ TChemForm }
procedure TChemForm.FormCreate(Sender: TObject);
begin
SetupChemGrid;
end;
procedure TChemForm.FormDestroy(Sender: TObject);
begin
// Free up the collection's memory!
Felements.Free;
end;
procedure TChemForm.SetupChemGrid;
procedure AddElement(aNumber: cardinal; const aName, aSymbol, aGroup: string);
var ei: TElementItem;
begin
ei := TElementItem(Felements.Add);
ei.AtomicNo := aNumber;
ei.Name := aName;
ei.Symbol := aSymbol;
ei.Group := aGroup;
end;
procedure AddElements;
begin
AddElement(1, 'Hydrogen', 'H', '"I"');
AddElement(2, 'Helium', 'He', '"II"');
AddElement(3, 'Lithium', 'Li', 'I');
AddElement(4, 'Beryllium', 'Be', 'II');
AddElement(5, 'Boron', 'B', 'III');
AddElement(6, 'Carbon', 'C', 'IV');
AddElement(7, 'Nitrogen', 'N', 'V');
AddElement(8, 'Oxygen', 'O', 'VI');
AddElement(9, 'Fluorine', 'F', 'VII');
AddElement(10, 'Neon', 'Ne', 'VIII');
end;
procedure InitalizeChemGrid;
begin
Self.Height := 310;
Self.Width := 340;
chemGrid.Align := alClient;
chemGrid.TIOptions := chemGrid.TIOptions + [tgoStartIndexAtOne];
chemGrid.Options := chemGrid.Options + [goDrawFocusSelected];
chemGrid.FixedColor := clMoneyGreen;
chemGrid.DefaultDrawing := True;
chemGrid.AutoFillColumns := True;
end;
begin
Felements := TCollection.Create(TElementItem);
AddElements;
InitalizeChemGrid;
chemGrid.ListObject := Felements;
end;
end.