TFormScript
: Shows how the TatPascalScripter power can be applied to allow
end user form customization
Downloads :![]()
![]()
![]()
![]()
Script to adapt
the form for visually impaired users : procedure TFormScript.Loaded;
begin
inherited;
with AddDelphiClass(TWinControl) do
begin
AddMethod('ControlCount',0,tkInteger,nil,GetControlCount);
AddMethod('Controls',1,tkClass,TControl,GetControls);
end;
with AddDelphiClass(TFont) do
begin
AddMethod('SetBold',1,tkNone,nil,SetBold);
AddMethod('SetItalic',1,tkNone,nil,SetBold);
AddMethod('SetUnderline',1,tkNone,nil,SetBold);
end;
SystemLibrary.AddObject('Form', Owner);
FOwner := TForm(Owner);
SystemLibrary.AddConstant('cRed',clRed);
//... initialize more color constants here
SystemLibrary.AddConstant('False',False);
SystemLibrary.AddConstant('True',True);
// automatically load the script from file
if FScriptFile <> '' then
if FileExists(FScriptFile) then
SourceCode.LoadFromFile(FScriptFile);
end;
As is shown the Loaded method adds the methods SetBold, SetItalic, SetUnderline to a TFont object. This is a convenient method to allow manipulation of the array property Style of a TFont object from the Pascal script. The routines take one boolean parameter and are implemented like this : procedure TFormScript.SetBold;
begin
if GetInputArgAsBoolean(0) then
TFont(CurrentObject).Style := TFont(CurrentObject).Style + [fsBold]
else
TFont(CurrentObject).Style := TFont(CurrentObject).Style - [fsBold];
end;
From the script, whenever
there is an instance of a font, you can write :
Font.SetBold(true) or Font.SetBold(False); procedure TFormScript.AddChildControls(Control: TWinControl);
var
i: Integer;
begin
for i := 0 to Control.ControlCount - 1 do
begin
SystemLibrary.AddObject(Control.Controls[i].Name,Control.Controls[i]);
if Control.Controls[i] is TWinControl then
if (Control.Controls[i] as TWinControl).ControlCount > 0 then
begin
AddChildControls(TWinControl(Control.Controls[i]));
end;
end;
end;
procedure TFormScript.Prepare;
begin
AddChildControls(FOwner);
end;
3) Starting to
play with scriptable forms
|