![]() |
![]() |
![]() |
DelphiWebScriptOOP - Object Orientated Programming |
|
![]() |
Homepage DWS ![]() |
Static ObjectsDWS implements two different kinds of object orientated programming. Using a normal TdwsFunc component it's possible to create "static objects": s:= request.name; The declaration of the TdwsFunc component has to be: "request (string, ...) : <resulttype>". If you replace the dots ... by additional parameters a call of this static method could look like this: s := request.name (1, 2, 4.5); The implementation of the function request looks like this: procedure TForm1.fncRequest
(Sender: TObject; args: TArgList; var Result: Variant); It's also possible to use static objects in an assignment: myobject.value := 2; This statement is transformed into... myobject ("value", 2); Have a look at the demo scripts for more information. Dynamic ObjectsDynamic Objects use almost the same concept as the objects known from Delphi (obj := TObject.Create). E. g. you could use this code in DWS: orders := dbOpen ('ORDERS.DB'); The objects "orders" and "customers" are in fact only variables of type integer. In the example the call to dbOpen creates and opens a Delphi TTable object. To make this object accessible from within DWS it's stored in a object derived from TdwsObj. TdwsDbObj = class (TdwsObj) The function NewObj of the TDelphiWebScript component adds the new object to its internal list an returns an index. This index is stored in the variable orders and customers like a normal integer value. The method calls work similar to the static objects: orders.dbFieldByName ('NAME'); The function dbFieldByName needs to access the TTable object previously stored with a call to the function NewObj. For this purpose the method GetObj has to be called using the integer value returned by NewObj as argument. A possible implementation of dbFieldByNameFunc.Evaluate: proedure TdbFieldByNameFunc.Evaluate; Have a look at the demo scripts for more information.
|