Jump to content

Alberto Miola

Members
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

3 Neutral

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. 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
  2. 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)
  3. 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
  4. 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
  5. Alberto Miola

    Hands-On Design Patterns with Delphi

    Very nice I am going to get this book for sure!
  6. 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
  7. 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;
  8. Alberto Miola

    MARS now supports Delphi 10.3 Rio :-)

    I have translated
  9. 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?
×