unit WebTbl; {Web 'aware' Table, originally for use with WebHub} (* Copyright (c) 1995-2003 HREF Tools Corp. Authors: Ann Lynnworth, Robert Martin at HREF Tools Corp. Permission is hereby granted, on 27-Feb-2003, free of charge, to any person obtaining a copy of this software (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *) (* Use the TWebTable object (instead of TTable) for the local tables in your application when you want to tag one or more tables as 'unavailable' (i.e. not active). You can then back those tables up, and/or use FTP to update their contents. During this tim e, and page that uses the table can look at the Availability property and give an appropriate 'please try later' message. Surfers would be able to work with all non-database-driven pages during this time (which is far better than having the whole site do wn). When the backup or file transfer is complete, you would set the Availability property back to normal. This sort of functionality would be put on an 'admin only' page that you probably would not link to the rest of your site. Furthermore, there is an onCommand event which is triggered before any sections run. You could toggle a boolean property added to a descendant to implement activating/deactivating tables. Then output can be controlled using conditionals in the page defi nition -- keeping a clean separation between HTML artist and Delphi/C++ programmer. In general, you can activate any feature within your application by creating a custom command which your application recognizes. Perhaps you would build an ADMIN page with commands for DeactivateTables, ActivateTables, ReloadTableOfContents, PackDatabase, ReIndexDatabase, etc. Your .htm page would have a URL such as %=JUMP|ADMIN,PackDatabase|Admin=%. The 'PackDatabase' string would be available for you in TWebApp.Command. You would then customize the OnSection event handler for the ADMIN page to respond as desired. *) interface uses SysUtils, Messages, Classes, Graphics, Controls, Windows , Forms, db, dbTables, StdCtrls , ucTypes, ucString , WebTypes , TpTable; type TTblAvailability=(wtaNormal,wtaReadOnly,wtaBusy); type TWebTable = class(TtpTable) private fAvailability: TTblAvailability; //current mode of the table. fLastField: TField; //last field to be used in the public functions below. protected procedure DoBeforeOpen; Override; procedure SetAvailability(const Value:TTblAvailability); public function LowerCaseFieldValue(const cField: String):String; function FilterExact(const cField: String; s: String):Boolean; function FilterStartsWith(const cField: string; s: String): Boolean; function FilterContains(const cField: String; s: String): Boolean; published property Availability: TTblAvailability read fAvailability write setAvailability default wtaNormal; end; //procedure Register; implementation {-------------------------------------------------------------------------} // procedures to control the table's availability procedure TWebTable.DoBeforeOpen; begin case fAvailability of wtaReadOnly: ReadOnly:=True; {else do nothing} wtaBusy: raise TWebException.create( Self,'['+tableName+'] is unavailable' ); end; inherited DoBeforeOpen; end; procedure TWebTable.setAvailability(const Value:TTblAvailability); var l:boolean; begin if fAvailability<>Value then begin fAvailability:=Value; l:=Active; case Value of wtaNormal: ; wtaReadOnly: begin Close; ReadOnly:=True; end; wtaBusy: l:=false; end; Active:=l; end; end; {----------------------------------------------------------------------------------------} //these functions let you get and compare the current value of a named field function TWebTable.LowerCaseFieldValue(const cField: String):String; begin if (fLastField<>nil) and (comparetext(fLastField.Name,cField)<>0) then fLastField:=nil; //same as last time? if fLastField=nil then //nothing qualified //fLastField:=FindField(cField); //find the field (silently) fLastField:=FieldByName(cField); //find else exception. (safer) if fLastField<>nil then //did we get it Result:=LowerCase(fLastField.AsString) //return the lowercase value else //else.. and this could be a pblm Result:=''; //return a blank string,(FindField) end; function TWebTable.FilterStartsWith(const cField: String; s: String):Boolean; begin Result :=pos(lowercase(s),LowerCaseFieldValue(cField))=1; end; function TWebTable.FilterContains(const cField: String; s: String):Boolean; begin Result := pos(lowercase(s),LowerCaseFieldValue(cField))<>0; end; function TWebTable.FilterExact(const cField: String; s: String):Boolean; begin //case insensitive. Result := lowercase(s) = LowerCaseFieldValue(cField); end; {----------------------------------------------------------------------------------------} //procedure Register; //begin // RegisterComponents('HREF', [TWebTable]); //end; {----------------------------------------------------------------------------------------} end.