{************************************************************************
 ***                          SEX                                     ***
 ************************************************************************}
{sorry, nothing exciting: provides an object for inputting & storing sex, ie M/F.
Stored as char type, which is either M or F.
Maybe in future can pass options for other possibilities, eg castrates}
{$I compflgs}

unit sex;

interface

uses tuiedit, objects, drivers;
{and now for the sex object...}  {sorry, couldn't resist that}

type
	TSex = (Male,Female);

	PInputSex = ^TInputSex;
	TInputSex = object(TInputELine)
		constructor Init(Bounds : TRect);
		procedure HandleEvent(var Event : TEvent); virtual;
		procedure Draw; virtual;
		procedure GetData(var Rec); virtual;
		procedure SetData(var Rec); virtual;
		function DataSize : word; virtual;
	end;


implementation

uses tuimsgs;

	constructor TInputSex.Init;
	begin
		inherited Init(Bounds, 1);
	end;

	procedure TInputSex.HandleEvent;
	begin

		if (Event.What = evKeyboard) then begin

			case Event.CHarCode of
				'm','M' : Event.CharCode := 'M';
				'f','F' : Event.CharCode := 'F';
			else
				if Event.CharCode>#32 then begin
					WrongKeyBleep;
					ClearEvent(Event);
				end;
			end;
		end;

		inherited HandleEvent(Event);
	end;

	{Make it look like a check box}
	procedure TInputSex.Draw;
	begin
		inherited Draw;                  {Sets cursor pos & data}
{		writeChar(0,0, '',4,1);         {First bracket}
{		writeChar(2,0, ']',4,1);         {Second}
	end;
{}
	procedure TInputSex.GetData(var Rec);
	begin
		char(Rec) := Data^[1];
	end;

	procedure TInputSex.SetData(var Rec);
	begin
		Data^ := char(Rec);
	end;

	function TInputSex.DataSize : word;
	begin DataSize := Sizeof(char); end;

end.
