unit BaseDataProvider; interface uses mybean.core.objects, System.Classes; type TBaseDataProvider = class(TMyBeanInterfacedObject) private FInited: Boolean; procedure Init(ATableName: string; ACreateTableSQL: string); protected function GetTableName: string; virtual; function GetCreateTableSQL: string; virtual; function CreatePointerResult(ASize: Integer): Pointer; public constructor Create(); override; destructor Destroy(); override; function ReInit: Boolean; procedure Uninstall; stdcall; procedure DestroyResult(var AObject); overload; procedure DestroyResult(AIntfaceOBject: IInterface); overload; procedure DestroyResult(var APointer: Pointer); overload; property Inited: Boolean read FInited; end; implementation uses FireDAC.Comp.Client, BaseDataModule, System.SysUtils, LoggerImport; { TBaseDataProvider } constructor TBaseDataProvider.Create; begin inherited; end; function TBaseDataProvider.CreatePointerResult(ASize: Integer): Pointer; begin Result := GetMemory(ASize); end; destructor TBaseDataProvider.Destroy; begin inherited; end; procedure TBaseDataProvider.DestroyResult(var AObject); begin if TObject(AObject) <> nil then FreeAndNil(AObject); end; procedure TBaseDataProvider.DestroyResult(AIntfaceOBject: IInterface); begin AIntfaceOBject := nil; end; procedure TBaseDataProvider.DestroyResult(var APointer: Pointer); begin FreeMemory(APointer); APointer := nil; end; function TBaseDataProvider.GetCreateTableSQL: string; begin end; function TBaseDataProvider.GetTableName: string; begin end; procedure TBaseDataProvider.Init(ATableName, ACreateTableSQL: string); var list: TStringList; str: string; AConnection: TFDCustomConnection; begin if BaseDataModel = nil then begin FInited := False; Info('BaseDataModel»¹Î´³õʼ»¯.', 'TBaseDataProvider.Init'); Exit; end; if (ATableName = '') or (ACreateTableSQL = '') then Exit; AConnection := BaseDataModel.GetConnection; if AConnection = nil then Exit; list := TStringList.Create; try AConnection.GetTableNames('','','',list); for str in list do if string.Compare(str, ATableName, true) = 0 then begin FInited := True; Exit; end; AConnection.ExecSQL(ACreateTableSQL); FInited := True; finally FreeAndNil(list); BaseDataModel.GiveBackConnection(AConnection); end; end; function TBaseDataProvider.ReInit: Boolean; begin if FInited then begin Result := FInited; Exit; end; Init(GetTableName, GetCreateTableSQL); Result := FInited; end; procedure TBaseDataProvider.Uninstall; begin FInited := False; end; end.