Examples Delphi

unit SNoUnit;
{Richard Ebbs Feb 1999...}
{Wee prog to retrieve the serial number from a disc in a drive. Here we look
for the CD serial number only but the code will work in principle for a disc
in any drive...}
{THIS DOESN'T HAPPEN. NO WORKY. ACCESS VIOLATION EXCEPTION
RAISED THE CAUSE OF WHICH IS NOT OBVIOUS...}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TSerPacket = record
Info: Word; {info level: always zero...}
SerNo: LongInt; {disk serial number...}
Vol: Array[1..11] of char;
FileType: Array[1..8] of char;
end;
type
TMainForm = class(TForm)
GoButton: TButton;
ExitButton: TButton;
procedure ExitButtonClick(Sender: TObject);
procedure GoButtonClick(Sender: TObject);
private
{private declarations}
public
{public declarations}
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
var
SPacket: TSerPacket;

procedure TMainForm.ExitButtonClick(Sender: TObject);
begin
Close;
end;
function GetSerialInfo(Drive: Byte): Byte; assembler;
asm
mov ah, 69h
{this is where you 1 set serial, 0 to get serial number...}
mov al, 0
{drive number 0 = default, 1 = A, 2 = B , 3 = C, 4=D...}
mov bl, 1
mov dx, offset [SPacket]
int 21h
end;
function SetSerialInfo(Drive: Byte; SerNo: LongInt): Boolean;
begin
GetSerialInfo(Drive);
SPacket.SerNo := SerNo;
asm
mov ah, 69h
{this is where you use 1 to set, or 0 to get, the serial number...}
mov al, 1
{drive number 0 = default, 1 = A, 2 = B , 3 = C, 4=D...}
mov bl, Drive
mov dx, offset [SPacket]
int 21h
end;
end;
procedure DisplaySerialInfo;
var
S, infoStr, SNoStr, volStr, typeStr, msgStr: String;
begin
infoStr := 'Info level: ' + String(Char(SPacket.Info)) + #0;
{WriteLn('Info level: ', SPacket.Info);}
SNoStr := 'Serial Num: ' + IntToStr(SPacket.SerNo) + #0;
{WriteLn('Serial Num: ', SPacket.SerNo);}
{FillChar(S, SizeOf(S), #0);}
S := String(SPacket.Vol) + #0;
{line above is better than 2 lines below which it replaces...}
{Move(SPacket.Vol[1], S[1], 11);}
{S[Length(S)] := #0;}
volStr := 'Vol: ' + S + #0;
{WriteLn('Vol: ', S);}
FillChar(S, SizeOf(S), #0);
S := String(SPacket.FileType) + #0;
{line above is better than 2 lines below which it replaces...}
{Move(Spacket.FileType,S[1], 8);
S[Length(S)] := #0;}
typeStr := 'Type: ' + S + #0;
{WriteLn('Type: ', S);}
msgStr := infoStr + SNoStr + volStr + typeStr;
Application.MessageBox(PChar(msgStr), ' CD Serial Number', mb_OK);
end;
procedure TMainForm.GoButtonClick(Sender: TObject);
begin
{SHOULD TEST THAT THERE'S A DISC IN THE DRIVE, FIRST, HERE...}
{'1' is for drive A, '2' is for drive B, '3'
is for drive C, and '4' is for drive D...}
{SetSerialInfo(1, 12);}
GetSerialInfo(1);
DisplaySerialInfo;
end;
end.