unit uEditor;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Grids, StdCtrls, Forms, Controls, Comctrls,
Dialogs;
// http://www.drbob42.com/delphi/componen.htm
Type
TmyEditor = Class(TObject) //*TControl // TControl is the base class for all graphical objects - defined in controls
private
TabSheet: TTabSheet;
sgeditor : TStringGrid;
Edit1: TEdit;
StaticText1: TStaticText;
procedure sgGetCellHint(Sender: TObject; ACol, ARow: Integer;
var HintText: String);
procedure sgValidateEntry(sender: TObject; aCol, aRow: Integer;
const OldValue: string; var NewValue: String);
procedure sgKeyPress(Sender: TObject; var Key: char);
public
Constructor Create(anOwnerPgCtrl : TPageControl); //*sender : TObject
Procedure ShowEditor;
Procedure HideEditor;
end;
implementation
Procedure TmyEditor.ShowEditor;
begin
sgeditor.Show;
edit1.Show;
statictext1.Show;
end;
Procedure TmyEditor.HideEditor;
begin
sgeditor.Hide;
edit1.Hide;
statictext1.Hide;
end;
{Self = TMyEditor, Sender = }
Constructor TmyEditor.Create(anOwnerPgCtrl : TPageControl);
begin
TabSheet := TTabSheet.Create(anOwnerPgCtrl); //PageControl1
TabSheet.PageControl := anOwnerPgCtrl;
anOwnerPgCtrl.SelectNextPage(True,False);
TabSheet.Caption := 'Tab Sheet ' + TabSheet.TabIndex.ToString;
{------------EDIT BOX------------}
edit1 := TEdit.Create(anOwnerPgCtrl.ActivePage);
edit1.Anchors := [akTop, akLeft, akRight];
edit1.AnchorSideLeft.Control := anOwnerPgCtrl.ActivePage;
edit1.AnchorSideTop.Control := anOwnerPgCtrl.ActivePage;
edit1.AnchorSideRight.Control := anOwnerPgCtrl.ActivePage;
edit1.AnchorSideRight.Side := asrRight;
//edit1.AnchorSideBottom.Side := asrBottom;
edit1.BorderSpacing.Left := 25;
edit1.BorderSpacing.Top := 10;
edit1.BorderSpacing.Right := 25;
edit1.BorderSpacing.Bottom := 10;
edit1.Parent := anOwnerPgCtrl.ActivePage;
{------------STATIC TEXT------------}
statictext1 := TStaticText.Create(anOwnerPgCtrl.ActivePage); //*(self)
statictext1.Anchors := [akLeft, akRight, akBottom];
statictext1.Visible:=True;
statictext1.AnchorSideLeft.Control := anOwnerPgCtrl.ActivePage;
statictext1.AnchorSideRight.Control := anOwnerPgCtrl.ActivePage;
statictext1.AnchorSideBottom.Control := anOwnerPgCtrl.ActivePage;
//statictext1.AnchorSideTop.Side := asrCenter;
statictext1.AnchorSideRight.Side := asrBottom;
statictext1.AnchorSideBottom.Side := asrBottom;
statictext1.Height:=35;
statictext1.BorderSpacing.Bottom := 5;
statictext1.BorderSpacing.Around := 10;
statictext1.Parent := anOwnerPgCtrl.ActivePage;
{------------STRING GRID------------}
sgEditor := TStringGrid.Create(anOwnerPgCtrl.ActivePage); //*(self)
sgeditor.Options:=sgeditor.options+[goEditing, goAlwaysShowEditor, goCellHints];
sgeditor.ColCount:=10;
sgeditor.RowCount:=10;
sgeditor.Anchors := [akTop, akLeft, akRight, akBottom];
sgeditor.AnchorSideLeft.Control := anOwnerPgCtrl.ActivePage;
sgeditor.AnchorSideRight.Control := anOwnerPgCtrl.ActivePage;
sgeditor.AnchorSideTop.Control := Edit1;
sgeditor.AnchorSideBottom.Control := StaticText1;
sgeditor.AnchorSideTop.Side := asrBottom;
sgeditor.AnchorSideRight.Side := asrBottom;
sgeditor.AnchorSideBottom.Side := asrTop;
sgeditor.BorderSpacing.Left := 25;
sgeditor.BorderSpacing.Top := 10;
sgeditor.BorderSpacing.Right := 25;
sgeditor.BorderSpacing.Bottom := 10;
sgeditor.Parent := anOwnerPgCtrl.ActivePage;
sgeditor.OnGetCellHint := @sgGetCellHint;
sgeditor.OnGetEditText := @sgGetCellHint;
sgeditor.OnKeyPress := @sgKeyPress;
sgeditor.OnValidateEntry := @sgValidateEntry;
HideEditor;
end;
procedure TMyEditor.sgKeyPress(Sender: TObject; var Key: char);
var
validkeys : set of char;
begin
case (Sender as TStringGrid).col of
1 : validkeys := ['0'..'9'];
2 : validkeys := ['a'..'z'];
3 : validkeys := ['A'..'Z'];
else
validkeys := [#0..#255];
end;
if not(key in validkeys) then key := #0;
end;
procedure TMyEditor.sgValidateEntry(sender: TObject; aCol, aRow: Integer;
const OldValue: string; var NewValue: String);
begin
Case aCol of
1 : edit1.Text:=sgeditor.Cells[aCol,aRow];
end;
end;
{===============================================================================
shows a hint in statictext1 when cursor moves over cell
===============================================================================}
procedure TmyEditor.sgGetCellHint(Sender: TObject; ACol, ARow: Integer;
var HintText: String);
begin
statictext1.Caption := '';
Case acol of
1 : statictext1.Caption := 'Traverse (T) or Radiation (R) ... default is Traverse';
2 : statictext1.Caption := 'Metres (M), Links (L), Feet (F) ... default is metres';
3 : statictext1.Caption := '+ve includes sector in area, -ve excludes sector from area';
4 : statictext1.Caption := '"." => repeat previous bearing' + #13#10 + '"R" => reverse bearing';
5 : statictext1.Caption := '"." => repeat previous distance';
end;
end;
end.