Class: TBasicCard

 TComponent ----+
                |
           TBasicCard

Description:
This class interfaces to Zeitcontrol's BasicCard API. It provides many functions from the CRI and BCI DLLs.
If not documented otherwise the functions will return True if they succeeded and False if they failed. The properties Error, SW1SW2 and FileError will be set if appropiate.

Unit:
ZCDCI1 (ZCDCI1.pas)

Constructors:

constructor Create(AOwner: TComponent); override;

Properties:

property ApplicationID: String read GetApplicationID;
The ApplicationID of the BasicCard or an empty string if not available
property ATR: ZCCRIATR read fATR;
The ATR returned by the card
property CardHandle: ZCBCICARD read fCard;
The handle of the card. You may need this to call the API directly.
property DefaultReader: String read GetDefaultReader write SetDefaultReader;
The name of the default card reader. May be set to change it.
property Error: ZCCRIRET read fError;
Last error returned by an API call
property FileError: Byte read fFileError;
Last FileErr returned by the BasicCard
property IsConnected: Boolean read fConnected;
Is true when connected to a Card
property IsOpen: Boolean read fIsOpen;
Is true when a reader is open
property OnCardInserted: TNotifyEvent read fOnCardInserted write fOnCardInserted;
This event is called when a card is inserted into the currently open reader
property OnCardRemoved: TNotifyEvent read fOnCardRemoved write fOnCardRemoved;
This event is called when the card is removed from the open reader
property OnReaderBusy: TNotifyEvent read fOnReaderBusy write fOnReaderBusy;
This event is called when the reader becomes busy, i.e. is used by another application
property ReaderCount: Integer read GetReaderCount;
The number of readers known to the API
property ReaderHandle: ZCCRIREADER read fReader;
The handle of the open reader. You may need this to call the API directly.
property Readers[Num: Integer]: String read GetReaderName;
An array containing the names of the known readers
property SW1SW2: Word read fSW1SW2;
Last SW1SW2 return value from the card

Methods:

function CardInReader: Boolean;
Returns true when there is a card in the (open) reader
function ChDir(Path: String): Boolean;
Changes current directory on card
function CloseAllFiles: Boolean;
Closes all open files
function CloseFile(FileNum: Byte): Boolean;
Closes a file
function CloseReader: Boolean;
Detaches and closes the reader
function Connect: Boolean; virtual;
Connects to the card
function CurDir(var Path: String): Boolean;
Returns current directory on card
destructor Destroy; override;
function DirCount(FileSpec: String; var Count: Word): Boolean;
Counts files and directories matching specification
function DirFile(FileSpec: String; Num: Word; var FileName: String): Boolean;
Returns file or directory name of a specific file
function Disconnect: Boolean; virtual;
Disconnects from the card
function Echo(var Chars: String; Incr: Byte): Boolean;
Executes the built-in Echo function
function EndEncryption: Boolean;
Terminates encrypted communication
function EraseFile(Path: String): Boolean;
Erases a card file
function FileGet(FileNum: Byte; var Data; Count: Byte): Boolean;
Reads from a binary file
function FileLength(FileNum: Byte; var Length: DWORD): Boolean;
Returns the file length
function FilePut(FileNum: Byte; const Data; Count: Byte): Boolean;
Writes to a binary file
function FileRead(FileNum: Byte; var Data; Count: Byte): Boolean;
Reads from a non-binary file
function FileWrite(FileNum: Byte; const Data; Count: Byte): Boolean;
Writes to a non-binary file
function GetAttr(Path: String; var Attrib: Word): Boolean;
Gets file or directory attributes
function GetFilePos(FileNum: Byte; var FilePos: DWORD): Boolean;
Returns the current file position
function GetLockInfo(Path: String; var LockInfo: ZCBCILOCKINFO): Boolean;
Gets lock information of file or directory
function MkDir(Path: String): Boolean;
Creates a new directory on card
function OpenFile(Path: String; Mode: Byte; RecordLen: Word; var FileNum: WORD): Boolean;
Opens a file on the BasicCard
function OpenReader(Reader: String): Boolean;
Opens a reader and attaches to it to the BCI.
function QueryEOF(FileNum: Byte; var EOF: Boolean): Boolean;
Checks if end of file has been reached
function Reconnect: Boolean; virtual;
Reconnects to the card, i.e. resets it
function Rename(OldPath, NewPath: String): Boolean;
Renames or moves a file or directory
function RmDir(Path: String): Boolean;
Removes a directory from card
function SelectReaderDialog: Boolean;
Opens a dialog where the user can select a reader and sets new reader if appropiate
function SetFileLock(Path: String; LockType: Byte; Lock: Boolean; KeyCount, Key1, Key2: Byte): Boolean;
Sets lock information of file or directory
function SetFilePos(FileNum: Byte; FilePos: DWORD): Boolean;
Sets the current file position
function SetKey(KeyNum: Byte; Key: String): Boolean;
Sets an encryption key
function SetPoly(PolyA, PolyB: DWORD): Boolean;
Sets the encryption polynoms
function StartEncryption(Algo, Key: Byte): Boolean;
Starts encrypted communication with card
function Transaction(CLA, INS: Byte; PData: PZCBCIPARM; DataCount: Byte): Boolean;
Calls a card command
function Transaction2(CLA, INS, P1, P2, Lc, Le: Byte; PData: PZCBCIPARM; DataCount: Byte): Boolean;
Calls a card command

constructor Create(AOwner: TComponent); override;


property ApplicationID: String read GetApplicationID;

The ApplicationID of the BasicCard or an empty string if not available


property ATR: ZCCRIATR read fATR;

The ATR returned by the card


property CardHandle: ZCBCICARD read fCard;

The handle of the card. You may need this to call the API directly.


property DefaultReader: String read GetDefaultReader write SetDefaultReader;

The name of the default card reader. May be set to change it.


property Error: ZCCRIRET read fError;

Last error returned by an API call


property FileError: Byte read fFileError;

Last FileErr returned by the BasicCard


property IsConnected: Boolean read fConnected;

Is true when connected to a Card


property IsOpen: Boolean read fIsOpen;

Is true when a reader is open


property OnCardInserted: TNotifyEvent read fOnCardInserted write fOnCardInserted;

This event is called when a card is inserted into the currently open reader


property OnCardRemoved: TNotifyEvent read fOnCardRemoved write fOnCardRemoved;

This event is called when the card is removed from the open reader


property OnReaderBusy: TNotifyEvent read fOnReaderBusy write fOnReaderBusy;

This event is called when the reader becomes busy, i.e. is used by another application


property ReaderCount: Integer read GetReaderCount;

The number of readers known to the API


property ReaderHandle: ZCCRIREADER read fReader;

The handle of the open reader. You may need this to call the API directly.


property Readers[Num: Integer]: String read GetReaderName;

An array containing the names of the known readers


property SW1SW2: Word read fSW1SW2;

Last SW1SW2 return value from the card


function CardInReader: Boolean;

Returns true when there is a card in the (open) reader


function ChDir(Path: String): Boolean;

Changes current directory on card
Parameters
   Path : New directory


function CloseAllFiles: Boolean;

Closes all open files


function CloseFile(FileNum: Byte): Boolean;

Closes a file


function CloseReader: Boolean;

Detaches and closes the reader


function Connect: Boolean; virtual;

Connects to the card


function CurDir(var Path: String): Boolean;

Returns current directory on card
Parameters
   Path : Will contain current directory


destructor Destroy; override;


function DirCount(FileSpec: String; var Count: Word): Boolean;

Counts files and directories matching specification
Parameters
   FileSpec : File specification
   Count : Will contain number of files and directories


function DirFile(FileSpec: String; Num: Word; var FileName: String): Boolean;

Returns file or directory name of a specific file
Parameters
   FileSpec : File specification
   Num : Number of file (starting with 1)
   FileName : Returns with name of matched file
See Also
    DirCount to get number of files


function Disconnect: Boolean; virtual;

Disconnects from the card


function Echo(var Chars: String; Incr: Byte): Boolean;

Executes the built-in Echo function
Parameters
   Chars : The String to pass to the function and the result
   Incr : Increment all chars by this value


function EndEncryption: Boolean;

Terminates encrypted communication


function EraseFile(Path: String): Boolean;

Erases a card file
Parameters
   Path : File name


function FileGet(FileNum: Byte; var Data; Count: Byte): Boolean;

Reads from a binary file
Parameters
   Data : A buffer for the data
   Count : Number of bytes to read


function FileLength(FileNum: Byte; var Length: DWORD): Boolean;

Returns the file length
Parameters
   Length : Will contain the file length


function FilePut(FileNum: Byte; const Data; Count: Byte): Boolean;

Writes to a binary file
Parameters
   Data : A buffer for the data
   Count : Number of bytes to write


function FileRead(FileNum: Byte; var Data; Count: Byte): Boolean;

Reads from a non-binary file
Parameters
   Data : A buffer for the data
   Count : Number of bytes to read


function FileWrite(FileNum: Byte; const Data; Count: Byte): Boolean;

Writes to a non-binary file
Parameters
   Data : A buffer for the data
   Count : Number of bytes to write


function GetAttr(Path: String; var Attrib: Word): Boolean;

Gets file or directory attributes
Parameters
   Path : File name
   Attrib : If successful will return attribute


function GetFilePos(FileNum: Byte; var FilePos: DWORD): Boolean;

Returns the current file position
Parameters
   FilePos : Returns current position (starting with 1)


function GetLockInfo(Path: String; var LockInfo: ZCBCILOCKINFO): Boolean;

Gets lock information of file or directory
Parameters
   Path : File name
   LockInfo : ZCBCILOCKINFO structure that will contain lock information
See Also
    API documentation for ZCBCILOCKINFO structure


function MkDir(Path: String): Boolean;

Creates a new directory on card
Parameters
   Path : New directory


function OpenFile(Path: String; Mode: Byte; RecordLen: Word; var FileNum: WORD): Boolean;

Opens a file on the BasicCard
Parameters
   Path : The file name (without @:)
   Mode : File mode
   RecordLen : Record/block size
   FileNum : Will contains the file number when returning successfully
See Also
    API documentation for valid file modes


function OpenReader(Reader: String): Boolean;

Opens a reader and attaches to it to the BCI.
Parameters
   Reader : The name of the reader or an empty string to open the default reader


function QueryEOF(FileNum: Byte; var EOF: Boolean): Boolean;

Checks if end of file has been reached
Parameters
   EOF : Will contain true if EOF reached when returning successfully


function Reconnect: Boolean; virtual;

Reconnects to the card, i.e. resets it


function Rename(OldPath, NewPath: String): Boolean;

Renames or moves a file or directory
Parameters
   OldPath : Current filename
   NewPath : New filename


function RmDir(Path: String): Boolean;

Removes a directory from card
Parameters
   Path : Directory to remove


function SelectReaderDialog: Boolean;

Opens a dialog where the user can select a reader and sets new reader if appropiate


function SetFileLock(Path: String; LockType: Byte; Lock: Boolean; KeyCount, Key1, Key2: Byte): Boolean;

Sets lock information of file or directory
Parameters
   Path : File name
   LockType : Lock type (ZCBCI_LOCK_...)
   Lock : True to lock file, False to unlock it
   KeyCount : Number of access keys (0..2)
   Key1 : Number of first key (if appropiate)
   Key2 : Number of second key (if appropiate)
See Also
    API documentation


function SetFilePos(FileNum: Byte; FilePos: DWORD): Boolean;

Sets the current file position
Parameters
   FilePos : New position (starting with 1)


function SetKey(KeyNum: Byte; Key: String): Boolean;

Sets an encryption key
Parameters
   KeyNum : Key number
   Key : The key itself (8 or 16 bytes long)


function SetPoly(PolyA, PolyB: DWORD): Boolean;

Sets the encryption polynoms
Parameters
   PolyA : First polynom
   PolyB : Second polynom


function StartEncryption(Algo, Key: Byte): Boolean;

Starts encrypted communication with card
Parameters
   Algo : The algorithm or 0 for auto-selection
   Key : The key number


function Transaction(CLA, INS: Byte; PData: PZCBCIPARM; DataCount: Byte): Boolean;

Calls a card command
Parameters
   CLA : Command class byte
   INS : Command instruction byte
   PData : A pointer to an array of ZBCIPARM
   DataCount : Numer of parameters to pass
See Also
    API documentation for structure of ZBCIPARM


function Transaction2(CLA, INS, P1, P2, Lc, Le: Byte; PData: PZCBCIPARM; DataCount: Byte): Boolean;

Calls a card command
Parameters
   CLA : Command class byte
   INS : Command instruction byte
   P1 : P1 byte
   P2 : P2 byte
   Lc : Lc or ZBCI_DEFAULT_LC
   Le : Le, ZCBCI_DISABLE_LE or ZCBCI_DEFAULT_LE
   PData : A pointer to an array of ZBCIPARM
   DataCount : Numer of parameters to pass
See Also
    API documentation for structure of ZBCIPARM