TSpecCollection

The class TSpecCollection supports the management of spectral collections. You can load and save spectral collections from/to the harddisk, or construct them from scratch. Please note that spectral collections are not intended to be a database replacement. Spectral collections are inherently slow due to the storage as tagged text files (see the spectral collection data format for details).

Properties

Methods

 

Please note that there is a predeclared instance of the class TSpecCollection, called SCData, which is globally available throughout a script and which allows you to access the spectra shown in the Spectral Collection Editor.

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.

Example 2: The following code snippet shows how to create a spectral collection from scratch and store it on the disk. It is assumed that the spectral collection is prepared for a dataset whose meta information is contained in the instance SrcMData.
Spc := TSpecCollection.Create(nil);
Spc.InitCalib (SrcMData);
//
// ... add spectra ...
//
Scp.Save (GetILabDir(idwork)+'mycollection.scll', false);
Spc.Free;


Last Update: 2018-Sep-13