Thanks Josh .... blatantly obvious (once you pointed it out!)
I've written my own Delphi component for accepting DataCAD Numbers (Distances, Decimal Angles, DegMinSec Angles etc.). I've chosed to use the Delphi DecimalSeparator field (which I believe is locale specific) rather than specify both period and comma as acceptable keystrokes.
Not sure if anybody other than me or Joe are developing anything using D4D, but if anybody is interested in using it, the source code for my component is below:
Code: Select allunit DcadNumericEdit;
interface
uses
System.SysUtils, System.Classes, Vcl.Controls, Vcl.StdCtrls, UInterfaces;
type
NumType = (Distance, DecDegrees, DegMinSec, IntegerNum, DecimalNum);
TDcadNumericEdit = class(TCustomEdit)
private
function isValid : boolean;
var datatype : NumType;
var number : double;
var allowNeg : boolean;
procedure setNumber (num : double); overload;
procedure setNumber (num : integer); overload;
function getNumber : double;
protected
procedure KeyPress(var Key: Char); override;
public
property valid : boolean
read isvalid;
property NumValue : double
read getnumber write setNumber;
published
property NumberType : NumType
read dataType write dataType default Distance;
property AllowNegative : boolean
read allowNeg write allowNeg default true;
{ publish properties }
property Align;
property Alignment;
property AlignWithMargins;
property Anchors;
property AutoSelect;
property AutoSize;
property BevelEdges;
property BevelInner;
property BevelKind;
property BevelOuter;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property Color;
property Constraints;
property Ctl3D;
property Cursor;
property CustomHint;
property Enabled;
property Font;
property Height;
property Hint;
property Left;
property Margins;
property MaxLength;
property Name;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ReadOnly;
property ShowHint;
property StyleElements;
property TabOrder;
property TabStop;
property Text;
property Top;
property Visible;
property Width;
property OnChange;
{ publish events }
property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DataCAD', [TDcadNumericEdit]);
end;
function TDcadNumericEdit.isValid : boolean;
var
i : integer;
begin
case datatype of
Distance : result := toDis (shortstring(text), number);
DegMinSec : result := Str2Ang (shortstring(text), true, number);
DecDegrees : begin
result := cvstrll(shortstring(text), number);
number := number*Pi/180;
end;
IntegerNum : begin
result := cvstint (shortstring(text), i);
number := i;
end
else result := cvstrll(shortstring(text), number);
end;
end;
procedure TDcadNumericEdit.setNumber(num: Double);
var
ss : shortstring;
begin
number := num;
if not allowNeg then number := abs(number);
case datatype of
Distance : tostr (number, ss, false);
DegMinSec : Ang2Str (number, ss, true, false);
DecDegrees : cvrllst (number*180/Pi, ss);
IntegerNum : cvintst (round(num), ss);
else cvrllst (number, ss);
end;
text := string (ss);
end;
procedure TDcadNumericEdit.setNumber(num: integer);
var
ss : shortstring;
begin
number := num;
if not allowNeg then number := abs(number);
case datatype of
Distance : tostr (number, ss, false);
DegMinSec : Ang2Str (number, ss, true, false);
DecDegrees : cvrllst (number*180/Pi, ss);
else cvintst (round(number), ss);
end;
text := string (ss);
end;
function TDcadNumericEdit.getNumber : Double;
begin
if isValid then begin
if datatype = IntegerNum then
result := double(round(number))
else
result := number;
if not allowNeg then
result := abs(result);
end
else
result := 0.0;
end;
procedure TDcadNumericEdit.KeyPress(var Key: Char);
begin
if not (key in ['0'..'9', '-', FormatSettings.DecimalSeparator , '/', #8, #13, #127]) then
key := #0;
if not allowNeg then
if key = '-' then key := #0;
if ((PGSaveVar^.scaletype <> 1) and (PGSaveVar^.scaletype <> 4))
or (datatype <> Distance) then begin
if key = '/' then key := #0;
end;
if (datatype = IntegerNum) and (key = FormatSettings.DecimalSeparator) then
key := #0;
if key = #0 then beep;
inherited KeyPress(Key)
end;
end.
If using the above you should check .valid property as well as .NumValue (as .NumValue will return zero if the text in the component is not a valid value for the type specified).