Jump to content

Mike Torrettinni

Members
  • Content Count

    1509
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Mike Torrettinni

  1. Mike Torrettinni

    Compile code on the fly...?

    Yes, SQLite says it is using bytcode to run sql queries: https://www.sqlite.org/opcode.html
  2. Mike Torrettinni

    Compile code on the fly...?

    Very interesting! Thanks for detailed explanation and I agree, definitely above my current skill set, and I probably will never need this. Thank you, but that was very confusing to read, the whole page. I was never good in just theory, I need examples - well, in this case of topic I doubt example would help me, anyway. And if you look at the history of this wiki page, so many many corrections and additions over the years (800+ edits, 463+ editors since 2002), for a topic that mostly has 1 or 2 paragraphs per term, you can realize this was a long journey to create. How can this be for rookies like myself? 🙂
  3. Mike Torrettinni

    Accept delimited & return an object

    I use records like this and it's really easy to add more fields, because you simply add to the record definition. You just need to make sure you initialize result, Result := Default(TRecord), and all record fields are initialized no matter how many are defined. I define a class when parsing need more complex rules or goes beyond single function. Then you have all the flexibility of full class.
  4. Mike Torrettinni

    Reading fields with different lenghts

    Oh, good thinking! Well if it's binary then I guess he can ignore the suggestion. Right?
  5. Mike Torrettinni

    Reading fields with different lenghts

    I would use TStringList because it gives you plenty of features already implemented, like get value by index. I would do something like this: // Parse input string into TStringList procedure ParseInput(const aInput: string; var aData: TStringList); var i, vStartOfValue: integer; begin // loop aInput and add each value between [...] to aData for i := 1 to aInput.Length do begin if aInput[i] = cStart then vStartOfValue := i+1 else if aInput[i] = cEnd then begin aData.Add(Copy(aInput, vStartOfValue, i - vStartOfValue)); end; end; end; Then you can get field after 'STX' like this: // use GetValueAfter(Data, 'STX', 2) for 2nd field after 'STX' function GetValueAfter(aData: TStringList; const aAfter: string; aIndex: integer): string; begin Result := aData[aData.IndexOf(aAfter) + aIndex]; end; And here is example: procedure TForm2.Button1Click(Sender: TObject); var vData: TStringList; begin vData := TStringList.Create; try ParseInput('[STX][0x1C][Field1][0x1C][Field2][0x1C][Field3][Field4][0x1C][ETX][LRC]', vData); // Get 2nd field after 'STX' Memo2.Lines.Add(GetValueAfter(vData, 'STX', 2)); finally vData.Free; end; end;
  6. Maybe this will help someone deciding on trying to use Delphi in VM: I used Delphi 10.2.3 in VMware for a month and I just reinstalled it back on my local machine, it just didn't really work for me in VM. So, specification: Desktop: Intel I7 4790K (4c/8t), 32 GB Ram and all SSDs; Windows 10. VMWare Workstation Pro 15.1 installed on local PC - I researched quite a lot on how to improve experience with VM Settings: Memory: 12GB Processors: 4 (processors: 2, cores per processor: 2) VM file is on separate SSD. Fresh Windows 10 installed in VM (+all updates + all latest drivers) To make it run a fast as possible (or to limit resources used) I disabled all non-essential services, cleaned up startup programs, no antivirus or antimalware installed. Very few other tools, just 7z, WinRar... Delphi 10.2.3 + IDEFixPack + MMX + GExperts + CNPack Disabled Start page + disabled Live binding. One of the reasons why I tried Delphi in VM is to have simple backup and grab-and-go Delphi environment. So, at first it seemed to work well, full build time was a bit slower, but not too annoying - 50% longer than compile time on local. A bit slower IDE, slower switching between Form and code. For the testing of concept it was acceptable and luckily at that time I didn't have any real development time scheduled, just some minor bug fixes. But as soon as I started really working with it, all these little things became very annoying, in a matter of few hours: - delays in mouse right-click in code to use Toggle Breakpoints or Refactor (rename variable) - delay on selecting Form controls and Object inspector to populate properties and Structure view - opening menus - even ctrl+home/end on large unit (40K loc ) was delayed - and other little delays here and there The delay I'm talking about is very minor, probably less or close to 1s, but when you use IDE a lot these delays become very apparent and annoying. For me this was too much after a few hours of real work. To summarize, I think I optimized VM as much as I could to run as fast as possible; the computer is still powerful enough even though is not brand new high-end computer; I don't have huge projects, but they do have some 100Ks loc each. If I would install all the rest of the tools I use in my daily development environment and run them as I do on local computer (memory regularly gets used 20GB+) it would slow down the whole VM experience even more. I doubt that VirtualBox or any server virtualization (Hyper-V?) would improve the experience. Maybe it's my patience (or the lack of it) that got tested really fast, but VM just isn't working for me. If anybody has different experience, please let me know if you have any advice on how to make the whole experience better - smoother IDE, like on local installation where runs really fast (very acceptable).
  7. Mike Torrettinni

    How secure is your WordPress installation?

    The description scares me a little bit... almost feels like it sends an assassin to anybody trying to access my website... 🙂 "Our Threat Defense Feed arms Wordfence with the newest firewall rules, malware signatures and malicious IP addresses it needs to keep your website safe. Rounded out by a suite of additional features, Wordfence is the most comprehensive security option available."
  8. Since I started using Frames, I'm setting up a lot of callback functions. I noticed a lot of them are getting duplicated, especially the simple ones, with simple type parameters. Of course all callbacks are defined and used within the needed scope, not global. Should I create a few common callback functions and have them defined in global scope, like: TIntFunctionWithIntParam = function(aValue: integer): integer of object; TStringFunctionWithIntParam = function(aValue: integer): string of object; TIntFunctionWithStringParam = function(const aStr: string): integer of object; TStringFunctionWithStringParam = function(const aStr: string): string of object; TIntFunction = function: integer of object; TStringFunction = function: string of object; these function can then be used in any Frame. Of course functions that are specific to each Frame, would still be defined in each Frame. Or is this the wrong approach and all callbacks should be defined exactly for the defined purpose, and within defined scope? Any advice is appreciated!
  9. Mike Torrettinni

    Common callback functions, or not?

    Correct, well I probably didn't phrase my statement correctly, as I'm not too experienced with anonymous methods. And as @Rollo62 has shown, a few posts prior, there's a lot you can do with anonymous methods.
  10. Mike Torrettinni

    Common callback functions, or not?

    Thanks, good to know.
  11. Mike Torrettinni

    Common callback functions, or not?

    Well, not sure how to answer this, because my understanding is event=callback.
  12. Mike Torrettinni

    Common callback functions, or not?

    I very rarely use anonymous functions, so I assume the limitation (compared to callback) is that it can only be used within already executed code. You can't just assign it to something, because it's anonymous (not defined anywhere). Right?
  13. Mike Torrettinni

    Common callback functions, or not?

    Thanks! I was thinking about this why I made such a big deal about this, the event vs callback, function vs procedure... It's simple, I can use what I need in that situation, as they both have valid use cases.
  14. Mike Torrettinni

    How secure is your WordPress installation?

    I'm not a WP expert, so it's nice to see a blog where the the problem is explained and solution is simple: download plugin+upload+activate. Simple, thanks!
  15. Mike Torrettinni

    Common callback functions, or not?

    Yes, arguments need so to be passed in procedure and function call. That is the same.
  16. Mike Torrettinni

    Common callback functions, or not?

    Oh, of course! I didn't really think about it in that way. It makes sense: assigned vs called, thanks! EDIT: Hm, well thinking about it... function is also assigned and you can use if Assigned(FOnGetSearchTextLine) then FOnGetSearchTextLine; Right? Maybe I'm proving your point, but I'm still little unsure about procedure vs function event.
  17. Mike Torrettinni

    Common callback functions, or not?

    Oh, Ok, I wasn't sure what you are referring to. But you want the purple icon, right? OK, I just 'thanked you'.
  18. Mike Torrettinni

    Common callback functions, or not?

    Where is the "thanks" button?
  19. Mike Torrettinni

    Common callback functions, or not?

    Aha, thanks. Looking through some examples, most of them use TEvent = procedure() of object, I assume TEvent = function(): resulttype of object; is not the normal way, right? Am I just lucky it works for me?
  20. Mike Torrettinni

    Common callback functions, or not?

    Maybe I over-designed it, but this is what I have: MainForm -FrameA -FrameB -FrameC -Frame..N CommonSearchForm each Frame has VirtualTreeview control to display data. CommonSearchForm has Search, SearchNext, SearchPrev, keyboard actions (Ctrl+F/N)... and these actions also control (move next/prev) searched lines in Frame's VirtualTreeView. So, each Frame creates it's own instance of CommonSearchForm and assigns local methods to events so that GetSearchTextLine gets different text from each Frame's local method that returns text line to be searched. Are you suggesting I create all Search features in each Frame?
  21. Mike Torrettinni

    Common callback functions, or not?

    Perhaps I'm using the callback term incorrectly... and these are events? I use these to assign local Frame method to a general Search form, like this: // definition callback/event TGetSearchTextLine = function (aDataIdx: integer) string of object; // method in Frame that returns data line to be searched within function TFrameA.PrepareDataLineForSearch(aDataIdx: integer): string; begin Result := fData[aDataIdx].ProjectName + fData[aDataIdx].ProjectDescription; end; // create Search form and assign/connect methods (callbacks/events) procedure TFrameA.StartSearch; begin ...// create fSearchForm fSearchForm.GetSearchTextLine := PrepareDataLineForSearch; end; // in Search Form I have public variable of type of callback/event public var GetSearchTextLine: TGetSearchTextLine; // and it gets called when Search is executed in Search form procedure TSearchForm.Search; begin fDataLineToSearch := GetSearchTextLine; SearchForText(fDataLineToSearch); end; When used like this, am I using a callback or event? In this case I'm not using Form/Controls methods (like OnClick and others). Do I still need Sender: Object? Is the reason for this so that I know who called the method?
  22. I use a lot of enums and was thinking if there is better to way to 'find' the proper enum to be used. So, I was thinking something like this for THTMLType enum: THTMLType = (htTemplate, htStatic, htHeader, htCustom); TReportEnums = record HTML: THTMLType; end; var gEnums: TReportEnums; and used like this: vHTMLReportType := gEnums.HTML.htTemplate; If I try I get error: E2018 Record, object or class type required, on HTML. . Edit: I would like to have something that could use code completion, so I don't need to remember htTemplate. I would type Enums. and I would select among options HTML. and then I would see THTMLType options... Any suggestions, or this is just not possible?
  23. Right now there are only 25 topics per page, displayed in forums. Is it possible to add 'Show all topics' or perhaps options to show 100, 200... topics per 1 page? The forum is becoming really useful resource, but it's quite annoying to have to go page by page back to find older topics. I'm referring to this navigation on top of each forum: Show All or Show 100/200/500... per page would be very useful. If Show all is possible, I don't mind waiting to load. I appreciate even considering this request. Thanks!
  24. Mike Torrettinni

    Adding 'Show All topics' to see all topics in selected forum

    I see this is not available. There are general Topics per page and Posts per page, but for the whole site, not per user or per topic. Shame. The explanation for removing this option is 8 years old, but I guess still valid today: https://invisioncommunity.com/forums/topic/362706-number-of-posts-to-show-per-page-user-setting/?do=findComment&comment=2271715
  25. Mike Torrettinni

    Organizing enums

    Aha, cool. I know I can use consts in records, but never thought of this approach to replace enums. I guess this whole topic would be pointless if code completion would work as it should. But I like the different approaches and suggestion, and a little history (I assume the discussion with Niklaus wasn't last week 🙂 ).
×