Jump to content

Serge_G

Members
  • Content Count

    311
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Serge_G


  1. It's been a long time since I've looked into livebindings, outside database links and even, less in VCL being much more FMX 🙄

    So, this question caught my attention.

    My first idea "its a VCL fact", but, writing the same sample in FMX, I got the same point 3 behaviour.

    My second clue was to notify BindingList a change, in memory my firsts steps with livebindings 

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    Checkbox1.Checked:=not Checkbox1.Checked;
    BindingsList1.Notify(Checkbox1,'checked');
    end;

    But, unsuccessfully. My guess, checkbox state is changed after the drawing ?

    For that sort of, unusual, thing I used a one record ProtypeBindSource component with a boolean field

    image.thumb.png.286c633241c2ba5b4d449ffe3de73573.png

     

    And this code
     

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    PrototypeBindSource1.DataGenerator.Fields.Items[0].SetTValue(not checkbox1.Checked);
    end;

     

    Project22.zip


  2. MyDac can use macro https://docs.devart.com/mydac/work_macros.htm

    Something like this code (sorry, I don't use Mydac but Firedac)

    Query1.SQL.Text := 'SELECT * FROM user Where ID IN (&list)';
    Query1.MacroByName('list').asString := '1,2,3';
    Query1.Open;

     

    Otherwise, you can use a format string

    sqlstring:='SELECT * FROM users WHERE id IN (%s)';
    inlist := '1,2,3'
    query.sql.text:=Format(sqlstring,[inlist]);

    Ok, it's really a very poor code !

    • Like 1

  3. 20 hours ago, GrumpyNoMore said:

    ...and by the way @Serge_G thanks for taking the trouble to respond over the Christmas holiday period. You are a champion!

     

    A retired champion for now :classic_wink: so I have time.
    I don't remember if I install ZEOS on my D11 version, but I always use SVN  (http://svn.code.sf.net/p/zeoslib/code-0/trunk) version of ZEOSDBO, perhaps this is why I don't mind this compatibility trouble 😄
    as you can see
    image.thumb.png.a34af0bbc2fd8fad13717ca53da2631a.png

    also ready for Delphi 12 Athenes :classic_smile:

     

    Best wishes for new year


  4. 11 hours ago, RDP1974 said:

    fmx seems a good technology for mobile platforms

    Not only I think, my last pro applications were written with fmx (even for windows) in mind Linux (not MacOS) distribution.

     

     

    Tutorials ? I don't think there is much.

    I wrote some French ones for Livebindings, TListview and building components you can find here, take a look at my blog too 😉

     

     

    My first steps with fmx were watching all videos I can found from Embarcadero events and others. I don't use all that getit template stuff but think there is something to dig there
    image.thumb.png.7e113a1441aa1924c1176f5bea9f2e23.png

    And remember there are a lot of samples in demo directory

     

    Fresh retired, my top ten to-do list is to finish my tutorial "writing fmx components  : RadioGroupBox" and beginning a book on FMX Styles 


  5. For each question (first one) I suggest you to indicate Delphi version.

     

     

    5 hours ago, Columbo said:

    I created a panel with 2 tabs. 

    use a TPageControl linked to a TImageList. You can change for each tab the imageindex property  (-1 to "hide" image)

    image.thumb.png.81e51668ce44c141d58a2e31b118cb9b.png

     

    If Delphi 11,  for the Font Color problems, with new versions you have to take care of StyleElements property, if you have set some appearance (style) to the project and don't remove seFont from the array then color you set at runtime should not be taken into account.
    Here, appearance is set to "Windows10 blue", button1.click  code 

    Label1.font.Color:=clred;

    is inefficient except if you set  Label1.StyleElements:=Label1.StyleElements-[seFont]

    image.thumb.png.aee6485fff90be02e13241e5c3bb4ec0.png

     


  6. 12 hours ago, Columbo said:

      'D:\Delphi_11_Community\MyProjects\Data\dat2.sqlite '.

    so, use this one not only dat2.sqlite.

    you can also use '..\..\Data\dat2.sqlite'

    (second  ..\   go up one level win32 first ..\ to project) 

    Quote

    If I go into the Win32 directory I have 2 files. FDtest_p.exe

    if you want to use only dat2.sqlite database have to be in this directory


  7. 12 hours ago, Columbo said:

    The path to the database is correct.  I even tried placing the dat2.sqlite file into the same folder as the program

    Are you sure of that? Program in debug mode is in a xxx\win32\debug directory where xxx is where are your project, unit and dfm path


  8. 'D:\Database=Delphi 11 Community\My Projects\FDTest\Data\dat2.sqlite'

    Problem is here. I don't think path is correct. First this = is somehow perturbing me, and those white spaces 🙄 don't help 

    image.png.6e87a9cf81b7b759e7ae9d99b72e5c5a.png

    I suspect you use part of the info here but, don't use 'Database' just the database file path 

     

     

    Then I am not sure your database is disconnected when you run  program (set option  ActiveStoredUsage to [] or only [auDesignTime]

     

    as @haentschman simplify your code, code can be only

    FDquery1.Open(query);

    or

    FDquery1.Open('Select * from DAT2'); 

    And last but not least, you will be confronted with a "locking" problem if you don't set connexion option LockingMode to Normal
     

     


  9. Did you consider using regular expressions ?

    uses system.regularexpressions;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var reg : TRegEx;
        r : String;
    const s = 'This is (string) which need to (remove)';
    begin
    reg:=TRegEx.Create('\([^()]*\)');
    r:=reg.Replace(s,'');
    showmessage(r);
    end;

     


  10. Hum, looking at your dfm, I saw you use DBX components (hate those 😄). I was wondering why till I click on the link !

    My suggestion still the same, use Firedac components 😉 

    As samples, you can find some clues in C:\Users\Public\Documents\Embarcadero\Studio\22.0\Samples\Object Pascal\Database\FireDAC\Samples\Getting Started\SQLite and more 

    Let me show you my version of your objective
    unit1.dfm and .pas

    object Form1: TForm1
      Left = 0
      Top = 0
      Width = 686
      Height = 501
      AutoScroll = True
      Caption = 'SQlite test'
      Color = clAqua
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -12
      Font.Name = 'Segoe UI'
      Font.Style = []
      OnCreate = FormCreate
      TextHeight = 15
      object DBGrid1: TDBGrid
        Left = 0
        Top = 0
        Width = 672
        Height = 177
        Align = alTop
        DataSource = DataSource1
        TabOrder = 0
        TitleFont.Charset = DEFAULT_CHARSET
        TitleFont.Color = clWindowText
        TitleFont.Height = -12
        TitleFont.Name = 'Segoe UI'
        TitleFont.Style = []
      end
      object DBNavigator1: TDBNavigator
        Left = 0
        Top = 177
        Width = 672
        Height = 25
        DataSource = DataSource1
        Align = alTop
        TabOrder = 1
        ExplicitTop = 183
      end
      object Button1: TButton
        Left = 120
        Top = 208
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 2
        OnClick = Button1Click
      end
      object Memo1: TMemo
        Left = 0
        Top = 237
        Width = 672
        Height = 229
        Align = alBottom
        Lines.Strings = (
          'This will be fed via Button1 click')
        ScrollBars = ssVertical
        TabOrder = 3
      end
      object FDConnection1: TFDConnection
        Params.Strings = (
          
            'Database=C:\Users\Public\Documents\Embarcadero\Studio\22.0\Sampl' +
            'es\Data\fddemo.sdb'
          'LockingMode=Normal'
          'DriverID=SQLite')
        ConnectedStoredUsage = []
        Connected = True
        LoginPrompt = False
        Left = 288
        Top = 16
      end
      object FDTable1: TFDTable
        IndexFieldNames = 'CategoryID'
        Connection = FDConnection1
        ResourceOptions.AssignedValues = [rvEscapeExpand]
        TableName = 'Categories'
        Left = 176
        Top = 32
      end
      object DataSource1: TDataSource
        DataSet = FDTable1
        Left = 376
        Top = 48
      end
    end
    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls,
      Vcl.DBCtrls, Vcl.Grids, Vcl.DBGrids,
      Vcl.StdCtrls, Data.DB, 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.SQLite,
      FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
      FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.VCLUI.Wait, FireDAC.Stan.Param,
      FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet,
      FireDAC.Comp.Client
      ;
    
    type
      TForm1 = class(TForm)
        FDConnection1: TFDConnection;
        DBGrid1: TDBGrid;
        DBNavigator1: TDBNavigator;
        Button1: TButton;
        Memo1: TMemo;
        FDTable1: TFDTable;
        DataSource1: TDataSource;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    
    uses StrUtils;
    
    procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
      S : String;
    begin
    fdtable1.First;
    memo1.Lines.Clear;
    while not Fdtable1.EOF do
     begin
       memo1.Lines.Add('knowing fieldnames and type');
       memo1.Lines.Add(Format('%s %s %s',[fdtable1.FieldByName('CategoryID').asString,
                                          fdtable1.FieldByName('CategoryName').asString,
                                          fdtable1.FieldByName('Description').asString]));
    
       memo1.Lines.Add('using fielddefs');
       S:='';
       for I := 0 to FdTable1.FieldDefs.Count - 1 do
         begin
           if FDtable1.Fields[i].DataType=ftBlob // not readable data
             then S:=S+' (GRAPHIC)'
             else S:=S+Ifthen(I>0,' ','')+ // no separator for for first field
                       FDtable1.Fields[i].asString;
         end;
       Memo1.Lines.Add(S);
       fdtable1.Next;
     end;
    fdtable1.First;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    fdtable1.Open();
    end;
    
    end.

    Note. Table used contains only a few records so it is acceptable to use this sort of code, with huge one a thread should be considered, but, for a beginner it's a big piece :classic_smile:


  11. One other way is to use a Query as datasource, then you can rename columns or set columns and so on

    i.e

    SELECT ...., KASE_EINSTELLUNGEN as DRAWBACK_CALCULATION, 0 AS PRINT_SMALLBONS .... FROM

    You said you use onNewRecord but, did you try onBeforePost ? (I don't check if this event is called)


  12. Agree @Stano Firebird SQL is a very good RDBMS, all my pro GPAO suite use it. SQLite has also some advantages for mono-station programs

    On 11/28/2023 at 4:58 PM, Columbo said:

    Since I posted this I have downloaded ZeosLib but any instructions that I have found about installing and using it seems to always refer to Firebird.  I want to use it for SQLite.

    ZeosLib can be used with many database system, not only firebird ones
     

    Quote

    The ZeosLib is a set of database components for MySQL, MariaDB, PostgreSQL, Interbase, Firebird, MS SQL Server, SAP Adaptive Server Enterprise and Adaptive Server Anywhere (previously Sybase), Oracle and SQLite for Delphi

    You have only to change Zconnection.protocol parameter to sqlite (or sqlite-3).

    If you find more doc ZEOSDBO+Firebird you can apply all (or at least a good part of) the doc to SQlite as well.

    Effectively when I wrote (never finished, but on the web) a (French) tutorial about ZEOS components my samples was Firebid ones also :classic_blush:


  13. Ah, the "synch" one ! I never search for this one.

     

    In my mind you need at least to declare in your code

     
        procedure ObserverToggle(const AObserver: IObserver; const Value: Boolean);
      protected
        function CanObserve(const ID: Integer): Boolean; override;  
    

    Then check a unit like FMX.Listview.pas (searching 'observer') 

     
     EditLinkID,  PositionLinkID and  IteratorLinkID (from System.Classes) seems to be the keys


  14. have a look at http://docwiki.embarcadero.com/RADStudio/Seattle/en/Tutorial:_Creating_LiveBindings-Enabled_Components
     

    in short, you need to declare these procedures and function in your component code

        procedure ObserverToggle(const AObserver: IObserver; const Value: Boolean);
      protected
        function CanObserve(const ID: Integer): Boolean; override;                  
        procedure ObserverAdded(const ID: Integer; const Observer: IObserver); override; 

    and do some register observable members
     

    If you read French, I wrote some tutorials (part I, part II)


  15. 9 hours ago, softtouch said:

    when I run the program, it only shows the normal checkboxes instead.

    Got same issue.
    As workaround, I force UseCustomGlyphs to true at runtime.
     

    procedure TForm1.FormCreate(Sender: TObject);
    begin
    for var ctrl in GetControls()
       do begin
         if ctrl is TRzCheckBox then TRZCheckBox(ctrl).UseCustomGlyphs:=true;
       end;
    end;

     

     


  16. 4 hours ago, Columbo said:

    I’m trying to learn Delphi 7 and at the moment I am trying to figure out how to access and retrieve data from a SQLite database. 

    Can I make two suggestions?
    First one, if you absolutely want to keep Delphi 7 use, try to install ZEOSLIB (aka  ZEOSDBO) and use this data access component suite instead of DBExpress

    Second, try Delphi 11 community, with his Firedac components,    


  17. Same thing for me !  I tried your sample, giving me a  326 value for a GMT one

    image.png.20a5359d18deaad5ade8fbd088a4f794.png

    Then I wrote this simple code

    procedure TForm1.FDQuery1MONCREATION_DATEGetText(Sender: TField;
      var Text: string; DisplayText: Boolean);
    begin
    text:=sender.asString;
    end;

    Giving me an "Incorrect argument for time encoding. " error  with my french version

×