Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 09/27/21 in all areas

  1. 0x8000FFFF

    Why empty dynamic arrays = NIL?

    I'm quite happy that I don't need any string.IsNullOrEmpty all over the place in my Delphi code as opposed to C#.
  2. Fr0sT.Brutal

    Why empty dynamic arrays = NIL?

    Yes, just like TDateTime = Double... and just like SizeOf(Char) = 1 until a thunder stroke at 2009 🙂 For me, not relying on implementation details is just an additional layer of stability. In 2009 those who weren't assuming Char is almost the same as Byte, could adopt Unicode with almost no changes. Others were suffering. If sometimes TDateTime becomes a record with two numbers (f.ex., days from 1 Jan 0001 and msecs of day), those who write "secsBetween := (dt1 - dt2)*86400" will suffer. Me, using "secsBetween := SecondsBetween(dt1, dt2)" won't. I personally consider it bad style. This relies on impl details, and any new coder will have to keep in mind these nuances. "What, var is null here? Okay, I know that from my Java/SQL/JS background. Let's assign it with 0 length for now, to be expanded later. What could go wrong?" Moreover, sometimes you want to refactor. F.ex., array becomes insufficient and you change type to TList. Option #1, if using `Length(arr)`: change type, try to build, change all `Length(arr)` to `arr.Count` that compiler will complain on Option #2, if using `arr = nil`: SUFFER. P.S. Honestly I don't see why array literals took so long to add. Clause "if arr = []" would be pretty obvious and consistent to string type
  3. Self.Name will never work in this situation, since it has not been assigned a value yet while the constructor is still running. The Name property is assigned a value after the constructor exits, whether that be at design-time or run-time. The only way around that is to pass in the desired value as a parameter to the constructor (but that will obviously not work for objects created at desing-time), eg: constructor TConcrete.New(aValue: string; aName: string; aOwner: TComponent); begin inherited Create(aOwner); Self.Name := aName; // <-- fReadOnlyProperty := aValue + Self.ClassName +' ] '+ sLineBreak + 'Object Instance Name is: [' + aName +' ]'; end;
  4. I've updated that unit in SVN twice today so far, and was about to do it again, so you'll see your changes real soon. Not sure how long they will be useful for, SHA1 is long deprecated. Angus
  5. Stefan Glienke

    Why empty dynamic arrays = NIL?

    Fixed it for you: const EmptyArray = nil; var numbers: TArray<Integer>; begin if numbers <> EmptyArray then Writeln('not empty'); end.
  6. In case you don't need the name you can also assign it to an empty string. Unnamed components can coexist inside their owner.
  7. One thing about component names is that you f.x. cannot dynamically add multiple identical frames to a form at runtime unless you ensure a unique name by doing something like this: type TOurFrameBase = class(TFrame) constructor Create(const AOwner: TWinControl); reintroduce; end; constructor TOurFrameBase.Create(const AOwner: TWinControl); begin inherited Create(TComponent(AOwner)); FPanel := AOwner; Parent := AOwner; Align := alClient; Name := ClassName + '_' + Seed.Next.ToString; // Ensure that every frame created gets a unique name I.e. we ensure a unique name for the frame instance. (Seed is a singleton for the class that delivers a unique (incrementing) cardinal (per app life time)). If you don't do this - you will run into duplicate name errors.
  8. Well, I don't have a practical example at hand in the moment and some academic ones would be of no value. Nonetheless, I will try to think of some, but as always there will be other ways to achieve the same goal - whatever that will be.
  9. Out of curiosity (and lack of imagination this morning), what for might this mechanism be good for other than in the Designer ?
  10. When Delphi first came out, seeing how this worked was one of those O-M-G! moments! If you've never programmed the old Windows event loops using Microsoft's crappy old "object framework" based on C++ but not really using objects, it's really hard to appreciate what the inventors did that actually hid all of that garbage. I don't think any of us really learned any of that "complicated backstage" because ... honestly, who cares? What it did was SIMPLIFY THE HELL out of creating forms in MS Windows apps. Not even VB was that elegant at first, because you had to write VB components in C++ due to the Windows part of that "complicated backstage". Delphi let you write components in ... Delphi! In large part because a TComponent had certain magical properties that let you drop it on a form and refer to everything in it as if it was part of the form. It was really ingenious, and so intuitive that nobody really gave it much thought. So coming at it the way you are, from the "run-time first", it's not surprising that you're confused. If you're going to do it that way, then study how to write components. That may confuse you even more at first, but at least it will get you going down the right road. That said, your naiveté might lead you to figure out something that the rest of us are blind to because we've been working with this for so long. The biggest annoyance I have is when I want to derive something from a common component, like a TLabel and make a TmyLabel with additional fields and methods. But you can't then inject it into the form easily because the IDE needs all components to be registered and installed, not just declared. I think I've seen some ways of doing it, but they've never stuck in my memory. So while this mechanism was almost miraculous when it was first introduced, it does have its limitations.
  11. David Heffernan

    Why empty dynamic arrays = NIL?

    Not sure I agree. It can be useful to distinguish between null and length 0 array. It can be useful to have these as different conceptual things.
  12. Make the storage data path (TDataStoragePath) a singleton object that initializes itself with the path. All other units that need the path will have to use the unit where TDataStoragePath is defined hence will force TDataStoragePath to initialize first.
  13. Stefan Glienke

    Why empty dynamic arrays = NIL?

    Because a pointer to empty would be quite stupid. While you can technically build an allocated array with a capacity of zero with some hacking the RTL always cleans up the memory as soon as an arrays length becomes 0. Fun fact - checking against nil for the purpose of "is it empty or not" opposed to comparing Length to 0 is slightly faster: procedure test(const a: TBytes); begin if a <> nil then Writeln; if Length(a) > 0 then Writeln; end; CheckArray.dpr.12: begin 0041D57C 53 push ebx 0041D57D 8BD8 mov ebx,eax CheckArray.dpr.13: if a <> nil then 0041D57F 85DB test ebx,ebx 0041D581 740F jz $0041d592 CheckArray.dpr.14: Writeln; 0041D583 A1B4254200 mov eax,[$004225b4] 0041D588 E8CF7DFEFF call @WriteLn 0041D58D E8B270FEFF call @_IOTest CheckArray.dpr.15: if Length(a) > 0 then 0041D592 8BC3 mov eax,ebx 0041D594 85C0 test eax,eax 0041D596 7405 jz $0041d59d 0041D598 83E804 sub eax,$04 0041D59B 8B00 mov eax,[eax] 0041D59D 85C0 test eax,eax 0041D59F 7E0F jle $0041d5b0 CheckArray.dpr.16: Writeln; 0041D5A1 A1B4254200 mov eax,[$004225b4] 0041D5A6 E8B17DFEFF call @WriteLn 0041D5AB E89470FEFF call @_IOTest CheckArray.dpr.17: end; 0041D5B0 5B pop ebx 0041D5B1 C3 ret
  14. Joseph MItzen

    web scraping or web parsing for project?

    It sounds like you hate web scraping. Meanwhile I've developed a new love of web scraping.. it unlocks all sorts of amazing possibilities. Delphi's really not the best tool for the job, though. But if you use selenium to control a headless browser and deal with the javascript for you, beautfiulsoup to scrape a page, and perhaps scrapy if you need to do web crawling... things become a lot simpler. My brother has a preexisting medical condition that made him quite vulnerable during the COVID lockdown. Food stores were offering a service where you could order online and they would shop for you and have contactless pickup but there were only so many time slots during each day available and high demand. The first time my brother managed to get an order in he had to do so at a store an hour away! I wrote a program that used selenium to log into my brother's local grocery store website and navigate to the time reservation page and then passed the HTML post-javascript to beautifulsoup to extract the time table and parse it. If there were new openings it would then email my brother to let him know. This was quite a big help to him and saved him two-hour round trips. I've scraped my Amazon wish lists and then used beautifulsoup and requests to search the online lending library at archive.org to find books I was interested in that were available to read for free through archive.org. I used some web scraping to create a script that checks if a piece of open source software I use has a new version available, and if so to download, compile and install it in one go for me. I'm competing in an online horse race handicapping contest and another script takes the races for the contest and scrapes the race track's YouTube page to let me know when the video is up from the relevant races (YouTube is an ugly JSON-filled mess to scrape unfortunately). I've been on the lookout for more things to scrape too! It can only take a line of code or two unless the website takes drastic measures to avoid it (*cough* Equibase *cough*) but then just a few more lines of code to bounce your page requests through TOR while resetting the connection each time to get a new output node at a different spot in the world will take care of that.
  15. Bill Meyer

    Missing The Old Forums

    As many of us are likely to recall from the old forums, a key perspective here is that "developers don't understand marketing." In order to consider making changes, one must first be open to the possibility that the current state of affairs could be improved.
  16. vfbb

    Skia4Delphi

    We are very pleased to announce the 2.0 release of the Skia4Delphi project. The library was almost completely rewritten, bringing many new features such as visual components (VCL/FMX), easy installation, easy configuration, miscellaneous error handling, and much more. Now it also has many more features as well as more examples. See main changes: v2.0.0 Added support for Delphi 11 Added support for OSX ARM 64-bit Added Setup (friendly install) Added IDE plugin to enable the skia in your project: replacing manual changes in project settings, deployment and dlls that were needed before. Now it's automatic, just right click on your project inside the IDE then "Enable Skia" Built-in by default the "icudtl.dat" file in dll Added the controls TSkLottieAnimation, TSkPaintBox and TSkSvg Added SkParagraph (multiple styles in text) Added support for Telegram stickers (using TSkLottieAnimation) Added error handling in sensitive methods Added the source of our website: https://skia4delphi.org Library rewritted Improved the integration with apple's MetalKit Improved library usage, like replacing SkStream to TStream Fixed AccessViolation using TStream Fixed issue with transparent bitmap in Vcl sample Fixed minor issues Explained Svg limitations in documentation We are now using the latest inactive milestone release of Skia (M88), because the others are updated frequently. Deprecated non-windows platforms in Delphi 10.3 Rio or older Homepage: skia4delphi.org GitHub: https://github.com/viniciusfbb/skia4delphi A liittle preview Setup Just download the Skia4Delphi_2.0.0_Setup.exe attached in Releases page. Enabling your project Telegram sticker (tgs files): SkParagraph: WebP: kung_fu_panda.webp Format Size Png (100% quality) 512 KB Jpeg (80% quality) 65.1 KB WebP (80% quality) 51.6 KB Controls And much more...
  17. Joseph MItzen

    Missing The Old Forums

    I won't go into the whole story, but I once had an online exchange with David Intersimone, then VP of Developer Relations, about a survey he'd run and tried to explain to him how it was only going to tell him what he wanted to hear and not what he needed to know. Despite my being a professional data analyst at the time, it felt like he was trying to lecture me on how surveys worked. I tried to explain that when you survey the first 500 people to buy a new release, you're missing those who chose not to upgrade because of bugs, price or features, which were the three biggest complaints at the time (still are). Of course, it also missed those who had already opted to leave for another platform. That's when David gave me insight into the thought processes at Embarcadero and I knew there was no helping them... he wrote "People leave Delphi for C#; people leave C# for Delphi; so we just keep on doing what we're doing." In short, they're like a black box whose outputs are not influenced by the inputs. This survey asked questions like (approximately) "What's the most awesome thing you can think of about Delphi?" and nothing about what's your biggest problem with it. Answers to this question (from the biggest fans who were quickest to order the upgrade) were used within days by the marketing team in a press release and a blog entry, showing the survey was nothing more than quote mining for marketing. Marco Cantu tried to claim that they have lots of surveys - dozens, hundreds, thousands! - where they ask all the questions I suggested and more, although no one seems to have ever received an invitation to take one of these alleged surveys. In another instance a person talked about being a subject domain expert but no Delphi experience who was hired by a Delphi shop. They took him to... he called it a user group meeting, but it sounded like one of the old World Tour events. I'll skip over his general impressions, but he was unsettled by the small number and age of the participants. He brought this up after the meeting with the Embarcadero employee who was there and said that the employee responded to him: "We don't like for new people to show up at these meetings; they're filled with angry middle-aged white men". I've got a few more examples I won't go into, but I'll say I've seen and heard enough to be convinced that for the *majority* of Embarcadero employees, the concerns of customers aren't really high on their agenda (David Millington being a notable exception). When two of the people who actually develop Delphi showed up in the old forums one day and someone brought up a critical bug they were experiencing and not getting help with, one of them wrote: "See - this is why we don't like to come here." Tony de la Llama, who was in sales, showed up in the forums once and he was a nice, friendly guy. When someone told him about a problem they were having, he expressed personal sorrow over their experience and promised to escalate the issue personally so they'd get a fix. He said we were all swell people and he really enjoyed interacting with the users and planned on doing it again. Days later the EMBT CEO blamed Tony personally for low Delphi sales (I was told this by another EMBT employee) and fired him right before Christmas. 😞 So anyway, they did not have a history of listening to their customers, rarely showed up in the forum and when they did it often didn't go well. And the one person who really listened got fired. Hence I don't think it's that great a loss. (Again, I want to give David Millington credit for being one of the few EMBT employees to visit forums, including Reddit, and actually offer help to users with problems and listen to their suggestions and feedback. He's the only one I've seen do so since Mr. de la Llama.)
  18. Roger Cigol

    Missing The Old Forums

    Well I'm a C++ MVP and active C++ user and I check this forum from time to time. If I can I do make the odd (hopefully) helpful comment. I also check Stack Overflow for questions tagged C++ Builder. Stack Overflow is a good place to post if you have a specific question. Here is the best place I can find for somewhat more imprecise (but still civilised and helpful) discussions. I too miss the old Embarcadero forums. I pushed as hard as I could to get Embarcadero to keep them. They were getting lots of public viewable negative feedback about some of their releases. I feel they should have used this as a low cost way of learning what they needed to concentrate on improving. But it seems that rather than fixing the problems that were annoying their customers their marketing dept. insisted that they close the mechanism of reporting down. They do have good products and they do have a good marketing team - but they do need to make sure that they listen to their customers and respond effectively to what they are not doing well. By closing their forum they lost an opportunity to do this.....
  19. Daniel

    wuppdi Welcome Page for Delphi 11 Alexandria?

    Not being a MVP anymore, it is the first time in years that I do not have access to a recent version Delphi. But I will have a solution for you. Please give me a couple of days.
×