Все остальные модули DBTreeView используют модуль соединения. В данном модуле 3 класса
1) класс параметров соединения, – TDBConnectionParams
Он нужен для показа параметров соединения в инспекторе объектов
2)Класс таблицы TDBTable и её полей
3) Класс непосредственно соединения TDBConnectionBPL
Выглядит он следующим образом.
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 |
unit uDBConnectionBPL; //Здесь 3 класса, //1) класс параметров соединения, - TDBConnectionParams //Он нужен для показа параметров соединения в инспекторе //2)Класс таблицы TDBTable //3) класс непосредственно соединения TDBConnectionBPL //Функциональность класса параметров TDBConnectionParams соединения вызывается как поле //в классе самого соединения TDBConnectionBPL interface uses System.SysUtils, System.Classes,vcl.dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MySQLDef, FireDAC.VCLUI.Wait, FireDAC.Comp.UI, FireDAC.Phys.MySQL, Data.DB, FireDAC.Comp.Client; //------------------------Класс параметров соединения TDBConnectionParams-------------------------- type TDBConnectionParams=class(TComponent) private FMySQLDriverDir32:string; FDataBase:string; FUser_Name:string; FPassword:string; FServer:string; FPort:string; FCharacterSet:string; //Геттеры function GetMySQLDriverDir32:string; function GetDataBase:string; function GetUser_Name:string; function GetPassword:string; function GetServer:string; function GetPort:string; function GetCharacterSet:string; //Сеттеры procedure SetMySQLDriverDir32(Value:string); procedure SetDataBase(Value:string); procedure SetUser_Name(Value:string); procedure SetPassword(Value:string); procedure SetServer(Value:string); procedure SetPort(Value:string); procedure SetCharacterSet(Value:string); public Procedure Assign(Source:TPersistent); Constructor Create(AOwner:TComponent); override; published //Свойства property MySQLDriverDir32:string read GetMySQLDriverDir32 write SetMySQLDriverDir32; property DataBase:string read GetDataBase write SetDataBase; property User_Name:string read GetUser_Name write SetUser_Name; property Password:string read GetPassword write SetPassword; property Server:string read GetServer write SetServer; property Port:string read GetPort write SetPort; property CharacterSet:string read GetCharacterSet write SetCharacterSet; end; //---------------------------Класс таблицы для DBTreeView и 3 важных полей для DBTreeView type TDBTable=class(TComponent) private Fid:string; FidParent:string; Fname:string; FIndex:string; FIsChecked:string; FIsExpanded:string; //<< FLevel:string; //<< FIsFolder:string; FTableName:string; //Геттеры function GetTable:string; function GetId:string; function GetIdParent:string; function GetName:string; function GetIsFolder:string; function GetIsChecked:string; function GetIndex:string; function GetExpanded:string; function GetLevel:string; //Сеттеры procedure SetTable(Value:string); procedure SetId(Value:string); procedure SetIdParent(Value:string); procedure SetName(Value:string); procedure SetIsFolder(Value:string); procedure SetIsChecked(Value:string); procedure SetIndex(Value:string); procedure SetExpanded(Value:string); procedure SetLevel(Value:string); public constructor Create(AOwner:TComponent); override; procedure Assign(Source:TPersistent); published property TableName:string read GetTable write SetTable; property id:string read GetId write SetId; property idParent:string read GetIdParent write SetIdParent; property NodeName:string read GetName write SetName; property IsFolder:string read GetIsFolder write SetIsFolder; Property IsChecked:string read GetIsChecked write SetIsChecked; Property IndexField:string read GetIndex write SetIndex; Property IsExpanded:string read GetExpanded write SetExpanded; Property Level:string read GetLevel write SetLevel; end; //-----------------------Класс соединения TDBConnectionBPL----------------------------------- type TDBConnectionBPL = class(TDataModule) FDConnection: TFDConnection; FDPhysMySQLDriverLink: TFDPhysMySQLDriverLink; FDGUIxWaitCursor: TFDGUIxWaitCursor; procedure DataModuleCreate(Sender: TObject); private FDBConnectionParams:TDBConnectionParams; FDBTable:TDBTable; public property DBConnectionParams:TDBConnectionParams read FDBConnectionParams write FDBConnectionParams; property DBTable:TDBTable read FDBTable write FDBTable; procedure Connect; end; implementation uses UTreeView; {%CLASSGROUP 'Vcl.Controls.TControl'} {$R *.dfm} { TDBConnectionParams } constructor TDBConnectionParams.Create; begin inherited; //-----------------------------Убрать эту часть когда будет готов компонент------------------------ //Заполняет поля в ObjectInspector Self.Name:='ConnParams'; Self.SetDataBase('treeview_db'); //Self.SetDataBase(FDataBase); Self.SetPassword('masterkey'); SetUser_Name('root'); SetServer('localhost'); SetPort('3306'); SetCharacterSet('utf8'); end; //-------------------------ГЕТТЕРЫ, РЕАЛИЗАЦИЯ--------------------------- function TDBConnectionParams.GetCharacterSet: string; begin Result:=FCharacterSet; end; function TDBConnectionParams.GetDataBase: string; begin Result:=FDataBase; end; function TDBConnectionParams.GetMySQLDriverDir32: string; begin Result:=FMySQLDriverDir32; end; function TDBConnectionParams.GetPassword: string; begin Result:=FPassword; end; function TDBConnectionParams.GetPort: string; begin Result:=FPort; end; function TDBConnectionParams.GetServer: string; begin Result:=FServer; end; function TDBConnectionParams.GetUser_Name: string; begin Result:=FUser_Name; end; //------------------------СЕТТЕРЫ, РЕАЛИЗАЦИЯ----------------- procedure TDBConnectionParams.SetCharacterSet(Value: string); begin FCharacterSet:=Value; end; procedure TDBConnectionParams.SetDataBase(Value: string); begin FDataBase:=Value; end; procedure TDBConnectionParams.SetMySQLDriverDir32(Value: string); begin FMySQLDriverDir32:=trim(Value); end; procedure TDBConnectionParams.SetPassword(Value: string); begin FPassword:=trim(Value); end; procedure TDBConnectionParams.SetPort(Value: string); begin FPort:=trim(Value); end; procedure TDBConnectionParams.SetServer(Value: string); begin FServer:=trim(Value); end; procedure TDBConnectionParams.SetUser_Name(Value: string); begin FUser_Name:=trim(Value); end; //---------------------Реализация Assign------------------------- procedure TDBConnectionParams.Assign(Source: TPersistent); begin if Source is TDBConnectionParams then with Source As TDBConnectionParams do begin Self.MySQLDriverDir32:=MySQLDriverDir32; Self.DataBase:=DataBase; Self.User_Name:=User_Name; Self.Password:=Password; Self.Server:=Server; Self.Port:=Port; Self.CharacterSet:=CharacterSet; end; end; { TDBConnectionBPL } procedure TDBConnectionBPL.Connect; var oParams:Tstrings; s:string; begin if not Assigned(DBTreeViewGlobal) then exit; //if FDBConnectionParams.FMySQLDriverDir32<>'' then //FDPhysMySQLDriverLink.VendorLib:=FDBConnectionParams.FMySQLDriverDir32; //showmessage(FDPhysMySQLDriverLink.VendorLib); oParams := TStringList.Create; oParams.Add('DataBase='+FDBConnectionParams.DataBase); oParams.Add('Password='+FDBConnectionParams.Password); oParams.Add('User_Name='+FDBConnectionParams.User_Name); oParams.Add('Port='+FDBConnectionParams.Port); oParams.Add('Server='+FDBConnectionParams.Server); oParams.Add('CharacterSet='+FDBConnectionParams.CharacterSet); FDConnection.Params.Assign(oParams); FDConnection.DriverName:='MySQL'; try FDConnection.Connected:=true; except end; oParams.Free; end; procedure TDBConnectionBPL.DataModuleCreate(Sender: TObject); begin // Передача параметров соединения и таблицы из запущенной программы FDBConnectionParams:=TDBConnectionParams.Create(Self); Self.FDBConnectionParams.Assign(DBTreeViewGlobal.DBTreeViewConnParams); // <<<<< FDBTable:=TDBTable.Create(Self); Self.FDBTable.Assign(DBTreeViewGlobal.DBTreeViewTable); // <<<<< if Assigned(DBTreeViewGlobal) then Self.Connect; end; //-------------------------{ TDBTables } procedure TDBTable.Assign(Source: TPersistent); begin if Source is TDBTable then with Source as TDBTable do begin Self.TableName:=TableName; Self.id:=id; Self.idParent:=idParent; Self.NodeName:=NodeName; Self.IsFolder:=IsFolder; Self.IsChecked:=IsChecked; end; end; constructor TDBTable.Create; begin inherited; //---------------Временные значения для тестирования компонента Self.Name:='TableSettings'; Self.SetTable('tree'); Self.SetId('id'); Self.SetIdParent('idParent'); Self.SetIndex('Index'); Self.SetExpanded('IsExpanded'); Self.SetLevel('Level'); Self.SetName('Name'); Self.SetIsFolder('IsFolder'); Self.SetIsChecked('IsChecked'); end; //---------------Геттеры-------------------- function TDBTable.GetExpanded: string; begin Result:=FIsExpanded; end; function TDBTable.GetId: string; begin Result:=Fid; end; function TDBTable.GetIdParent: string; begin Result:=FIdParent; end; function TDBTable.GetIndex: string; begin Result:=FIndex; end; function TDBTable.GetIsChecked: string; begin Result:=FIsChecked; end; function TDBTable.GetIsFolder: string; begin Result:=FIsfolder; end; function TDBTable.GetLevel: string; begin Result:=FLevel; end; function TDBTable.GetName: string; begin Result:=FName; end; function TDBTable.GetTable: string; begin Result:=FTableName; end; //-------------------Сеттеры--------------------------- procedure TDBTable.SetId(Value: string); begin Fid:=trim(Value); end; procedure TDBTable.SetIdParent(Value: string); begin FIdParent:=trim(Value); end; procedure TDBTable.SetIndex(Value: string); begin FIndex:=trim(Value); end; procedure TDBTable.SetIsChecked(Value: string); begin FIsChecked:=trim(Value); end; procedure TDBTable.SetExpanded(Value: string); begin FIsExpanded:=trim(Value); end; procedure TDBTable.SetIsFolder(Value: string); begin FIsFolder:=trim(Value); end; procedure TDBTable.SetLevel(Value: string); begin FLevel:=trim(Value); end; procedure TDBTable.SetName(Value: string); begin FName:=trim(Value); end; procedure TDBTable.SetTable(Value: string); begin FTableName:=trim(Value); end; //------------------------------------------------- end. |