Jump to content

Squall_FF8

Members
  • Content Count

    87
  • Joined

  • Last visited

Everything posted by Squall_FF8

  1. Hey guys, I have old MS SQL 2008 and a Query (FireDAC), that returns some fields in Date format. In a Delphi application all work great, it seems FireDac takes care to visualize Date to FormatSettings. However when I open a FastReport document, it seems it convert Date to a the PC local settings (different from my changes in FormatSettings). And that is not good, because on different machines, results could look differently. I wonder, is there a way, to force Dates in FastReport to be in my desired format regardless of the PC local? A possible solution, could be if I force the Query to return the desired format, I just wonder how?
  2. Hey guys, I have written a procedure in Delphi, but would like to port it to MS SQL. Unfortunately I'm new to MSSQL so If you have time to lift a hand, even with parts of it - that would be of great help!!! The structure: 3 tables - Contract - with contract info. It has Date_Sign, Date_Start, Date_Stop, MonthlyTax - Payment - keep records of paid taxes for each Month/Contract. It has DatePayment, Year, Month, Amount - Annex - keep track when the tax has been changed. It has Date and Amount I'm trying to create a procedure in MSSQL that takes ContractID and returns - Months - number of months without payment - Owes- sum of all taxes that hasn't been paid procedure TfmContractEdit.BuildChrono; var y, m, d: word; d1, d2: tDate; pay: Currency; // keeps track of what current tax that needs to be paid begin if deStart.Enabled then d1 := deStart.Date else d1 := deSign.Date; d1 := RecodeDay(d1, 1); if deStop.Enabled then d2 := deStop.Date else d2 := Date; d2 := RecodeDay(d2, 1); DM.Qry.Open(format(sql_GetAnnex, [ID])); // ID is ContractID DM.Qry2.Open(format(sql_GetPaymentTax, [ID])); pay := cuMonthTax.Value; // Current Contract tax var Sum: Currency := 0; var MonthDebt: integer := 0; while d1 < d2 do begin if (not DM.Qry.Eof) and (d1 >= DM.Qry.FieldByName('Date').AsDateTime) then begin pay := DM.Qry.FieldByName('Amount').AsCurrency; DM.Qry.Next; end; DecodeDate(d1, y, m, d); var v: variant := DM.Qry2.Lookup('Year;Month',VarArrayOf([y, m]), 'MonthlyTax'); if VarIsNull(v) then begin Sum := Sum + pay; inc(MonthDebt); end; d1 := IncMonth(d1); end; // Returns Sum, MonthDebt
  3. Squall_FF8

    Delphi procedure -> MS SQL stored procedure

    The hardest part for me is - how to do Next on SQL query inside procedure. Also is it possible to do Lookup, without re-running the same SQL statement each iteration
  4. Wow it worked! Thank you VERY MUCH, @weirdo12 !!!! I had never created variables in FR itself (just trough Delphi code). That is a very neat trick! Thank you for taking time for the screenshots and step by step how to do it!
  5. @weirdo12 Great example and practical illustration!!! May we adapt it, if the text is in RichView (instead of Memo) and it is more complicated, like: xxxxx [Ticket."ticket_date"] xxxxxx
  6. Good old Convert ... I'm wondering is there more convenient way - to set format per session, like in Oracle (you set some local settings only for "your" session). The reason is that I have tables with 20+ fields (at least 6 are in date format) and that will make huge Select statements.
  7. Squall_FF8

    Delphi Mystery: Edit vs Action

    Hey guys, I found the following mystery. Could you help me to solve it? A VCL application with Main form. On that form we have Edit and panel that different forms attach to it (one at a time, depending on a context). - The Edit has OnKeePress that handle, when Enter is used. - Attached forms have Action that has short-key: Enter. - 7 of Attached forms are Auto created (in the project). - 2 of Attached forms are created only once per use in run time. The mystery: What will happen if the Edit has a focus and I hit Enter? Whose handler will be triggered - Edit or attached window? Well at run time, if I have attached one of the 7 - Edit handler respond. If I have attached one of the 2 - their handler respond. So I guess my question is WHY? Why the difference between 7 and 2 windows? What is going on under the hood?
  8. Squall_FF8

    Delphi Mystery: Edit vs Action

    Hmm are you suggesting, that because Main is the owner of the 2 windows (and the Edit), the Actions have higher precedence? (and thus difference in behavior)
  9. Squall_FF8

    Delphi Mystery: Edit vs Action

    Yes, to both questions, The 2 are created on demand and reused after that (if/when needed)
  10. Squall_FF8

    Aggregates for TFDQuerry

    Hey guys, I wanted to do simple thing - use Aggregates. So following the help: procedure TForm.Button1Click(Sender: TObject); begin if Qry.Aggregates.Count = 0 then with Qry.Aggregates.Add do begin Expression := 'COUNT(Town)'; Active := True; Qry.AggregatesActive := true; end; end; Should be pretty simple, right? But I get error (on Activate := true): Do you know why? What I'm doing wrong?
  11. Squall_FF8

    Aggregates for TFDQuerry

    Thank you very much!!! Usually thigs like this have default name that is good enough (it works, the name = you dont use/dont care) Are you talking for Aggregates in general, or my example of use?
  12. Hey guys, I have a shared folder on the local net that I want to be able to Copy/Move/Delete files from it with a Delphi application. It works great when I share that folder with unlimited access. For security requirements I cant do that - I need to make it accessible only with user/pass Do you know how I can that?
  13. Squall_FF8

    RichEdit with MSSQL

    Hi guys, I have a TFDQuerry connected to MSSQL that returns a record with field Test - nvarchar(max). I would like to be able to Paste a text from Word in a RichEdit and be able to save it (formatted as RTF) in Test and latter on load it from there. How I can do that? (code snippet) P.S. If possible I try to use Insert/Update statements, but if I have to - I will use BLOBs. I just dont understand how blobs work in conjunction with normal Insert/Update.
  14. Squall_FF8

    RichEdit with MSSQL

    If I remember correctly, the whole concept/interface with Post, Edit, EoF, First, Next,... was created for BDE, but was so loved/easy to use by developers that its functionality was replicated in general and every new DBset specific for specific DB (DAC, FireDAC, I even had components for Postgre and Oracle implementing those). It doesn matter for the thread, but for general DB perspective, MSSQL as a spiritual successor of Access, comes natively packed with auto-inc. So you dont need triggers for that. Later versions added Sequence (I guess influenced by Oracle ). Even IBX adopted Sequence, which if used makes Generators a little obsolete.
  15. Squall_FF8

    RichEdit with MSSQL

    THANK you very much for that explanation!!! It clears my confusion. I assume that is the BDE way, but I missed that class (academic, not Delphi) 🙂 BTW what happens with the ID after Insert? Is it automatically received or you need to make sure that Insert statement have the right things (like 'OUTPUT INSERTED ID' in MS SQL)
  16. Squall_FF8

    RichEdit with MSSQL

    How I can do that for create (Insert)? My Query returns only 1 record, from Where clause (usually ID of a table). But if it is a new record ...? BTW Using Select to Insert/Update - that will never come to my mind 🙂 I understand that actual operations come from Edit/Append. Thank you!
  17. Squall_FF8

    RichEdit with MSSQL

    It will be interesting to peek in a snippet of it ^_^ How that works in conjunction with TQuery? I mean, when I call ExecSQL with Insert/Update, TDBRichEdit automatically provides the context for my BLOB field (no extra code)? Or I need to provide some code before/after ExecSQL?
  18. Squall_FF8

    RichEdit with MSSQL

    TBH, I dont know how to escape for MS SQL query. However as you said control codes are not needed for RTF standard, so I just made a routine that skips them. And all works fine now!!! BTW this might be interesting for you - Delphi and WordPad put exact same control codes. In my observation - 13, 10 after \par and 0 at the end. Good point - great suggestion! Thank you very much for taking time to write detail answers!!!
  19. Squall_FF8

    RichEdit with MSSQL

    Thank you @Tom Chamberlain for the code and comments!!! I'm sure it will be very helpful. Later today I will examine it very carefully.
  20. Squall_FF8

    Using FireDAC with Access accdb file

    Yes, I had similar problem. If you scroll down, you should find my post - I updated everything for future reference (as the case is now) In short the problem is from 32/64 mode. Windows come with mdb support only for 32. In 64 you can use mdb/accdb (because we usually install 64 versions of Access). And because Delphi is still 32 ... no design mode (unless you do something hacky (like '/passive /quiet') to have 32 drivers too. But I have to admit, that Delphi couldnt get all the blame. If you work with well supported DB (for example MS SQL) you get both 32/64 drivers.
  21. Squall_FF8

    RichEdit with MSSQL

    OK, I did: // To get RTF var Stream := tStringStream.Create; Rich.Lines.SaveToStream(Stream); Result := QuotedStr(Stream.DataString); // for Insert/Update, the text needs quotes However when I use the result in Query, I get error - it messes up the syntax of the SQL. So I inspected the returned DataString ... It seems it uses not just plain text, but control codes: 13, 10, 0. That creates 2 problems: 1. QuotedStr - formats it in Delphi way: 'text'#13#10'text'.... SQL doesn't like that! 2. #0 is considered end of a string (most of the times) and Delphi cuts what follows. Questions: - Since when RTF includes control codes (ASCII < 32)? If that is the case then things like `\par` are nonsense. - The RTF text states version 2.0. Do you know what version of RichEdit Delphi 12+ uses? Because of: "{\rtf1\ansi". I'm not familiar with "RTF using 8bit characters". Does Delpji / Windows RichEdit supports that? Do you know of a program that supports that?
  22. Squall_FF8

    Advise for building a document

    Hey guys, I'm trying to make a document in FastReport that will look like: * Contract Text - RichText with some data fields. text could be huge (more then a page!!!) * Small Table - TableObject with 2 columns for Contract Objects (max 4 lines) * Contract Text - same as above. I did that in FastReport like: * ReportTitle (logo + ...) * MasterData (band) - RichText - TableObject with event for Manual Build and code copied from Demo (how to make TableObject display DB) - RichText * PageFooter (for Page Numbers) And it didnt work: - The TableObject is not shown!. I suspect Manual build is not called. If I put it directly on Page1 it works. It works with other bands too, just MasterData - no. You would think - just remove MasterData, but: - Since RichText is huge, I can make it print on several pages only inside MasterData. Is there any other ways? Could you guys advise me? How you would implement such document? If it matters, my version is 2023.2.
  23. Squall_FF8

    Advise for building a document

    Not even a suggestion! Does that mean, that nobody is using FastReport?
  24. Hey guys, I have a table in MS SQL that holds in one column the file names of existing files in a local storage. When I show this table with TFDQuerry, I would like to add visually extra info - the file size. So what I did is to add extra calculated field Size. OnAfterOpen I get the file sizes in a Dictionary<ID, FileSize>, and OnCalcFields I simply fetch the file size from the Dictionary. The problem is - OnCalcFields is called before OnAfterOpen, actually the order by debugging is: Calc, AfterOpen, Calc. The result on screen is - some rows have Size 0 (no value in the Dictionary). After a scroll in the display Grid, all works fine. Could you help me resolve this? Or if you have a better way for a task like this?
×