Jump to content

Alberto Miola

  • Content Count

  • Joined

  • Last visited

Everything posted by Alberto Miola

  1. Alberto Miola

    New section for native apps

    I have been talking with Yaroslav Brovin recently (the creator of FGX native) and this project is going to be in public beta at the beginning of 2020. Would it be a good idea to make a section for it? If not now at least when the beta starts. FGX native will be an add on for the Delphi IDE This is a webinar unfortunately only in Russian; btw this will work for Android only at the beginning, iOS will come later. I attach some pictures of the documentation. More info on FGX are here: http://fire-monkey.ru/forum/370-native-fgx/ (use https://translate.yandex.com/ which is a good russian-english translator)
  2. Alberto Miola

    New section for native apps

    I used to work with FMX but I have dropped it in favor of Flutter. They are not comparable in terms of productivity and performance; it's like if you compare a Ferrari (Flutter) with a bibycle with deflated tyres (FMX). I really hope that FGX will give more visibility to Delphi in the mobile world!
  3. Alberto Miola

    Correct open SSL library

    I have a java back-end that is on https and this is the Delphi code: procedure TBaseHTTPRequest.DoRequest(OnCompleted: TCompletedHandler; OnError: TErrorHandler); begin TTask.Run( procedure var FIdHTTP: TIdHTTP; FIdSSL: TIdSSLIOHandlerSocketOpenSSL; exc: TObject; json: string; begin FIdHTTP := TIdHTTP.Create(nil); try FIdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); try try //1. Setup the IdHTTP object SetupConnection(FIdHTTP, FIdSSL); //2. JSON response from the server json := ExecuteRequest(FIdHTTP); //3. Synchronize with the main thread TThread.Synchronize(nil, procedure begin OnCompleted(json); FSelf := nil; end ); except on E: Exception do begin //Capure the exception object exc := AcquireExceptionObject; //Synchronize with the main thread TThread.Synchronize(nil, procedure begin OnError((exc as Exception).Message); FSelf := nil; end ); end; end; finally FIdSSL.Free; end; finally FIdHTTP.Free; end; end ); end; Indy is able to make POST requests because in this method I assing the SSL handler procedure TBaseHTTPRequest.SetupConnection(FIdHTTP: TIdHTTP; FIdSSL: TIdSSLIOHandlerSocketOpenSSL); begin with FIdHTTP do begin //API key needed to access the website Request.CustomHeaders.AddValue('ApiKey', API_KEY); //Set the Content-Type Request.CustomHeaders.AddValue('Content-Type', 'application/x-www-form-urlencoded'); //Connection timeout ReadTimeout := 2000; //SSL Handler IOHandler := FIdSSL; end; end; As you can see the the FIdSSL object is only created, I do not set any property (everything is default but I guess that it's correct, isn't it?). My project has the following files: mvm_gestionale.exe libeay32.dll ssleay32.dll Thanks to the DLLs I can connect to the https endpoint. I have downloaded the dll from https://indy.fulgan.com/SSL/ but actually I have picked a random one! I am using openssl-1.0.2t-i386-win32.zip but does it make any difference if I use any other zip? If so, do I have to change the code? They are openssl-1.0.2r, openssl-1.0.2s, openssl-1.0.2t but I'm not able to figure out if I'm doing things in the proper way
  4. Alberto Miola

    Delphi certification program 2019

    I've had to do 2 Java certifications with my company (here). I did not know about them but they are very useful in your CV and I've strenght my knowledges way more than before. Also now I can "prove" (for what is worth) that I have a good understanding of Java. I have seen that https://www.embarcaderoacademy.com/p/delphi-developer-certification-premium-package gives me the possibility to take an exam and get certified (like with Oracle/java). I have some questions for you in case you've already got it: From this doc I see the rules but the page to access the exam does not load. In fact http://certification.embarcadero.com/exam is broken; good start Is this still valid in 2019/2020? There are guides, exam preparation and video only for 2018 I guess that the exam is online, isn't it? I had to travel to Rome to do the java exam because Oracle did not allow me to do it from home. Ok my company has paid the course and most of the travel to Rome but if I had to pay everything by myself it would have been so expensive! What worries me the most is the quality of embarcadero's serivces because most of the resources I have been looking for aren't available due to server errors. Any feedback if appreciated
  5. I have a big project that has been well documented and illustrated with UML diagrams. How can I generate the HTML version of the documentation? In this page they say that I have two ways to do it: 2) Where is Generate in the model view page? 1) Where is the option in Tools menu? I have alread done what's written here: http://docwiki.embarcadero.com/RADStudio/Rio/en/XML_Documentation_for_Delphi_Code
  6. Alberto Miola

    Automatic documentation generation

    Ok so that's the issue. I have downloaded the project from git and opened it with my laptop in which I have installed 10.3 CE and that's why I cannot find it
  7. Alberto Miola

    Automatic documentation generation

    It seems that there's a program called GenDocCLI does the work but I cannot find it (http://docwiki.embarcadero.com/RADStudio/Rio/en/Running_Documentation_Generation_from_the_Command_Line)
  8. Alberto Miola

    Delphi 10.2 TNetHTTPClient vs TRestClient

    If you are using the latest version of the IDE you should also have the latest version (or one of the most recent). If you are going to handle HTTPS, check here! I have never tried TNetHTTPClient so I can't tell nothing about it
  9. Alberto Miola

    Delphi 10.2 TNetHTTPClient vs TRestClient

    I have stopped using Firemonkey in July 2018 (in favor of Flutter which is awesome 😉 ) so what I am going to say could be useless (bugs have been fixed, MAYBE) but these are the issues: There is not a clear way to handle errors with REST components (REST client / request / response) because sometimes they "randomly" raise exceptions When you try to run a non-blocking operation on the background there are so many issues that I cannot write an full list. I had asked a question some time ago for example (https://stackoverflow.com/questions/50437782/delphi-rest-async-request-detect-connection-failure) but no answers. Major problems are: cannot catch exceptions in async requests, connection timeout seems to be broken because it does not actually time out and when you set params for POST requests I cannot remember which problem I had (they were not properly passed due to encoding problems; it was not a problem of mine because with C# I was able to do everything flawlessy) If you try to use the 3 components with live bindings and data sets with the examples given online (or directly downloading the source code) you get N errors of M type I was able to do some stuff with TOAuth1Authenticator using workarounds because it did not work under certain circumstances My solution was the following: TIdHTTP. Indy is very reliable and it allowed me to create my REST service without any problem. I used to handle GET and POST requests with TIdHTTP inside a TTask.Run(); and then with some anonymous function I used to handle the async response. I had spent 3 hours on this which is nothing compared to the 2 days I had spent with REST components (trying to figure out what was wrong). This is my experience and, as I have already said, bugs may have been fixed. I am telling you the problems that I found so you can save your time or see if the components now work properly. If no, you can safely remove them from Delphi and a simple solution is TIdHTTP in a worker thread. Again, if it can be useful to you, I used to write by myself the REST connection handler with TIdHTTP and some good design patterns that helped me were the following: Template Method, Singleton and Decorator. There are many more that can be useful to you, check on Google!
  10. Alberto Miola

    is FGX native still around?

    Yes it is. You can contact Yaroslav Brovin (the owner) via Telegram, the open beta should come in this summer from what I got told
  11. Alberto Miola

    Indy - TIdMultiPartFormDataStream

    I usually use this kind of code: StringStream := TStringStream.Create(Params, TEncoding.UTF8); try Result := FIdHTTP.Post('http://abc.de/my/service/', StringStream); finally StringStream.Free; end; In the above code, I set this property for the FIdHTTP object: //Set the Content-Type FIdHTTP.Request.CustomHeaders.AddValue('Content-Type', 'application/x-www-form-urlencoded'); And here's how the variable Params looks like: Params := 'id=1&name=test'; Server-side, the values can be easily saved with this code: $id = $_POST["id"] //this is '1' $name = $_POST["name"] //this is 'test' Is there a better way? Yes, for sure. I don't know what's the best approach but this is the solution that I usually use to send POST requests via program. It works well
  12. Alberto Miola

    Efficient list box items with Frames

    I have to create a Delphi program and since it's going to run only under Windows, I'm going to use VCL instead of FMX. This is an example of a program that I have made using another library (it's called Qt, it uses C++). Check this picture: https://i.imgur.com/6owIISN.png I'd like to do something like this with VCL. Basically the picture shows that there is a black container and I can put inside it the green rectangle (some objects with an associated "view"). How can this be done with VCL? I have thought that I could create a Frame, put on it the 2 buttons and a label. But then how can I place the frames in the listbox? Do I have to switch to FMX? Thanks
  13. Alberto Miola

    Efficient list box items with Frames

    Ok after some googling I have tried this and it works, but it's under FMX and NOT VCL. procedure TForm2.FormCreate(Sender: TObject); var items: array[0..9] of TListBoxItem; i: integer; frame: TFrame1; begin Randomize; for i := 0 to 10 do begin items[i] := TListBoxItem.Create(Self); items[i].Selectable := false; items[i].Height := 100; frame := TFrame1.Create(Self); frame.Name := 'Test' + IntToStr(i); frame.Parent := items[i]; ListBox1.AddObject(items[i]); end; end; This works fine; I can fill the listbox with many items created as a frame. See the result: http://prntscr.com/ndtuhh Can I do the same with VCL? If no, I will use Firemonkey but I'd prefer using VCL because I think that FMX is pretty broken (I've had bad times with android and ios)
  14. Alberto Miola

    Delphi permutation code complexity

    Those loops are simply not valuable in big O terms because O(infinite) does not exist. f(N) = O(g(N)) if |K*g(n)| => f(n) for K constant and n > n0; this stuff means that the O(something) is a function f that stays below another function g starting from an n0 point. But f and g are both REAL functions and infinite is not in real (R* group) so that's not O(n) and O(infinite) gives the idea but that's mathematically wrong. I don't want to look boring with math things so a reference is here https://en.wikipedia.org/wiki/Big_O_notation and https://en.wikipedia.org/wiki/Taylor_series here (it explains better than me!! 🙂 ) Regarding the loop question, there is a correlation between the "result" of a loop operation and the complexity. It's not the result but it is a point (like 1 in this case) which determines the "starting point" of the asymptotic evaluation. I can't explain well in english this topic but if you have math skill you can understand looking at the definition of O(n) (where the similar applies to sigma(n) and theta(n): https://wikimedia.org/api/rest_v1/media/math/render/svg/847cbaaa1d74b521d199bebdb3b27612e631028b
  15. Alberto Miola

    Hands-On Design Patterns with Delphi

    Very nice I am going to get this book for sure!
  16. Alberto Miola

    Delphi permutation code complexity

    First 2 loops are O(log n) and O(log m). The last loop is clearly O(9) due to the bound but the O(9) is "asymptotically equal" to O(1). Overall you have O(log n + log m + 1) where 1 is constant so only n and m are involved. That complexity is O(log n + log m) but to be correct it would be O(log max{m, n}) where max gives you the biggest value between m or n. Do not say that for loops are O(n) by default, that would be a wrong assumption! Example here: https://stackoverflow.com/questions/10039098/why-is-this-function-loop-olog-n-and-not-on Look this example: var x: double; //x = 1000 maybe while (x > 1) do x := x * 0.3; You are executing this loop many times, let's say n, and so you are taking x * (0.3^n) and you want it to be bigger than something, in this case 1. Now you need to get n from that equation but n is an exponent so you can use logarithms to take the n down like: x * (0.3^n) = 1 -> log(0.3^n) = log(1/x) -> nlog(0.3) = log(1/x) and so on, at the end you'll get an asymptotic O(log n). This is probably not the place to demonstrate what I am saying but if you understand math topics like "limits" and "asymptotes" you can google for this and see that there are methods like substitution, master theorem or trees to get the O(something) notation
  17. I've always had the need to translate my apps in many languages and it's not something that's already integrated in the IDE. Or better, you can localize your VCL projects but there is no support for FMX (and thus, no support for Android/iOS). I have decided to create a component that works with VCL and FMX and can be used to localize your win/android/ios applications. Once the components has been installed in the IDE, it load a json file with all the various translations. This particular json will be created and maintained using the editor I've created. GitHub repo In the repo you can find a quick install guide, a simple tutorial and the source code. I have decided to use this approach because a .json file is easy to maintain and it's basically a text file so the file size is, in general, not a problem at all. Here's an usage example extracted from github: procedure TForm1.FormCreate(Sender: TObject); begin //The 'jsonResourceId' is the Identifier of the .json file that contains the //translated strings. It has to be loaded in the IDE as resource (RCDATA) Language1.setSource('jsonResourceId'); Language1.setLanguage('Default'); end; procedure TForm1.Button1Click(Sender: TObject); begin Language1.setLanguage('it'); //The caption is now 'casa' Label1.Caption := Language1.localize('home'); Language1.setLanguage('fr'); //The caption is now 'maison' Label1.Caption := Language1.localize('home'); end;
  18. Alberto Miola

    MARS now supports Delphi 10.3 Rio :-)

    I have translated
  19. Alberto Miola

    MARS now supports Delphi 10.3 Rio :-)

    Hiandrea, congratulations it's a very nice project! I didn't know about the existance of MARS, I am sure that I'm going to use it next year for a REST project that I have to do at work. I'd like to ask you: is there a component for this library? Or I simply have to import the .pas files?