Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 12/03/22 in all areas

  1. salvadordf

    Is there a component can help me automate web actions ?

    Try using a CEF4Delphi browser in off-screen rendering (OSR) mode. That mode allows you to simulate mouse, touch and keyboard events.
  2. Attila Kovacs

    form data store component ?

    It's for text only. I'd put binary in resources. Or you can extend the component to apply to your needs.. but in this case you have to replace tstringlists with streams and implement a Writer and a Reader for the dfm.
  3. Fred Ahrens

    DL a file from the web

    uses Vcl.ExtActns; procedure Download(URL: String; FileName: String); var DownloadAction: TDownloadUrl; begin DownloadAction := TDownloadUrl.Create(nil); DownloadAction.Filename:=FileName; DownloadAction.URL:=URL; DownloadAction.Execute; DownloadAction.Free; end; But no error handling at all.
  4. FPiette

    Is there a component can help me automate web actions ?

    You can embed TEdgeBrowser in your application and interact with it to automate web actions. You interact mostly by injecting JavaScript once a page is load.
  5. Attila Kovacs

    DL a file from the web

    https://chat.openai.com/chat "To download a file from HTTP in Delphi, you can use the TIdHTTP component from the Indy library. This component provides methods for sending HTTP requests and receiving HTTP responses, including the ability to download files from a URL. Here is an example of how you could use TIdHTTP to download a file in Delphi:" uses IdHTTP; var http: TIdHTTP; url: string; filename: string; stream: TMemoryStream; begin // Create the HTTP client object http := TIdHTTP.Create; // Specify the URL of the file you want to download url := 'http://www.example.com/myfile.txt'; // Specify the name of the file where you want to save the downloaded data filename := 'C:\myfile.txt'; // Create a memory stream to hold the downloaded data stream := TMemoryStream.Create; try // Use the HTTP client to download the file from the specified URL http.Get(url, stream); // Save the downloaded data to the specified file stream.SaveToFile(filename); finally // Clean up stream.Free; http.Free; end; end. "In this example, the TIdHTTP.Get method is used to download the file from the specified URL and save the data to the TMemoryStream object. Once the download is complete, the data is saved to the specified file using the TMemoryStream.SaveToFile method." 2nd run: uses IdHTTP; procedure DownloadFile(const URL, FileName: string); var HTTP: TIdHTTP; Stream: TFileStream; begin HTTP := TIdHTTP.Create(nil); try Stream := TFileStream.Create(FileName, fmCreate); try HTTP.Get(URL, Stream); finally Stream.Free; end; finally HTTP.Free; end; end; "download a file from http in delphi in the background": uses IdHTTP, Classes; type TDownloadThread = class(TThread) private FURL: string; FFileName: string; FHTTP: TIdHTTP; FStream: TFileStream; protected procedure Execute; override; public constructor Create(const URL, FileName: string); destructor Destroy; override; end; constructor TDownloadThread.Create(const URL, FileName: string); begin inherited Create(False); FURL := URL; FFileName := FileName; FHTTP := TIdHTTP.Create(nil); FStream := TFileStream.Create(FileName, fmCreate); end; destructor TDownloadThread.Destroy; begin FStream.Free; FHTTP.Free; inherited Destroy; end; procedure TDownloadThread.Execute; begin FHTTP.Get(FURL, FStream); end; procedure DownloadFile(const URL, FileName: string); var Thread: TDownloadThread; begin Thread := TDownloadThread.Create(URL, FileName); Thread.Start; end;
  6. No. First, not even considering threads yet, TApplication is simply not designed to run multiple instances at a time. There are globals that it uses internally which it assumes it has exclusive access to, and will not share well with other instances. Also, there is plenty of code inside of the VCL that assumes there is only 1 global TApplication object, and won't even consider the existence of other instances. Second, considering threads, the VCL is simply not thread-safe to begin with. It is not designed to be used in multiple threads at a time. VCL controls are expected to be used only in the main UI thread which runs the single global TApplication object. Also, the VCL runs on top of the Win32 API, and API window handles have an affinity to the thread that creates them, which restricts which threads are allowed to access them. And VCL controls simply don't react well when those window handles get messed up when accessed across thread boundaries. Don't do it. That is a very bad design choice. Handle all of your UI needs in the default main UI thread only. You can use multiple worker threads to handle your business logic however you want, and you can create a separate TForm to associate with each worker thread if that is what you need. Just make sure that any data you share across threads is adequately protected from concurrent access, and that you have worker threads synchronize with the main UI thread whenever they need to access the UI.
  7. Fr0sT.Brutal

    DL a file from the web

    CreateProcess ('curl.exe ' + URL) 🙂
  8. Attila Kovacs

    form data store component ?

    I made this component back in the days, drop it on a form/datamodule, you can add files by doubleclicking the component on the form or manually enter text by adding items. Use it like: "Storage['Title']" I have commented out some encryption stuff but you can implement it yourself if you need it. It can zip its content. (Install it by creating a new package and add the units to it) Public domain, no restrictions, have fun. forsix.StringListHelper.pas forsix.VCL.Storage.pas forsix.VCL.Storage.Design.pas
  9. Stefan Glienke

    ANN: Open Source Event Bus NX Horizon

    Spring4D Events are just multicast events (like your regular OnClick but with possibly multiple handlers) - an event bus is more.
  10. Dalija Prasnikar

    ANN: Open Source Event Bus NX Horizon

    Thanks! I will try to add some. I will need some time to prepare some meaningful examples that can show potential use cases. Event bus is a messaging system. Delphi already has basic event bus implementation in System.Messaging https://docwiki.embarcadero.com/CodeExamples/Alexandria/en/System.Messaging_(Delphi) You can also look at the examples there as those use cases apply to my event bus, too. Main difference is that System.Messaging is not thread-safe and you can only use it to send messages in the context of the main thread. If you want to send messages across multiple threads you need a thread-safe event bus, like NX Horizon. Because, it is thread-safe, it also has some additional features like dispatching events (messages) asynchronously in the background thread. Maybe the easies way to explain what is event bus is comparing it to a Button OnClick event handler. When user clicks a button code in the OnClick event handler will run. main difference (besides multithreading support) is that with button and its event handler there is usually deeper connection and there is direct link with the button and its event handler. For instance if you click Help button on some form, you would want to open Help window from its OnClick event handler. But in that case your form with button needs to know about help form. If you have many forms that need to open help form will create tight coupling between all those forms and help form. With event bus, you can declare TOpenHelp event type and then you can subscribe some code to such event type. In your forms with help buttons, you would still need OnClick event handler, but instead of directly opening help form from that OnClick event you can send a message to event bus that TOpenHelp event happened. And then subscribers to that event (there can be more than one) will receive it and run the appropriate code in associated subscription event handler. This way your forms don't need to know about your help form, and code handling your help form does not need to know from where TOpenHelp came from. Event type also serves two purposes. Its type tells that particular event happened, and its content (event can be any automatically managed or value type) is used to pass additional data. for instance if the TOpenHelp is integer type, you use it to store and pass help page number depending on which help button is clicked and then you can open help on particular help page. Another example would be downloading some files in the background thread and then sending TDownloadCompleted event from that thread with some data about particular download and then subscribers can handle and do whatever they need to do with that data. Process it further, show it to the user, or anything else.
×