1. 可以使用的對象以下:dom
1.1. 原始類:ide
Tobject, TPersistent ,TList, TStrings, TStringList, TStream, TFileStream, TMemoryStream, TComponent, TfsXMLItem, TfsXMLDocument.函數
A) Tobject:ui
方法:spa
constructor Createrest
Freecode
function ClassName: Stringorm
B)TPersistent :class(Tobject);對象
方法:繼承
procedure Assign(Source: TPersistent)
C) TList :class (TObject)
方法:
function Add(Item: TObject): Integer'
procedure Clear', CallMethod);
procedure Delete(Index: Integer)
function IndexOf(Item: TObject)
procedure Insert(Index: Integer; Item: TObject)
function Remove(Item: TObject): Integer
屬性:
Count: Integer
Items[i: Integer]: TObject'
D) TStrings: class(TPersistent)
function Add(const S: string): Integer
function AddObject(const S: string; AObject: TObject): Integer
procedure Clear', CallMethod);
procedure Delete(Index: Integer)', CallMethod);
function IndexOf(const S: string): Integer', CallMethod);
function IndexOfName(const Name: string): Integer
function IndexOfObject(AObject: TObject): Integer
procedure Insert(Index: Integer; const S: string)
procedure InsertObject(Index: Integer; const S: string; AObject: TObject)
procedure LoadFromFile(const FileName: string)
procedure LoadFromStream(Stream: TStream)
procedure SaveToFile(const FileName: string)
procedure SaveToStream(Stream: TStream)
屬性:
CommaText:string
Count:Integer
Names', 'Integer', 'string', CallMethod, True);
Objects', 'Integer', 'TObject',;
Values', 'String', 'string',;
Strings[i: Integer', 'string',
'Text', 'string', GetProp, SetProp);
end;
E)TStringList: class(TStrings)
方法:
function Find(s: String; var Index: Integer): Boolean
procedure Sort', CallMethod)
屬性:
Duplicates: TDuplicates
Sorted:Boolean
F) TStream:class(TObject)
方法:
function Read(Buffer: string; Count: Longint): Longint
function Write(Buffer: string; Count: Longint): Longint
function Seek(Offset: Longint; Origin: Word): Longint
function CopyFrom(Source: TStream; Count: Longint): Longint
屬性:
Position:Longint
Size:Longint
G) TFileStream:class('TStream')
constructor Create(Filename: String; Mode: Word)
H) TMemoryStream:class('TStream')
procedure Clear', CallMethod);
procedure LoadFromStream(Stream: TStream)
procedure LoadFromFile(Filename: String)
procedure SaveToStream(Stream: TStream)
procedure SaveToFile(Filename: String)
I) TComponent:class(TPersistent)
方法:
constructor Create(AOwner: TComponent)
屬性:
Owner:Component
J) TfsXMLItem:=class(TObject)
方法:
constructor Create
procedure AddItem(Item: TfsXMLItem)
procedure Clear', CallMethod)
procedure InsertItem(Index: Integer; Item: TfsXMLItem)
function Add: TfsXMLItem
function Find(const Name: String): Integer
function FindItem(const Name: String):
function Prop(const Name: String): String
function Root: TfsXMLItem
屬性:
Data:Integer
Count:Integer
Items[i: Integer]: TfsXMLItem
Name:String
Parent:TfsXMLItem
Text:String
K) TfsXMLDocument:=class('TObject')
方法:
constructor Create
procedure SaveToStream(Stream: TStream)
procedure LoadFromStream(Stream: TStream)
procedure SaveToFile(const FileName: String)
procedure LoadFromFile(const FileName: String)
屬性:
Root:fsXMLItem'
-------------------------------------------------------------------------------------
1.2. 經常使用類:(若是須要使用此類控件須要加fsFormsRTTI1控件)
控件:
TWinControl類(TWinControl: Class(Tcontrol))
TEdit,TMemo,Tmaskedit,TCombobox,TCheckBox,TRadioButton,TBitbtn, TListBox,TForm, TTScrollBox
TControl類 (TControl: Class(TComponent))
TSpeedbutton ,Ttoolbar ,Tpanel ,Tbitbtn,TLabel ,TGroupBox ,TImage,TShape,TToolbar
TComponent 類
TDataModule
------------------------------------------------------------------------------------
說明:
對於TControl有
方法:
procedure Hide
procedure Show
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer)', CallMethod);
事件:
OnCanResize
OnClick
OnDblClick
OnMouseDown
OnMouseMove
OnMouseUp
OnResize
對於TWinControl除了有上面TControl的方法和事件外,還有:
方法:
procedure SetFocus
事件:
OnEnter
OnExit
OnKeyDown
OnKeyPress
OnKeyUp
對於TCombobox還有以下事件:
OnChange
OnDropDown
OnCloseUp
除了有Published屬性外還有以下屬性:
DroppedDown:Boolean
ItemIndex:Integer
對於TEdit,TMemo還有以下方法:
procedure CopyToClipboard
procedure CutToClipboard
procedure PasteFromClipboard
對於TlistBox除了有Published屬性外還有以下屬性:
ItemIndex:Integer
SelCount:integer
Selected[Index: Integer]: Boolean
對於Form類還有:
方法:
procedure Close
procedure Hide
procedure Show
function ShowModal: Integer
事件:
OnActivate
OnClose
OnCloseQuery
OnCreate
OnDestroy
OnDeactivate
OnHide
OnPaint
OnShow
除了有Published屬性外還有以下屬性:
Canvas
ModalResult
---------------------------------------------------------------------------------------------------------------------
1.3. 數據敏感類:(若是須要使用此類控件須要加fsDBCtrlRTTI1控件)
控件:
TWinControl類
TDBEdit,TDBComboBox,TDBImage,TDBCheckBox,TDBListBox,TDBMemo,TDBNavigator,TDBRadioGroup,TDBLookupControl,TDBLookupListBox,TDBLookupComboBox,TDBGrid
TGraphicControl(在fsFormsRTTI1裏定義 AddClass(TGraphicControl, 'TControl')
TDBText
TPersistent類:
TColumnTitle,TColumn,TDBGridColumns
說明:
對於TDBCheckBox除了有Published屬性外還有以下屬性:
Checked:Boolean
對於TDBComboBox
除了有Published屬性外還有以下屬性:
Text:String
DroppedDown:Boolean
ItemIndex:Integer
除了Twincontrol事件外,還有以下事件:
OnChange
OnDropDown
OnCloseUp
對於TDBListBox除了有Published屬性外還有以下屬性:
ItemIndex:Integer
SelCount:integer
Selected[Index: Integer]: Boolean
對於TDBRadioGroup除了有Published屬性外還有以下屬性:
ItemIndex:Integer
Value:String
對於TDBLookupListBox除了有Published屬性外還有以下屬性:
KeyValue:Variant
SelectedItem:String
對於TDBLookupComboBox除了有Published屬性外還有以下屬性:
KeyValue:Variant
Text:String
對於TDBGridColumns
除了有Published屬性外還有以下屬性:
Items[i:Integer]:Tcolumn
方法:
function Add: TColumn
function Count: Integer
procedure RebuildColumns
procedure RestoreDefaults
1.4. 字段和數據集類:( 若是須要使用此類控件須要加fsDBRTTI1控件)
A) TField: class(TComponent)
屬性:
AsBoolean:Boolean
AsCurrency:Currency
AsDateTime:TDateTime
AsFloat:Double
AsInteger:Integer
AsString:String
AsVariant:Variant
DataType:TFieldType
DisplayName:String
DisplayText:String
IsNull:Boolean
Size:Integer
Value:Variant
B) TFields:class(TObject)
屬性:
Fields[i: Integer]:TField
C) TStringField: class(TField)
D) TNumericField: class(TField)
E) TIntegerField: class(TNumericField)
F) TSmallIntField: class(TIntegerField)
G) TWordField: class(TIntegerField)
H) TAutoIncField: class(TIntegerField)
I) TFloatField: class(TNumericField)
J) TCurrencyField: class(TFloatField)
K) TBooleanField: class(TField)
L) TDateTimeField: class(TField)
M) TDateField: class(TDateTimeField)
N) TTimeField: class(TDateTimeField)
O) TBinaryField: class(TField)
P) TBytesField : class(TBinaryField)
Q) TVarBytesField: class(TBinaryField)
R) TBCDField: class(TNumericField)
S) TBlobField: class(TField)
方法:
procedure LoadFromFile(const FileName: String)
procedure LoadFromStream(Stream: TStream)
procedure SaveToFile(const FileName: String)
procedure SaveToStream(Stream: TStream)
T) TMemoField:class(TBlobField)
U) TGraphicField: (TBlobField)
V) TFieldDef: class(TPersistent)
W) TFieldDefs: class(TObject)
function AddFieldDef: TFieldDef', CallMethod);
function Find(const Name: string): TFieldDef', CallMethod);
procedure Add(const Name: string; DataType: TFieldType; Size: Word; Required: Boolean)
procedure Clear
procedure Update
屬性:
Items[i:Integer] :TFieldDef
X) TDataSource: class(TComponent)
Y) TDataSet: TComponent
方法:
procedure Open
procedure Close
procedure First
procedure Last
procedure Next
procedure Prior
procedure Cancel
procedure Delete
procedure Post
procedure Append
procedure Insert
procedure Edit
function FieldByName(const FieldName: string): TField
procedure GetFieldNames(List: TStrings)
function FindFirst: Boolean
function FindLast: Boolean
function FindNext: Boolean
function FindPrior: Boolean', CallMethod);
procedure FreeBookmark(Bookmark: TBookmark)
function GetBookmark: TBookmark
procedure GotoBookmark(Bookmark: TBookmark)', CallMethod);
function Locate(const KeyFields: string; const KeyValues: Variant;' +
'Options: TLocateOptions): Boolean
function IsEmpty: Boolean
屬性:
Bof:Boolean
Eof:Boolean
fieldCount:Integer
RecordCount:Integer
FieldDefs:TFieldDefs
Fields:TFields
Filter:string
Filtered:Boolean
FilterOptions:TFilterOptions
Active:Boolean
事件:
BeforeOpen
AfterOpen;
BeforeClose
AfterClose
BeforeInsert
AfterInsert
BeforeEdit
AfterEdit
BeforePost
AfterPost
BeforeCancel
AfterCancel
BeforeDelete
AfterDelete
BeforeScroll
AfterScroll
OnCalcFields
OnFilterRecord
OnNewRecord
Z) TParam:class(TPersistent)
方法:
procedure Clear
屬性:
AsBoolean:Boolean
AsCurrency:Currency
AsDateTime:TDateTime
AsFloat:Double
AsInteger:Integer
AsDate:TDate
AsTime:TTime
AsString:String
Bound:Boolean
IsNull:Boolean
Text:String
AA) TParams:class(TPersistent)
方法:
function ParamByName(const Value: string): TParam
事件:
function FindParam(const Value: string): TParam
屬性:
Item[i: Integer]:TParam
1.5. ADO類:( 若是須要使用此類控件須要加fsADORTTI1控件)
TDataBase,TDataSource,TDataSet,TAdoconnection,TAdoDataSet,TAdoquery,TAdoTable,TAdoStoredProc,TClientDataSet
A) TADOConnection:TComponent
B) TParameter:TPersistent
屬性:
Items[i:Integer]:TParameter
C) TCustomADODataSet: class(TDataSet)
D) TADODataSet:class(TCustomADODataSet)
E) TCustomClientDataSet:class(TDataSet)
F) TADOTable:class(TCustomADODataSet);
G) TADOQuery:class(TCustomADODataSet') do
方法:
procedure ExecSQL
H) TADOStoredProc:TCustomADODataSet
方法:
procedure ExecProc
I) TClientDataSet: class(TCustomClientDataSet
方法:
procedure Excute
1.6. BDE類:(若是須要使用此類控件須要加fsBDERTTI1控件)
TTable,Tquery,TDataBase,TStoreProc,TSession
對於TDataBase能夠使用以下方法:
procedure Open
對於TTable能夠使用以下方法:
procedure CreateTable
procedure DeleteTable;
procedure EmptyTable;
function FindKey(const KeyValues: array): Boolean;
procedure FindNearest(const KeyValues: array);
procedure RenameTable(const NewTableName: string);
對於TQuery能夠使用以下方法:
procedure ExecSQL
function ParamByName(const Value: string): TParam
procedure Prepare
ParamCount
對於TStoredProc能夠使用以下方法:
procedure ExecProc
function ParamByName(const Value: string): TParam
procedure Prepare
ParamCount
1.7. 對話類:(若是須要使用此類控件須要加fsDialogRTTI1控件)
TOpenDialog、TSaveDialog、TColorDialog 、TFontDialog、TPrintDialog、TPrinterSetupDialog
function InputBox(ACaption, APrompt, ADefault: string): string
function InputQuery(ACaption, APrompt: string; var Value: string): Boolean
1.8. 圖像類:
控件:
TFont,TPen,TBrush,TCanvas,TGraphic,TMetafile,Timage,TMetafileCanvas,TBitmap
對於TCanvas: TPersistent,除了TPersistent的方法外還有以下方法:
procedure Draw(X, Y: Integer; Graphic: TGraphic)
procedure Ellipse(X1, Y1, X2, Y2: Integer)
procedure LineTo(X, Y: Integer)
procedure MoveTo(X, Y: Integer)
procedure Rectangle(X1, Y1, X2, Y2: Integer)
procedure RoundRect(X1, Y1, X2, Y2, X3, Y3: Integer)
procedure StretchDraw(X1, Y1, X2, Y2: Integer; Graphic: TGraphic)
function TextHeight(const Text: string):Integer
procedure TextOut(X, Y: Integer; const Text: string)
function TextWidth(const Text: string):Integer
Pixels(X, Y: Integer;):TColor
對於TGraphic= class(TPersistent)
除了TPersistent的方法外,還有以下
方法:
procedure LoadFromFile(const Filename: string)', CallMethod);
procedure SaveToFile(const Filename: string)', CallMethod);
屬性:
Height:Integer
Width:Integer
對於TBitmap: TGraphic
除了TPersistent的屬性外,還有以下屬性:
Canvas: TCanvas
2. 經常使用函數:(系統默承認以使用下列函數)
轉換類:
IntToStr(i: Integer): String
FloatToStr(e: Extended): String
DateToStr(e: Extended): String
TimeToStr(e: Extended): String
DateTimeToStr(e: Extended): String
VarToStr(v: variant): String
StrToInt(s: String): Integer
StrToFloat(s : String): Float
StrToDate(s: String): TDate
StrToTime(s: String): TTime
StrToDateTime(s:String): TDateTime
格式化類:
Format(Fmt: String; Args: array): String
FormatFloat(Fmt: String; Value: Extended): String
FormatDateTime(Fmt: String; DateTime: TDateTime): String
FormatMaskText(EditMask: String; Value: String): String
時間類:
function EncodeDate(Year, Month, Day: Word): TDateTime
procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word)
function EncodeTime(Hour, Min, Sec, MSec: Word): TDateTime
procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word)
function Date: TDateTime
function Time: TDateTime
function Now: TDateTime
function DayOfWeek(aDate: DateTime): Integer
function IsLeapYear(Year: Word): Boolean
function DaysInMonth(nYear, nMonth: Integer): Integer
字符串類:
function Length(s: String): Integer
function Copy(s: String; from, count: Integer): String
function Pos(substr, s: String): Integer
procedure Delete(var s: String; from, count: Integer): String
procedure Insert(s: String; var s2: String; pos: Integer): String'
function Uppercase(s: String): String
function Lowercase(s: String): String
function Trim(s: String): String
function NameCase(s: String): String
function CompareText(s, s1: String): Integer
function Chr(i: Integer): Char
function Ord(ch: Char): Integer
procedure SetLength(var S: String; L: Integer)
數學類:
function Round(e: Extended): Integer
function Trunc(e: Extended): Integer
function Int(e: Extended): Integer
function Frac(X: Extended): Extended
function Sqrt(e: Extended): Extended
function Abs(e: Extended): Extended
function Sin(e: Extended): Extended
function Cos(e: Extended): Extended
function ArcTan(X: Extended): Extended
function Tan(X: Extended): Extended
function Exp(X: Extended): Extended
function Ln(X: Extended): Extended
function Pi: Extended
其餘:
procedure Inc(var i: Integer; incr: Integer = 1)
procedure Dec(var i: Integer; decr: Integer = 1)
procedure RaiseException(Param: String)
procedure ShowMessage(Msg: Variant)
procedure Randomize
function Random: Extended
function ValidInt(cInt: String): Boolean
function ValidFloat(cFlt: String): Boolean
function ValidDate(cDate: String): Boolean
說明:
因爲FastScript解釋執行腳本,因此不少對象或者對象的屬性都沒有包括,也就是在Delphi中有的對象或屬性、方法等在腳本里面可能不能用,以上面所述爲準。可是對於大多數狀況下,FastScript能知足,且能較方便地進行擴展。
1.在FastScript中,任何類都能用屬於Published的屬性,若是又加了屬性,則也能夠用。
2.子類繼承父類的全部方法和屬性。也就是子類能夠使用父類的全部方法和屬性。
若是有加了方法和事件,也同樣能夠用
編者:袁鋒
日期: 2004-06-05
附:
A.關於如何使用第三方控件,增長方法、屬性、事件)
舉例以下:
如:有一控件爲edtbutton:TedtButton,咱們須要在動態腳本中使用該控件。咱們採用以下方法:
咱們能夠把該控件申明在fs_iformsrtti單元裏面(固然也能夠申明在其餘的單元如fs_idbrtti裏面,可是遵照一個原則是儘可能使得功能類似的控件放在同一個單元裏面,這樣只須要把該單元所對應的控件拖動到form上便可,提升系統運行效率)
如:fs_iformsrtti單元對應控件板上的fsiformsrtti。以此類推
AddClass(TedtButton, 'TControl');
對於增長方法:請看以下例子:
如須要增長Tedit類的CopyToClipboard、CutToClipboard、PasteFromClipboard方法。則代碼以下所示:
with AddClass(TEdit, 'TWinControl') do
begin
AddMethod('procedure CopyToClipboard', CallMethod);
AddMethod('procedure CutToClipboard', CallMethod);
AddMethod('procedure PasteFromClipboard', CallMethod);
end;
在 CallMethod中須要增長相應方法的實現。
function TFunctions.CallMethod(Instance: TObject; ClassType: TClass;
const MethodName: String; var Params: Variant): Variant;
var
Form: TCustomForm;
begin
Result := 0;
if ClassType = TControl then
begin
if MethodName = 'HIDE' then
TControl(Instance).Hide
else if MethodName = 'SHOW' then
TControl(Instance).Show
else if MethodName = 'SETBOUNDS' then
TControl(Instance).SetBounds(Params[0], Params[1], Params[2], Params[3])
end
else if ClassType = TWinControl then
begin
if MethodName = 'SETFOCUS' then
TWinControl(Instance).SetFocus
end
else if ClassType = TEdit then//須要增長的實現(只是對於Tedit);
begin
if MethodName = uppercase('CopyToClipboard') then
Tedit(Instance).CopyToClipboard ;
if MethodName = uppercase('CutToClipboard') then
Tedit(Instance).CutToClipboard ;
if MethodName = uppercase('PasteFromClipboard') then
Tedit(Instance).PasteFromClipboard ;
end
End
對於增長屬性:請看以下例子:
如須要增長TdataSet的RecordCount屬性,則代碼以下所示:
with AddClass(TDataSet, 'TComponent') do
begin
AddMethod('procedure Open', CallMethod);
……
AddProperty('FieldCount', 'Integer', GetProp, nil);
AddProperty('RecordCount', 'Integer',GetProp,nil); 由於RecordCount屬性只有讀沒有寫。
AddProperty('Active', 'Boolean', GetProp, SetProp);既能讀又能寫。
End
若是有寫過程,則須要在 GetProp過程當中增長相應屬性的實現。
function TFunctions.GetProp(Instance: TObject; ClassType: TClass;
const PropName: String): Variant;
begin
…….
if ClassType = TField then
begin
……
Result := _TField.Size
else if PropName = 'VALUE' then
Result := _TField.Value
……
end
else if ClassType = TDataSet then
begin
……
else if PropName = 'FIELDCOUNT' then
Result := _TDataSet.FieldCount
else if PropName = 'RECORDCOUNT' then
Result := _TDataSet.RecordCount
……
end。
procedure TFunctions.SetProp(Instance: TObject; ClassType: TClass;
const PropName: String; Value: Variant);
……
if ClassType = TField then
begin
_TField := TField(Instance);
if PropName = 'ASBOOLEAN' then
_TField.AsBoolean := Value
else if PropName = 'ASCURRENCY' then
_TField.AsCurrency := Value
else if PropName = 'ASDATETIME' then
_TField.AsDateTime := Value
else if PropName = 'ASFLOAT' then
_TField.AsFloat := Value
else if PropName = 'ASINTEGER' then
_TField.AsInteger := Value
else if PropName = 'ASSTRING' then
_TField.AsString := Value
else if PropName = 'ASVARIANT' then
_TField.AsVariant := Value
else if PropName = 'VALUE' then
_TField.Value := Value
end
else if ClassType = TDataSet then
begin
_TDataSet := TDataSet(Instance);
if PropName = 'FILTER' then
_TDataSet.Filter := Value
else if PropName = 'FILTERED' then
_TDataSet.Filtered := Value
else if PropName = 'FILTEROPTIONS' then
_TDataSet.FilterOptions := IntToFilterOptions(Value)
else if PropName = 'ACTIVE' then
_TDataSet.Active := Value
end
……
B.調用Delphi過程:
1. 先建立事件處理方法:TfsCallMethodEvent
2. 而後再用調用TfsScript.AddMethod方法,第一個參數爲Delphi方法的語法,第二個參數爲TfsCallMethodEvent連接的一個句柄。
如在Delphi有一個過程爲DelphiFunc,
…..
procedure TForm1.DelphiFunc(s: String; i: Integer);
begin
ShowMessage(s + ', ' + IntToStr(i));
end;
{TfsCallMethodEvent}
function TForm1.CallMethod(Instance: TObject; ClassType: TClass; const MethodName: String;
var Params: Variant): Variant;
begin
if MethodName = 'DELPHIFUNC' then //注意方法名稱都爲大寫比較。
DelphiFunc(Params[0], Params[1]);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{ clear all items }
fsScript1.Clear;
{ script text }
fsScript1.Lines := Memo1.Lines;
{ frGlobalUnit contains standard types and functions }
fsScript1.Parent := fsGlobalUnit;
{ make DelphiFunc procedure visible to a script }
fsScript1.AddMethod('procedure DelphiFunc(s: String; i: Integer)', CallMethod);
{ compile the script }
if fsScript1.Compile then
fsScript1.Execute else{ execute if compilation was succesfull }
ShowMessage(fsScript1.ErrorMsg); { show an error message }
end;
C.調用FastScript過程:與調用Delphi函數相似。
舉例說明:若是在動態腳本里面有一個'ScriptFunc'的一個過程,則在delphi代碼裏須要寫以下:
fsScript1.Clear;
{ script text }
fsScript1.Lines := Memo1.Lines;
{ frGlobalUnit contains standard types and functions }
fsScript1.Parent := fsGlobalUnit;
{ make DelphiFunc procedure visible to a script }
{ compile the script }
if fsScript1.Compile then
{ Call script function with one string parameter and one integer param }
fsScript1.CallFunction('ScriptFunc', VarArrayOf(['Call ScriptFunc', 1])) else
ShowMessage(fsScript1.ErrorMsg); { show an error message }
end;
例如動態腳本內容以下:
procedure ScriptFunc(Msg: String; Num: Integer);
begin
ShowMessage('1st param: ' + Msg +
'2nd param: ' + IntToStr(Num));
end;
begin
DelphiFunc('Call DelphiFunc', 1);
end.