1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
type
TBSClientQuery = class ;
TBSClientOption = class (TPersistent)
private
FClient : TBSClientQuery;
FEditor: TcxDBTextEdit;
FRequiredField_1: TStringField;
FRequiredField_2: TStringField;
FAskbeforeDelete: Boolean;
FDeleteMsg: string;
procedure SetEditor(const Value: TcxDBTextEdit);
procedure SetRequiredField_1(const Value: TStringField);
procedure SetRequiredField_2(const Value: TStringField);
procedure CtrlDelete;
procedure CtrlEditor;
procedure CtrlEmptyField;
protected
public
constructor Create(Client : TBSClientQuery);
destructor Destroy ; override;
published
property RequiredField_1: TStringField read FRequiredField_1 write SetRequiredField_1;
property RequiredField_2: TStringField read FRequiredField_2 write SetRequiredField_2;
property Editor: TcxDBTextEdit read FEditor write SetEditor ;
property DeleteMsg: string read FDeleteMsg write FDeleteMsg;
property AskbeforeDelete: Boolean read FAskbeforeDelete write FAskbeforeDelete;
end;
{ ==================================================================================== }
{ Exception Handler will intercept all exceptions in levels : }
{ ------------------------ }
{ + Before insert
+ Before Post
+ Before Edit
+ Before Delete
+ Before Cancel
+ Before Refresh
}
TBSClientQuery = class(TBSDataSet)
private
FAfterCancel: TDataSetNotifyEvent;
FAfterDelete: TDataSetNotifyEvent;
FAfterEdit: TDataSetNotifyEvent;
FAfterInsert: TDataSetNotifyEvent;
FAfterPost: TDataSetNotifyEvent;
FBeforeCancel: TDataSetNotifyEvent;
FBeforeDelete: TDataSetNotifyEvent;
FBeforeEdit: TDataSetNotifyEvent;
FBeforeInsert: TDataSetNotifyEvent;
FBeforePost: TDataSetNotifyEvent;
FClientOption: TBSClientOption;
OldException : TExceptionEvent;
protected
procedure DoAfterCancel; override;
procedure DoAfterDelete; override;
procedure DoAfterEdit; override;
procedure DoAfterInsert; override;
procedure DoAfterPost; override;
procedure DoBeforeCancel; override;
procedure DoBeforeDelete; override;
procedure DoBeforeEdit; override;
procedure DoBeforeInsert; override;
procedure DoBeforePost; override;
procedure BSFireException(Sender:TObject;E:Exception);
procedure BSInstallExecption;
procedure BSUninstallException;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property BeforeInsert: TDataSetNotifyEvent read FBeforeInsert write FBeforeInsert;
property AfterInsert: TDataSetNotifyEvent read FAfterInsert write FAfterInsert;
property BeforeEdit: TDataSetNotifyEvent read FBeforeEdit write FBeforeEdit;
property AfterEdit: TDataSetNotifyEvent read FAfterEdit write FAfterEdit;
property BeforePost: TDataSetNotifyEvent read FBeforePost write FBeforePost;
property AfterPost: TDataSetNotifyEvent read FAfterPost write FAfterPost;
property BeforeCancel: TDataSetNotifyEvent read FBeforeCancel write FBeforeCancel;
property AfterCancel: TDataSetNotifyEvent read FAfterCancel write FAfterCancel;
property BeforeDelete: TDataSetNotifyEvent read FBeforeDelete write FBeforeDelete;
property AfterDelete: TDataSetNotifyEvent read FAfterDelete write FAfterDelete;
property ClientOption: TBSClientOption read FClientOption write FClientOption;
end;
implementation
constructor TBSClientQuery.Create(AOwner: TComponent);
begin
inherited;
FClientOption := TBSClientOption.Create(Self);
end;
{ ------------------------------------------------------- }
{}
{ ------------------------------------------------------- }
destructor TBSClientQuery.Destroy;
begin
FreeAndNil(FClientOption);
inherited;
end;
{ ------------------------------------------------------- }
{}
{ ------------------------------------------------------- }
procedure TBSClientQuery.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent,Operation);
if (Operation = opRemove) and (AComponent=FClientOption.FEditor) then
FClientOption.FEditor := nil;
if (Operation = opRemove) and (AComponent=FClientOption.FRequiredField_1) then
FClientOption.FRequiredField_1 := nil;
if (Operation = opRemove) and (AComponent=FClientOption.FRequiredField_2) then
FClientOption.FRequiredField_2 := nil;
end;
.........
procedure TBSClientOption.SetEditor(const Value: TcxDBTextEdit);
begin
// FEditor := Value;
// CtrlEditor;
//{
//if FEditor<>nil then
// FEditor.FreeNotification(FClient);
if Assigned(FEditor) and (not (csDestroying in FEditor.ComponentState)) then
FEditor.RemoveFreeNotification(FClient);
FEditor := Value;
if Assigned(FEditor) then
FEditor.FreeNotification(FClient);
CtrlEditor;
// }
end;
{ ------------------------------------------------------- }
{}
{ -------------------------------------------------------}
procedure TBSClientOption.SetRequiredField_1(const Value: TStringField);
begin
// FRequiredField_1 := Value;
if Assigned(FRequiredField_1) and (not (csDestroying in FRequiredField_1.ComponentState)) then
FRequiredField_1.RemoveFreeNotification(FClient);
FRequiredField_1 := Value;
if Assigned(FRequiredField_1) then
FRequiredField_1.FreeNotification(FClient);
end;
{ ------------------------------------------------------- }
{}
{ ------------------------------------------------------- }
procedure TBSClientOption.SetRequiredField_2(const Value: TStringField);
begin
// FRequiredField_2 := Value;
if Assigned(FRequiredField_2) and (not (csDestroying in FRequiredField_2.ComponentState)) then
FRequiredField_2.RemoveFreeNotification(FClient);
FRequiredField_2 := Value;
if Assigned(FRequiredField_2) then
FRequiredField_2.FreeNotification(FClient);
end;
constructor TBSClientOption.Create(Client: TBSClientQuery);
begin
FClient := Client;
end;
destructor TBSClientOption.Destroy;
begin
FClient := nil;
inherited;
end; |
Partager