Jump to content

JohnLM

Members
  • Content Count

    347
  • Joined

  • Last visited

Community Reputation

27 Excellent

Technical Information

  • Delphi-Version
    Delphi 11 Alexandria

Recent Profile Visitors

23877 profile views
  1. JohnLM

    The Advent of Code 2024.

    Aoc2024Day11 Puzzle Part 1 Okay, so I have finally completed part 1 of this puzzle. As usual, I had a lot of issues to resolve. I believe it to be a working solve. I've added two additional columns, one for the line count, (to know what line you see) and the other is the stone counts. As you can see, the last line, 6, shows 22 stones, just as stated in the instructions. Since I don't use the console projects method, I used the TMemo for this. During the whole processing of this puzzle, I fed off the memo, almost recursive, in a way. So, as I obtained the stones from the lines property of the memo and processed it same, I updated to the next line to obtain the next set of stones, and so on. Anyway, I think it looks good and solved! << fig 1 - AoC2024Day11 >>
  2. JohnLM

    How do I synchronize two TMemo scrolling? [Solved]

    specs: Delphi XE7, VCL, Win7 laptop -- syncing two memo's scrolling via cursor keys and mouse -- Success #2 !! I was busy in another project these past few days. Uwe's first version works as requested. I did not think to add additional keys and mouse features at the time. Later, someone else asked for further features. Today, I tested the rest of the posted versions from Uwe, and the last one from Kryvich (his post from Monday 7:06am, page 1). Here is my list of what works successfully for scrolling inside the two memo's under Windows 7 using Kryvich's code snippet: * scrolling Up/Down, Left/Right via cursor keys * scrolling Up/Down via PageUp/Down keys * scrolling Up/Down via mouse wheel while clicked inside any of the memo's. * scrolling Up/Down/Left/Right via mouse click-and-dragging up/down on the verticle scrollbars * scrolling Left/Right via mouse click-and-dragging on the horizontal scrollbars In this scenario, the two memo's window or viewing size should be the same. One should not be larger in width, though it may not matter in some cases--I did try it by playing around with the Anchors and re-sizing one of the memo's at runtime. The scrolling will function accordingly, but at some point it will not because it runs out of scrolling space, which makes sense. So, keeping the window size the same for the memo's is beneficial for this feature. What does not work is scrolling Left/Right via mouse wheel via "rolling" the wheel. As far as I can tell, this was not asked about. But this feature is something I used in the good old days of the Opera browser, some 15 or 20 years ago, and then one day they took it out for good. You would press the Ctrl key while spinning the mouse wheel Up/Down in order to go left or right in the browser window. I miss this feature in a browser. The TMemo does not have this feature. But it would sure be nice if it did. The user would move the mouse pointer over the main thick scrollbar (the one inside, between the Left/Right scrollbars) and press and hold the Ctrl key and spin the mouse wheel to scroll left and right in the memo. Actually, if memory serves me, as long as I was in the document section or browser window with the mouse point, I could press and hold down the Ctrl and spinning the mouse wheel. I don't think it had to be on the scrollbar, or maybe it changed and you didn't have to be on the scrollbar anymore. And then they removed that whole feature. My thanks to both Uwe and Kryvich for providing the solutions to this aged old wish, going back to the early 2000's for me. Anyway. I am greatfull !!
  3. JohnLM

    How do I synchronize two TMemo scrolling? [Solved]

    update on the sync'ed scrolling of both memos via the cursor UP and DOWN keys when inside a memo. . . using the code from the link I posted earlier, I have the following working to scroll the memo's during cursor up/down inside a memo. I am calling the methods from memo1 only, not added to memo2 for this test demo. To make things a little convenient, below is a short demo project. 1. add two memos controls to a form. (I called mine m1 and m1 to reduce typing). 2. add two statictext controls. (again, I called mine st1 and st2) - I was using them to help me debug where I was at in the memo via the memo.caret.Y position. 3. fill both memos with some text. I added the following in both memos to make things easier, below. 1 line 1 2 line 2 3 line 3 4 line 4 5 line 5 6 line 6 7 line 7 8 line 8 9 line 9 10 line 10 11 line 11 12 line 12 The source code so far. . . unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; m1: TMemo; m2: TMemo; Splitter1: TSplitter; st1: TStaticText; st2: TStaticText; procedure m1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function GetVisibleLineCount(Memo: TMemo): Integer; var DC: HDC; SaveFont: HFONT; TextMetric: TTextMetric; EditRect: TRect; begin DC := GetDC(0); SaveFont := SelectObject(DC, Memo.Font.Handle); GetTextMetrics(DC, TextMetric); SelectObject(DC, SaveFont); ReleaseDC(0, DC); Memo.Perform(EM_GETRECT, 0, LPARAM(@EditRect)); Result := (EditRect.Bottom - EditRect.Top) div TextMetric.tmHeight; form1.st1.Caption := result.ToString(); end; procedure TForm1.m1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); var LineCount, TopLine: Integer; begin // sec 1 if key=vk_down then begin st2.Caption := m1.CaretPos.Y.ToString(); LineCount := M1.Perform(EM_GETLINECOUNT, 0, 0) - 1; TopLine := M1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0); if (m1.CaretPos.Y+topline >= GetVisibleLineCount(M1)) then begin SendMessage(M2.Handle, EM_LINESCROLL, 0, 1); end; end; // sec 2 if key=vk_up then begin st2.Caption := m1.CaretPos.Y.ToString(); LineCount := M1.Perform(EM_GETLINECOUNT, 0, 0) - 1; TopLine := M1.Perform(EM_GETFIRSTVISIBLELINE, 0, 0); if (m1.CaretPos.Y <= GetVisibleLineCount(M1)) then begin SendMessage(M2.Handle, EM_LINESCROLL, 0, -1); end; end; end; end. When you run it, and cursor down, when you are on line 8, and cursor down, the second memo will scroll. But, when cursor'ing up, its buggy. I can't seem to figure how to sync the two as yet in { // sec 2 } its just eluding me at the moment, and its late and I'm in a rush to get ready for work. Note, it is not as fluidly smooth/quick as the part that Uwe had posted earlier, but it should get the job done once the bug(s) are resolved. I gave it a shot, but perhaps someone else reading this can figure it out or something else better. visual screenshot demo from design mode, below.
  4. JohnLM

    How do I synchronize two TMemo scrolling? [Solved]

    I felt I better try to explain my idea, regarding being inside the memo and cursoring up or down and cusing both memos to scroll in sync: When you are inside the memo and, say, cursor keying down, you want to find the last line that is with-in the memo's window region. So say you have 30 lines of text in the main memo (the left pane) and your window's dimentional region is showing 5 lines of text: (mind you, both memo's have the exact text) 1 2 3 ========================================= 4 this is line 4, I am 4 lines into this memo of 30 total lines. 5 and line 5, okay getting somewhere 6 line 6, getting closer 7 line 7, almost there 8 line 8, I'm here, at the end section of the region, now i want to see lines 9 and onward in this memo and cause the other memo to scroll in sync. ========================================= 9 10 . . 30 end of memo document. You don't want the cursor down key to cause a (down) scrolling to occur while inside that window between line 4 and 7 as you are cursor down'ing, but when you are at line 8 and you press the cursor down key, then you want the scrolling(s) to occur in sync. And the same goes for when you are cursoring up, to not (up) scrolling in sync until you are at 4 and want to scroll into line 3 and so on until you hit line 1 and no scrolling should occur.
  5. JohnLM

    How do I synchronize two TMemo scrolling? [Solved]

    Okay, I found the link. It is to calculate the memo's lines, or I believe it to be part of what I was searching for. Its old, from 2013 but still useful, I believe. https://stackoverflow.com/questions/17707689/delphi-scrolling-memo see Sertac Akyuz's response where he posted some code, the first part. He explains it better than I what is needed. As for step 3, so far, I have not found a way.
  6. JohnLM

    How do I synchronize two TMemo scrolling? [Solved]

    Unfortunately, no. As it turns out, I do need to cursor-Up/Down when inside any of the memos. I have been searching all around to figure this one out, but to no avail. However, I have one clue that should work that (I believe) is required to make the scrolling up/down part to work: 1. when inside the memo cursoring up/down, calculate the inside of the memo window, the top or bottom (depending on your cursor/caret position) 2. use that to set the scrolling position (for both memos) 3. then, find the scrollbar up/down chicklet and tap it. That should trigger the scrolling up/down. I'm sure of it. But I can't figure out how to calculate the inside memo area, and I can't figure out how to find the scrollbar of the current memo that I am in to move the mouse pointer to it to tap it. I'm sure there is more than one way to accomplish this, but the above is my non-advanced way. But I have at least one clue, LoL. I found this code a few days ago. I just been busy and out of energy in this endeavor to continue it yet. Once I find that link in one of my browsers, I will post it. Maybe you can continue that part in step 1 for me, and maybe step 3 if you know that already.
  7. JohnLM

    The Advent of Code 2024.

    AoC2024/D11 I got an impulse to tackle day 11's puzzle and took a break from the other ones I was doing work in. I recall reading this puzzle multiple times and said to myself, "no way.. can't do this one, can't understand it.." But today, I was able to work it out in steps using Excel to help visualize it, not that I needed Excel, but at first, I thought I would need it. Anyway. I believe I can do at least part 1. So that will keep me busy and give me something to look forward to when at work. The first thing that came to mind for part 1 was a recusive function. I'm pretty sure that's how it should be coded, but, well, since I can't wrap my head around recursive function anything, I'm afraid I will pass on that aspect and go another route. Some day I will learn how to do recursive function anything. I hope to post something for D11 puzzle soon. Let me see how fast I can code something up.
  8. JohnLM

    How do I synchronize two TMemo scrolling? [Solved]

    I am marking this as Solved !! I can't tell you how many, many months I spent searching on/off these last two years and probably further back, for this solution! And I'm sure there are others out there in this boat. Thank you Uwe, for this code snippet! It works well. Even the PageDn/PageUp keys scync as well. And yes, the data in the two memo's will not change. I am reading large data comparisons, and puzzles that I bump/parse/etc.. And not having to add line numbers (if I don't have to, in order to sync what I am reading) is a plus, thus one less step to do.
  9. Specs: delphi xe7, vcl, win7 - TMemo components I've been searching to no avail on this topic. I can't find any example source code showing how to synchronize two memo's scrolling, via keyboard, mouse, and scrollbars. I see there are a few for TListBox examples but not for TMemo. I also tried one example (it was for tlistbox) and everything compiles except that TMemo does not have a .TopIndex so that source code does not compile up to that point. (link below). link to that resource -> https://stackoverflow.com/questions/24195857/synchronize-scrollbars-of-two-listboxes. source from stackexchange: To set the top line of a list box you use TopIndex. You can create a TListbox descendent that handles the WM_VSCROLL (and WM_HSCROLL if you want). You can then hook into this and update the second list box. Here is an example of this. I am only doing the hook one way so scrolling listbox2 won't scroll listbox1. You will need to add this TListBox override to your unit before the form declaration: TListBox = class(Vcl.StdCtrls.TListBox) private FOnScroll: TNotifyEvent; protected procedure ListBoxScroll(var Message: TMessage); message WM_VSCROLL; public property OnScroll: TNotifyEvent read FOnScroll write FOnScroll; end; This adds a OnScroll event to the listbox. The implementation for this class: procedure TListBox.ListBoxScroll(var Message: TMessage); begin inherited; if Assigned(FOnScroll) then FOnScroll(Self); end; You can then hook up the event in code: procedure TMyForm.FormCreate(Sender: TObject); begin listbox1.OnScroll := DoScrollListBox1; end; The code for DoScrollListBox1 is very simple: procedure TMyForm.DoScrollListBox1(Sender: TObject); begin listbox2.TopIndex := listbox1.TopIndex; end; This handles the scrolling by using the scroll bar. You will also need to add the following line to your OnClick of the listbox so keyboard actions will also trigger the scrolling. procedure TMyForm.ListBox1Click(Sender: TObject); begin ... listbox2.TopIndex := listbox1.TopIndex; ... end; My modified version of the above code: unit Unit1; interface TForm1 = class(TForm) memo1: TMemo; memo2: TMemo; procedure memo1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; implementation {$R *.dfm} procedure TMemo.MemoScroll(var Message: TMessage); begin inherited; if Assigned(FOnScroll) then FOnScroll(Self); end; procedure TForm1.FormCreate(Sender: TObject); begin memo1.OnScroll := DoScrollMemo; end; procedure tform1.DoScrollMemo(Sender: TObject); begin memo2.TopIndex := memo1.TopIndex; end; // This handles the scrolling by using the scroll bar. You will also need to // add the following line to your OnClick of the listbox so keyboard actions // will also trigger the scrolling. procedure tform1.memo1Click(Sender: TObject); begin //... //memo2.TopIndex := memo1.TopIndex; // <--- Does not compile at this point because there is no .TopIndex in TMemo. I learned this all to late. //... end; Does anyone have source code for synchronizing two TMemo's?
  10. JohnLM

    The Advent of Code 2024.

    Yes, I'm prob suffering from a similar (out-of-bounds) issue. When I get close to the edge of the matrix in a larger data array, I have these issues when the processing nears the 3-chars or less. I'm sure I will figure it out. Doing these puzzles has become a new side-hobby for me, and it does help me to keep my mind off of stress and other personal life issues I have going on.
  11. JohnLM

    The Advent of Code 2024.

    I discovered a bug or two after increasing the size of the sample text, and am now trying to fix it.
  12. JohnLM

    The Advent of Code 2024.

    Progress Update. . . AoC 2024 Day 04 Okay. I've got the two custom-made functions working successfully. MidStrDiagLF(GridArray,R,C,Len) and MidStrDiagRT(GridArray,R,C,Len) Both functions work by processing the grid array from top [1,1], from left to right, 1, 2, 3, ... 10, and downward, 1, 2, 3, ... 10, each function. And, creating a running list by capturing the x,y locations and the matches for both "XMAS" and "SAMX". << fig.2.aoc2024day04 >>
  13. JohnLM

    The Advent of Code 2024.

    AoC 2024 Day 04 Part 1 MMMSXXMASM MSAMXMSMSA AMXSXMAAMM MSAMASMSMX XMASAMXAMM XXAMMXXAMA SMSMSASXSS SAXAMASAAA MAMMMXMMMM MXMXAXMASX I've actually started that puzzle a few months ago and played with it a little, here and there, whenever I'd get bored with one puzzle or another or other projects. And at that time I recall thinking about this using a [x,y] matrix. But as I have hinted in various posts here (and probably elsewhere on this forum), I utilize the TMemo as a matrix or grid when trying to visualize some quickly because it is easier to set up quickly. I just set the font to "Consolas" and maybe give size=12 or 16. Then, I will convert it to a two-dim array. If only there was a way to modify the TMemo to draw an outline (like a TStringGrid) of square borders after every "char" typed. That would greatly help to visualize. So I use TMemo because I can quickly copy/paste something into it and get a visual in my head what I might or can do next. So, for the last couple of days, I've been working on an idea. The idea was to run a list of all the combinations of 4-char words. I am not knowledged of all the built-in string functions, nor string techniques, so I created from scratch what I could. I use the built-in MidStr() as a custom-made function I wrote, MidStrDn() to extract the 4-char words in this grid, from top-downward. In these processes, and also check for the Reveresed as well, thus, "SAMX". In all directions: Horizontal and Vertical. But this is incomplete because I also need to search and extract Diaginaly: left and right. I've had that in my head for some time but not done any work on it since. But these past days as I was working on the H/V parts, I am now working on the Diag part today. I already have it worked out, I just need to write the code and test it. Then, I will be able to pull all the 4-char words, and their [x,y] locations, and go from there. Note, I already have all the locations of the XMAS and SAMX locations in that grid. Eventually, I'd like to show it here in some visual form. <<fig.1.aoc2024day04>>
  14. JohnLM

    12.3 or 13/14 as next?

    A feature request I would love to see happen is the ability to add a comment to the Open Recent section on the welcome page. And a create/modify date. I would like to be able to add/change a comment for each of the entries so that I know more details about a project I may have forgotten about. Every time I open a project in XE7, I just keep wishing there was such a feature. And let it be customizable in options or something, like you can do in Explorer where you right-click the labels bar and a drop-down of selections appear to customize the viewing layout.
  15. JohnLM

    12.3 or 13/14 as next?

    I like the IDE the way it is. I hope they did not change it to something completely different. For example, I like the way you can scroll via cursor up/down keys and not have the caret pinned to the end of the line.
×