Loading a Data Set (Delphi)

Take the following steps to start a project and to add some code that loads a DICOM Data Set and prints information about the data set:

1.

Start Delphi.

2.

From the File menu, choose New Application

3.

On the Delphi toolbar, click the LEADTOOLS tab. Select the LEAD DICOM control and add the control to your main form.

4.

Add a command button to your form and name it as follows:

 

Name

Caption

 

LoadLead

Load Image

5.

Add the following initialization code to the main form's Create procedure. In online help, you can use the copy the block of code and paste it in your form.

procedure TForm1.FormCreate(Sender: TObject);
begin
   {Unlock DICOM support.}
   {Note that this is a sample key, which will not work in your toolkit.}
   LEADDicom1.UnlockSupport(L_SUPPORT_MEDICAL, 'TestKey');
end;

6.

At the beginning of the Unit1 file, add LTVCLUNT to the uses section. In order to use the constants in Delphi, you must add the LTVCLDEF unit to the uses section. For example:

 

uses

 

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, LEADVCL, StdCtrls, TwainVcl, LTVCLDEF

7.

Code the LoadLead button's click procedure as follows:

procedure TForm1.LeadLoadClick(Sender: TObject);
var
   nRet: Integer;
   uCount: Cardinal;
   bResult: Boolean;
begin
   LEADDicom1.EnableMethodErrors := false;
   nRet := LEADDicom1.LoadDS('c:\LEAD\Images\test2.dic', 0);
   If nRet <> SUCCESS Then
   begin
      ShowMessage('Error ' + IntToStr(nRet) + ' loading file!');
      Exit;
   end;
   uCount := LEADDicom1.GetModuleCount();
   LEADDicom1.FindIndexModule(0);
   bResult := LEADDicom1.SetCurrentElement(LEADDicom1.CurrentModule.Element[0].hElement);
   If bResult Then
      ShowMessage('There are ' + IntToStr(uCount) + ' modules in this data set.' + #13+
         'The first module has ' + IntToStr(LEADDicom1.CurrentModule.ElementCount) +
         ' elements.' + #13 + 'The first element has: ' + #13 + 'Tag number:' +
         IntToHex(LEADDicom1.CurrentElement.Tag, 0) + #13 + 'VR: ' +
         IntToHex(LEADDicom1.CurrentElement.VR, 0));
   LEADDicom1.EnableMethodErrors := true;
end;

8.

Run your program to test it.

9.

Save the project to use as a starting point for other tasks in this tutorial.