Live bindings to Firebird table lazarus / 16-Databases ---------------------------------------------------------------------- Wargan · 2017-09-09 07:06 Hello, friends! I recently started getting to know Firebird 3.0.2. However, in the tools "out of the box", I did not find things that were extremely important to me, such as binding to table classes from the database. Here is my example: I use Virtual String Tree to display data from a database (this is a list of streets). To improve performance, I used records. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TStreet = record    Id: integer;    Name: string;  end; However, in the future, everything changed in my work Firebird database has a table called Streets with the following parameters: Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  Id INTEGER PRIMARY KEY Name VARCHAR (32) UNIQUE NOT NULL In the future, I still plan to create a separate class using the MVC pattern, like this template: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TStreetEx = class  private    FId: integer;    FName: string;    procedure SetId (AValue: integer);    procedure SetName (AValue: string);  public    property Id: integer read FId write SetId;    property Name: string read FName write SetName;  end; So, can I bind the fields of the Streets table to the fields of my TStreetEx? For them to be loaded automatically (for example, by binding to TSQLQuery), then they were changed through the program interface, and then saved. p.s. so I understand, to use several TStreetEx I need to create a separate class TStreetsList with the methods BeginUpdate and EndUpdate, and then shove them into the VST... ---------------------------------------------------------------------- mangakissa · 2017-09-09 07:58 Well, something like mORMot or tiOPF shall do the trick. MORMot use SQLite as internal database. I haven't read MVC pattern book yet, but you have to create a link by yourself. Filling the class is easy: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses fgl; TStreetEx = class  private    FId: integer;    FName: string;    procedure SetId (AValue: integer);    procedure SetName (AValue: string);  public    property Id: integer read FId write SetId;    property Name: string read FName write SetName;  end; TStreetlist = specialize Tobjectlist; TStreets = classprivate  fStreetlist : TStreetlist;public  constructor create;  destructor  Destroy; override;   procedure load;end; constructor TStreets.create;begin  fStreetlist := TStreetlist.create;end;  destructor Tstreets.destroy;begin  fStreetlist.free;end; procedure TStreets.load;var SQLQuery : TSQLQuery;    FStreetEx: TStreetEx; begin  SQLQuery := TSQLQuery.create(nil);  try    /* connect your table to SQLQuery */    while not SQLQuery.eof do    begin      FStreetEx      := TStreetEx.create;      FStreetEx.Id   := SQLQuery.fields[0].AsInteger;        FStreetEx.Name := SQLQuery.fields[1].AsString;      fStreetlist.Add(FStreetEx);      SQLQuery.next;    end;  finally    SQLQuery.free;  end;end; Delphi has his own livebindings and use the same method underwater. It's not perfect, but it answers your question. For generics: see http://wiki.freepascal.org/Generics ---------------------------------------------------------------------- Thaddy · 2017-09-09 13:21 Quote from: Wargan on September 09, 2017, 09:06:27 amHello, friends! I recently started getting to know Firebird 3.0.2. p.s. so I understand, to use several TStreetEx I need to create a separate class TStreetsList with the methods BeginUpdate and EndUpdate, and then shove them into the VST... You are using the wrong string type in your record. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TStreet = packed record    Id: integer;    Name: Array[0..31] of AnsiChar;  end; Maps to Code: MySQL  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  Id INTEGER PRIMARY KEY Name VARCHAR (32) UNIQUE NOT NULL Note if your database is created in UTF8 it needs to be array[0..127] of AnsiChar, four times the size! Subsequent conversions are otherwise easy. Reason is the database stores no string length inside the record, but in the table and field meta data, so you need to use an array of a suitable fixed length char type. (Ansi, UCS2, or UTF32). UTF8, UTF16 are variable length char types (from 1 to 4 bytes). Pascal strings always contain string length...The database does not. Note your record can have e.g. an added ToString function to do that. Advanced records... Does not matter for mapping or storage. ---------------------------------------------------------------------- Graeme · 2017-09-11 09:15 Take a look at tiOPF [http://tiopf.sourceforge.net], it does exactly what you need, and has been open source and continuously maintained and  developed since 1999. One the "tiopf_apps" repository, there is also a db mapping tool that will generate fully working tiOPF based units for you - from simple XML mapping information. This will save you tons of boiler-plate coding. tiOPF also include an implementation of MGM (Model-GUI-Mediator) which is very similar to MVC, except that it reused the events of modern GUI toolkits - no need to reinvent the wheel again - what MVC requires. You are welcome to visit the tiopf.support newsgroup for any additional questions. Simply follow the Support link on the website.