home *** CD-ROM | disk | FTP | other *** search
- unit Macrec;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, ExtCtrls;
-
- type
- TMacroForm = class(TForm)
- Panel1: TPanel;
- OKBtn: TButton;
- CancelBtn: TButton;
- MacroMemo: TMemo;
- MsgLabel: TLabel;
- Panel2: TPanel;
- MacKeyLabel: TLabel;
- KeyCharEdit: TEdit;
- MacKeyMsg: TLabel;
- procedure OKBtnClick(Sender: TObject);
- procedure CancelBtnClick(Sender: TObject);
- procedure MacroMemoKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- procedure FormActivate(Sender: TObject);
- procedure KeyCharEditChange(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- const
- MaxLen = 255; { Delphi 1's default maximum string length }
- MKLABEL = 'Macro Key CTRL-ALT-';
-
- var
- MacroForm: TMacroForm;
-
- implementation
-
- {$R *.DFM}
- uses MacEd; { This 'uses' clause must be placed beneath the 'implementation'
- keyword, otherwise you will generate a circular reference (since
- this unit is itself used by the MacEd unit.
-
- The reason for this using MacEd is that it references
- the MainForm.GetMacString method in that unit }
-
- procedure TMacroForm.OKBtnClick(Sender: TObject);
- var
- OK : TModalResult;
- begin
- OK := mrOK; { by default, return mrOK, which will close MacroForm }
- if MacroMemo.Text = '' then
- if KeyCharEdit.Text = '' then OK := mrCancel { there's nothing to process }
- else if MessageDlg('Assign no text to this macro key?',
- mtConfirmation, mbOkCancel, 0) = mrCancel then
- OK := mrNone;{ if user selects Cancel, don't close MacroForm }
- ModalResult := OK;
- end;
-
- procedure TMacroForm.CancelBtnClick(Sender: TObject);
- begin
- ModalResult := mrCancel;
- end;
-
- procedure TMacroForm.MacroMemoKeyUp(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- { When the user has almost entered the maximum allowed macro text
- (MexLen-10), show a warning message. Show another message when
- maximum text is entered }
- var
- TextLen : integer;
- begin
- TextLen := Length(MacroMemo.Text);
- MsgLabel.Caption := IntToStr(TextLen) + ' chars. ';
- if (TextLen = MaxLen) then
- MsgLabel.Caption := MsgLabel.Caption +
- 'WARNING! Cannot add more text!'
- else if (TextLen > (MaxLen-10)) then
- MsgLabel.Caption := MsgLabel.Caption +
- 'WARNING! Near to maximum size!';
- end;
-
- procedure TMacroForm.FormActivate(Sender: TObject);
- { Clear any text. Set Memo to ReadOnly.
- Show KeyCharEdit to let user add macro-key char }
- begin
- MacroMemo.Clear;
- MacroMemo.ReadOnly := true;
- MacKeyLabel.Caption := MKLABEL;
- KeyCharEdit.Text := '';
- KeyCharEdit.Show;
- ActiveControl := KeyCharEdit; { set focus when showing form }
- end;
-
- procedure TMacroForm.KeyCharEditChange(Sender: TObject);
- { The KeyCharEdit field remains active until the user
- enters a valid macro-activation character ('A' to 'Z').
- Then it is hidden and the Memo is activated for the user
- to enter the macro text. If the activator character already
- has macro text associated with it, this text is placed
- into the Memo for editing }
- var
- ch : char;
- begin
- If KeyCharEdit.Text <> '' then
- begin
- ch := KeyCharEdit.Text[1];
- if ch = '' then
- { do nothing }
- else if not (UpCase( ch ) in ['A'..'Z']) then
- MacKeyMsg.Caption := 'Key must be a letter.'
- else
- begin
- KeyCharEdit.Hide;
- MacKeyLabel.Caption := MKLABEL + UpCase(ch);
- MacroMemo.ReadOnly := false;
- MacroMemo.Text := MainForm.GetMacString( ch ); { get existing macro text }
- ActiveControl := MacroMemo;
- end;
- end;
- end;
-
- end.
-