Jump to content

JohnLM

Members
  • Content Count

    353
  • Joined

  • Last visited

Community Reputation

27 Excellent

Technical Information

  • Delphi-Version
    Delphi 11 Alexandria

Recent Profile Visitors

23893 profile views
  1. Specs: Delphi XE7, VCL, Windows 7 So, while working in a new (isolated) project to figure out a better function() to use in one of my projects (SimpleBrowser), I stumbled upon a problem. And the subject says it all. I need to pull a custom function that I wrote from the SimpleBrowser project and work on it as a separate project. So, I select and copy it to the clipboard and then paste it into a new delphi project. The code snippet is pasted correctly in the IDE. However, when I selected and copied that code again from that new project and pasted it into notepad (because for every new function I create, I added to my "delphi code snippet" file) all the source code are on one line. If I follow that same process but copy from the original project, I get the same issues, all the source codes are on one line--there is no carriage returns, no formating, etc.. I tried to figure out why this is happening, and I can only assume that something unique was set in the IDE of this demo project, "SimpleBrowser" but I can't figure it out. This SimpleBrowser is a demo from the "CEF4Delphi" project. The folder is: "..\CEF4Delphi\WebView4Delphi\demos\Delphi_VCL\SimpleBrowser" Does anyone have any clues as to what is going on ?
  2. JohnLM

    Creating an app to play Youtube videos

    progress update. . . some videos via embed fail's to play. Unfortunately, I am unable to play certain embeded videos. I am finding a lot now and it is causing me a lot of grief. Does anyone know what is causing this and/or is this a known problem or maybe the channel is responsible? I don't know. I am just grasping at straws now. I really want this project to work.
  3. JohnLM

    Creating an app to play Youtube videos

    update on this endeavor. . . Hi All. Thanks for your ideas/suggestions. Sorry for the long delay. I had gone down a rabbit hole while trying to solve an initial idea to create a unique list of YT HASHes that turned a bit sour on me. What I wanted to do was, after receiving a YT URL link, I would parse out the HASH part (so I can store it in a list) and then later, rebuild it into a proper YT URL, thus, https://www.youtube.com/watch?v=+HASH at will, say for instance when I click on the [Go] button. The issue I wanted to catch was duplicate URL's, because I may have selected the same link elsewhere in the YT dashboard page. I will have to figure it out another time. Anyway. I may have a better idea for the combobox list--its funtional purpose and storage. I can auto-update the list, populating it by copying all the links that I am interested in while on the Youtube main dashboard page. Sort of like creating a personal tvguide list for today, for instance. And then when I'm ready, I start watching the videos. Thus.. A) Each time I right-click-select-to-clibpboard on a video link, my app will sinse the Windows message and detect that I have a CF_TEXT format and take that text (from the clipboard) and parse out the HASH and add that to the combobox list, and B) When I finish watching something, I can update the list to show that I watched the video by padding a "Y" in the list. And later, I can save that list into a master list somewhere, or a database. I have not decided yet. I am working on these ideas as I write this response. But I have working code snippets for both A and B that I worked out earlier. They work. I can receive notification that the clipboard has something (text) in it and snip the contents (the YT URL) and parse it. I just need to rework those code snippet(s) into this youtube player project. And of course, I welcome your thoughts. I will update on this projects progress soon.
  4. JohnLM

    Creating an app to play Youtube videos

    Actually, the screenshot in my previous post does show it :) But here is how I call the URL. What I do is grab a URL via rightclick+copy from youtube's main dashboard and parse it to change its format and feed that into the Navigate() command in the button's [Go] event: /// 1 function findStr(fStr, sStr: string): boolean; begin if pos(fStr,sStr,1)>0 then result:=true else result:=false; end; /// 1 - end /// 2 function findStrReplace(sStr: string; fStr: string; rpStr: string): string; begin if pos(fStr,sStr,1)>0 then result := StringReplace(sStr,fStr,rpStr,[rfReplaceAll, rfIgnoreCase]); end; /// 2 - end procedure TMainForm.GoBtnClick(Sender: TObject); var s: string; begin { change this https://www.youtube.com/watch?v=ZJhJILyS388 to this https://www.youtube.com/embed/ZJhJILyS388 } s:=addresscb.Text; addressCb.Text:=findStrReplace(s, 'watch?v=', 'embed/'); //# 2 WVBrowser1.Navigate(AddressCb.Text); end; I'm sure there are better ways to code it than how I did it but you get the idea. Also, I have to do something similar for the Dailymotion URL's, which a bit more complicated but doable. Then, I will have to include some more conditions to determine what kind of video am I serving, Youtube, Dailymotion, etc.. So the code above will have to change, eventually. At least now, I can watch videos in a small window (can size it too, obviously) and can make the apps window stay-on-top while I work or code on the laptop. Something I always wanted to do but didn't know how, until now. What I am thinking next, is how to add URL's to the combobox while the program is running. That idea is tricky to me as I've never done that and don't know how, yet. Then, every time I copy/paste/[Go], the URL is to be checked if in the combobox list, and if not, add it, and if it is already there, ignore it. Something like that, I guess. Anyway, I am already liking this app :)
  5. JohnLM

    Creating an app to play Youtube videos

    Success!! I was initially trying the built-in TWebBrowser, which failed. And then tried the recommended browser engine alternative for Windows 7 (under XE7) and it failed. But I believe it failed because I do not have that component, the WebView4Delphi (TWVBrowser and TWVWindowParent components) set up correctly and I was not getting a webpage or anything showing in the TWVWindorParent window. Then, I went to the demos folder and tried the SimpleBrowser and that worked, that is, it will show a browser window of anything, say for instance, www.google.com and so on, and all under Windows 7 on my laptop. I use my laptop with win7 as my main work station. I surf the internet and build applications and what-not's. And then after further searches, I found out how to play a Youtube video in a window using the WebView4Delphi browser component alternative (for win 7) without loading the whole youtube webpage. And that is through embeding, and the same for Dailymotion videos, though a bit different, both methods work perfectly. And now, all I need to do is add a few more features.
  6. Specs: Delphi XE7, VCL, Windows 7 -- youtube video URL's, to play videos only. I don't know why, but I am struggling with this one, how to create an app to just play youtube videos in. At first, I thought I should be using the TWebBrowser component. But then I thought maybe that is not a good idea because then the whole webpage will show, and that is not what I want. I only want to play video by its URL. Thus, only to show a video window. I have a list of youtube URL's (and also their thumbnail URL's) , so I will use a combobox or listbox control on my form. I would also like to play other website videos, like Vemeo, and Dailymotion, etc. Although I've played around with using the TWebBrowser, that was a fail--for obvious reasons. And i've also tried CEF4Delphi and WebView4Delphi and those two are also not working. So I am thinking I need some other component all-together. What (free) components do I need to accomplish this?
  7. 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 >>
  8. 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 !!
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. 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.
  15. 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?
×