![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » DBISAM Technical Support » Product Manuals » DBISAM Version 4 Manual for RAD Studio XE2 (Delphi Win64) » Using DBISAM » Customizing the Engine |
procedure TMyForm.EngineBeforeDeleteTrigger(Sender: TObject; TriggerSession: TDBISAMSession; TriggerDatabase: TDBISAMDatabase; const TableName: String; CurrentRecord: TDBISAMRecord); var OrdersQuery: TDBISAMQuery; begin if (AnsiCompareText(TableName,'customer')=0) then begin OrdersQuery:=TDBISAMQuery.Create(nil); try with OrdersQuery do begin SessionName:=TriggerDatabase.SessionName; DatabaseName:=TriggerDatabase.DatabaseName; RequestLive:=True; SQL.Text:='SELECT * FROM Orders '+ 'WHERE CustNo=:CustNo AND '+ 'AmountPaid < ItemsTotal'; ParamByName('CustNo').AsFloat:= CurrentRecord.FieldByName('CustNo').AsFloat; Open; try if (RecordCount > 0) then raise Exception.Create('Cannot delete this '+ 'customer, there are still '+ IntToStr(RecordCount)+' active '+ 'orders present for this '+ 'customer'); finally Close; end; end; finally OrdersQuery.Free; end; end; end;
begin { We'll just use the default Engine global function for this example } with Engine do begin with Functions.CreateFunction(ftInteger,'DaysBetween').Params do begin CreateFunctionParam(ftDate); CreateFunctionParam(ftDate); end; end; end;
procedure MyForm.CustomFunction(Sender: TObject; const FunctionName: String; FunctionParams: TDBISAMParams; var Result: Variant); var Stamp1: TTimeStamp; Stamp2: TTimeStamp; begin if (AnsiCompareText(FunctionName,'DaysBetween')=0) then begin { Notice that the function parameters are accessed in a 0-based manner } Stamp1:=DateTimeToTimeStamp(FunctionParams[0].AsDateTime); Stamp2:=DateTimeToTimeStamp(FunctionParams[1].AsDateTime); Result:=Trunc((Stamp2.Date-Stamp1.Date)+ (((((Stamp2.Time-Stamp1.Time)/1000)/60)/60)/24)); end; end;
Extensions | Properties |
Event | Description |
OnServerStart | This event will be triggered whenever the server starts listening for incoming normal data connections. The server is started via the TDBISAMEngine StartMainServer method or remotely via the TDBISAMSession StartRemoteServer method. |
OnServerStop | This event will be triggered whenever the server stops listening for incoming noraml data connections. The server is stopped via the TDBISAMEngine StopMainServer method or remotely via the TDBISAMSession StopRemoteServer method. |
OnServerConnect | This event will be triggered whenever a normal data connection is established. |
OnServerReconnect | This event will be triggered whenever a normal data connection is re-established by an automatic reconnection by the remote session. |
OnServerLogin | This event will be triggered whenever a user logs in on a normal data connection. |
OnServerLogout | This event will be triggered whenever a user logs out on a normal data connection. |
OnServerDisconnect | This event will be triggered whenever a normal data connection is closed. |
Event | Description |
OnServerLogEvent | This event is triggered whenever the server needs to log an event. The log record that is passed to the event handler is defined as a TLogRecord type. |
OnServerLogCount | This event is triggered whenever the server needs to get a count of the number of log records in the current log. This event is triggered whenever the TDBISAMEngine GetServerLogCount method is called or the TDBISAMSession GetRemoteLogCount method is called by a remote session. |
OnServerLogRecord | This event is triggered whenever the server needs to get a specific log record from the current log. This event is triggered whenever the TDBISAMEngine GetServerLogRecord method is called or the TDBISAMSession GetRemoteLogRecord method is called by a remote session. |
procedure TMyForm.ServerScheduledEvent(Sender: TObject; const EventName: String; var Completed: Boolean); var TempSession: TDBISAMSession; TempDatabase: TDBISAMDatabase; TempDescription: string; TempPath: string; BackupFiles: TStrings; begin TempDescription:=''; TempPath:=''; if (AnsiCompareText(EventName,'DailyBackup')=0) then begin { Create a new session component, remembering the multi-threading requirements of DBISAM for session names } TempSession:=TDBISAMSession.Create(Self); try with TempSession do begin SessionName:='DailyBackup'+IntToStr(GetCurrentThreadID); Active:=True; end; { Create a new database component } TempDatabase:=TDBISAMDatabase.Create(Self); try with TempDatabase do begin SessionName:=TempSession.SessionName; DatabaseName:='DailyBackup'; { Get the actual local path for the Main database } ServerEngine.GetServerDatabase('Main', TempDescription, TempPath); Directory:=TempPath; Connected:=True; BackupFiles:=TStringList.Create; try TempSession.GetTableNames(DatabaseName,BackupFiles); Completed:=Backup( IncludeTrailingBackslash(TempPath)+'backup'+ StringReplace(DateToStr(Date),'/', '',[rfReplaceAll])+'.bkp', 'Daily Backup for '+DateToStr(Date),6,BackupFiles); finally BackupFiles.Free; end; Connected:=False; end; finally TempDatabase.Free; end; finally TempSession.Free; end; end else Completed:=True; end;
procedure TMyForm.ServerProcedure(Sender: TObject; ServerSession: TDBISAMSession; const ProcedureName: String); var TempFileName: string; begin if (AnsiCompareText(ProcedureName,'TextFile')=0) then begin with ServerSession do begin TempFileName:=RemoteParams.ParamByName('FileName').AsString; { Now clear the parameters for use in populating the result parameters } RemoteParams.Clear; if FileExists(TempFileName) then begin { If the file exists, use the TDBISAMParam LoadFromFile method to load the file data into the parameter } with RemoteParams.CreateParam(ftMemo,'FileContents') do LoadFromFile(TempFileName,ftMemo); end else { If the file doesn't exist, just create a NULL parameter with the correct result name } RemoteParams.CreateParam(ftMemo,'FileContents'); end; end; end;
This web page was last updated on Thursday, November 16, 2023 at 10:39 AM | Privacy Policy![]() © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |