Example 1: |
The following short program lets you select a spectrum from the spectral collection and displays it as a diagram:
program ShowSpecOfCollection;
const
PAGE = 1; // chartbook page
var
i : integer;
astr : string;
Spcoll : TSpecCollection;
DlgResults : TVariantArray;
spix : integer;
fl, ll : integer;
spec : TDoubleArray;
begin
SpColl := TSpecCollection.Create(nil);
SpColl.Assign (SCData); // create a copy of the currently loaded collection
// to avoid any harm to the stored collection
if CreateDialog (100,20, // AlignAt, TopPos
'Please select a collection entry', // DialogCaption;
[gcDRopDown], // Components
['Spectra:']) = 0 then
begin
// prepare the dropdown box
astr := Decimal(Spcoll.Items[0].ItemId,6)+':'+Spcoll.Items[0].Caption;
for i:=2 to SpColl.NSpectra do
astr := astr + '|'+Decimal(Spcoll.Items[i-1].ItemId,6)+':'+Spcoll.Items[i-1].Caption;
couts (astr);
ConfigDlgComponent (1, 'opt='+astr+'; val=1; wid=300');
DlgResults := ShowDialog; // show the dialog
if DlgResults[0] = 0 then
begin
spix := DlgResults[1]-1; // index of selected spectrum
ChartBook.Reset;
ChartBook.Configure
(PAGE, // page 1
true, false, false, // only the chart is visible
250, 250); // default width & height
ChartBook.TabCaption[PAGE] := 'Spectrum';
with ChartBook.Charts[PAGE] do
begin
Reset;
Caption := 'Specral Collection Entry '+ Decimal(Spcoll.Items[spix].ItemId,6)+':'+Spcoll.Items[spix].Caption;
GridStyle := gsDotLines;
GridColor := clSilver;
ScalePropsY[1].ShortTicks := false;
Spcoll.ObtainGroupLayerLimits(1,fl,ll); // display the first spectral group only
MoveTo (SpColl.IndexToWL(fl),SpColl.Items[spix].Spectrum[fl-1]);
for i:=fl to ll do
DrawTo (SpColl.IndexToWL(i),SpColl.Items[spix].Spectrum[i-1]);
AutoRange (1,4);
if SpColl.ReversedScale[1] then // for IR spectra: reverse the x-axis
ChartBook.Charts[PAGE].FlipAxis (dimX);
Update;
end;
end;
end;
SpColl.Free;
end.
|