Jump to content

weirdo12

Members
  • Content Count

    156
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by weirdo12


  1. Try adding a variable. I included a bunch of screen shots because it's not exactly obvious that you have to create a new Category before you can create a variable.

     

    image.png.fe99d692ea8d17be46fd2a19796ca442.png

     

    Then add a Category:

     

    image.png.4035261ba36fa5328e71f5d144d0a121.png

     

    Select the Category and click Variable and assign it a value:

     

    image.thumb.png.2d3375cf71dd3a9024965cdd025bcbea.png

     

    Close Edit Variables. Now you *should* be able to drop that variable into the Rich Edit control.

     

    image.png.750cf6d9c6164b3d23b0029dbd5326ac.png

     

    image.png

    image.png


  2. 8 minutes ago, Squall_FF8 said:

    May we adapt it, if the text is in RichView (instead of Memo) and it is more complicated, like:

    
    xxxxx  [Ticket."ticket_date"]  xxxxxx

     

    If you double-click the RichView component is there a Format tab? If so, look in expressions and pick your date/time column and set the format string there. If the RichView contains multiple columns, each one will be listed in Expressions.

     

    image.thumb.png.dc5a8c13633357f1e0a1d0eb31f7d3ac.png 


  3. Add a BeforePrint handler to the memo control. Make sure that you clear the DataField and DataSet properties of the memo control or BeforePrint won't have any effect..

     

    procedure Memo13OnBeforePrint(Sender: TfrxComponent);
    begin
      TfrxMemoView(Sender).Text := FormatDateTime('yyyy-mm-dd', <Ticket."ticket_date">);                                                                            
    end;

     

    No formatting:

    image.png.e13788e7d43cf9937a112687c8429c20.png

     

    With the BeforePrint:

    image.png.1a91fea5d50cc0e4c432e576832f6e91.png

    • Like 1

  4. 4 hours ago, Brian Evans said:

    Had time to test it and using 32-bit client binaries from a newer PostgreSQL 32-bit ODBC driver version still works. 

    For sure. If there are 32-bit binaries from newer versions they will work. I will look into updating the ones I have been using too.


  5. 2 hours ago, unitsistemas said:

    I'm asking for help. When I try to compile a 32-bit executable, in my 32-bit Delphi as well, in my 64-bit operating system, Windows 10 Home Single Language, Version 22H2, an error appears about libpq.dll, saying that it was found, but not loaded. I use Postgres 15.3

     

    You need the PostgreSQL 32-bit library files and that means you should install PostgreSQL 10.23. You can still get it here:

     

    https://get.enterprisedb.com/postgresql/postgresql-10.23-1-windows.exe

     

    These are the files you will need to copy from C:\Program Files (x86)\PostgreSQL\10\bin to the same directory as your exe:

     

    libssl-1_1.dll
    libcrypto-1_1.dll
    libiconv-2.dll
    libintl-8.dll
    libpq.dll

     

    And you also need correct version of Microsoft Visual Studio 2013 (VC++ 12.0) C++ Redistributable run-time library. You can download it here:

     

    https://aka.ms/highdpimfc2013x86enu

    • Like 1

  6. If you use TFDScript you can use macros and and parameters. I tested this text and it works as expected. You end up with 2 rows in the table.

     

    DROP TABLE "&table_name" CASCADE;
    
    CREATE TABLE "&table_name"
    (
    serial_number serial,
    ticket_date timestamp NULL DEFAULT LOCALTIMESTAMP,
    PRIMARY KEY (serial_number)
    );
    
    BEGIN;
    INSERT INTO "&table_name" (serial_number, ticket_date) VALUES (1, CAST(:start_date AS TIMESTAMP));
    INSERT INTO "&table_name" (serial_number, ticket_date) VALUES (2, CAST(:start_date AS TIMESTAMP));
    END;
    
    BEGIN;
    INSERT INTO "&table_name" (serial_number, ticket_date) VALUES (3, CAST(:start_date AS TIMESTAMP));
    INSERT INTO "&table_name" (serial_number, ticket_date) VALUES (1, CAST(:start_date AS TIMESTAMP));
    END;

     

    The TFDScript.OnScriptError event is called when an attempt to INSERT serial_number 1 again and serial_number 3 does not exist in the table.

     

    [FireDAC][Phys][PG][libpq] ERROR: duplicate key value violates unique constraint "receipt_ticket_pkey".
    Key (serial_number)=(1) already exists.

    The TDScript.Status value at the completion of the TDScript.ExecuteAll is ssFinishedWithErrors.

     

    FDScript->ScriptOptions->CommandSeparator = ";";
    FDScript->SQLScripts->Clear();
    
    auto sql_script {FDScript->SQLScripts->Add()};
    
    sql_script->SQL->Assign(cxMemoSQL->Lines);
    
    if (FDScript->Macros->FindMacro("table_name") == nullptr)
    {
    	auto macro_ {FDScript->Macros->Add()};
    
    	macro_->Name = "table_name";
    }
    
    FDScript->Macros->MacroByName("table_name")->AsRaw = FFrameTicketDateFilter->TableName;
    
    if (FDScript->Params->FindParam("start_date") == nullptr) {
    	FDScript->Params->Add("start_date", ftString);
    }
    
    FDScript->Params->ParamByName("start_date")->AsString = FFrameTicketDateFilter->StartDate();
    
    if (FDScript->Params->FindParam("end_date") == nullptr) {
    	FDScript->Params->Add("end_date", ftString);
    }
    
    FDScript->Params->ParamByName("end_date")->AsString = FFrameTicketDateFilter->EndDate();
    
    FDScript->ValidateAll();
    
    if (FDScript->Status == ssFinishSuccess)
    {
    #if defined(_CODESITE)
    	// Don't time how long it take to make the previous CodeSite calls.
    	_di_ICodeSiteTimer timer_ {CodeSite->Timer({}, TCodeSiteTimingFormat::tfMilliseconds, true, false)};
    #endif
    	FDScript->ExecuteAll();
    
    #if defined(_CODESITE)
    	timer_->Stop();
    #endif
    	if (FDScript->Status == ssFinishSuccess)
    	{
    		auto msg_ {"The SQL Source text executed successfully."};
    
    		cxMemoSQLText->Clear();
    		cxMemoSQLText->Lines->Add(msg_);
    		Dxmessagedialog::dxMessageDlg(msg_, mtInformation, TMsgDlgButtons() << mbOK, 0);
    	}
    }
    
    void __fastcall TFrameGridLoadSummary::FDScriptError(TObject *ASender, TObject *AInitiator,
    		  Exception *&AException)
    {
    	cxMemoSQLText->Clear();
    	cxMemoSQLText->Lines->Add(AException->Message);
    	Dxmessagedialog::dxMessageDlg(AException->Message, mtError, TMsgDlgButtons() << mbOK, 0);
    }
    //---------------------------------------------------------------------------

    image.thumb.png.6de66affcc25d6483f3a70cba196668b.png

     

    image.thumb.png.61c2aa9fd1c5a8f8143a725d0d4efad5.png

     

    Edit:

     

    I just wanted to add if I execute this code:

    BEGIN;
    INSERT INTO "&table_name" (serial_number) VALUES (3);
    INSERT INTO "&table_name" (serial_number) VALUES (1);
    END;

    Using TFDQuery instead of TFDScript I get exactly the same issue that was initially reported if immediately after I execute something like 'SELECT * FROM &table_name'.

     

    Quote

    [FireDAC][Phys][PG][libpq] ERROR: current transaction is aborted, commands ignored until end of transaction block

     


  7. Edit: I'm going check this again tomorrow but I am pretty sure I am actually running code like below in a TFDQuery 😉 

     

    You could use TFDScript. For example, you could put these commands in the script:

     

    BEGIN;

    INSERT INTO t1(id) VALUES ('1');

    INSERT INTO t1(id) VALUES ('2');

    -- to test it cause an error

    INSERT INTO t1(id) VALUES ('1');

    END;

     

    And the in the exception handler call ExecSQL("ROLLBACK');

     

     


  8. Like you, I used SQL Anywhere as the default for many, many years - starting when it was still known Watcom SQL and running on DOS.

     

    I switched to using SQLite as the default database that the product ships with because it provided the same kind of installation experience (along with maintaining SQL Anywhere support for existing customers).

     

    When a new multi-user server is required, I use PostgreSQL.


  9. 5 minutes ago, egnew said:

    When I release the application, libpq.dll will be in the executable directory.

    I found that the library files had to be in a sub-directory named lib but that may have changed since I originally started supporting PostgreSQL. I use 12.2 now and just put the files in Debug\lib and Release\lib out of habit.


  10. 7 hours ago, Anders Melander said:

    Having two list think they "own" the same object would be a very bad idea; The layers are already owned and managed by a layer collection.

    So just to extend the conversation as it pertains to the original code, there is no need to store TBitmapLayer* at all (except for convenience as a temporary so that it can be initialized as required). The best practice is to always access a layer through ImageBackground->Layers->Items. Would that be good advice or overkill?


  11. Another approach is to use std::vector<std::unique_ptr<TBitmapLayer>>  created by std::make_unique instead of using an array of raw TBitmapLayer pointers which can lead to memory unsafe code. When the std::vector is destroyed (goes out of scope) everything gets cleaned up.


  12. On 11/5/2024 at 5:51 AM, Fraser said:

    I am getting some compiling done now.  Is per file overrides set by right clicking on a project file and selecting edit local options?  I haven't looked at this before.

    Right click on the source file and choose Edit local options.

×