Jump to content

Mike Torrettinni

Members
  • Content Count

    1509
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Mike Torrettinni

  1. Aha, I think I use the word refactoring wrongly. @Stano see my Edit in a few posts above, I tried to explain the purpose of the topic.
  2. I think we have a little misunderstanding here, see my Edit in the post above.
  3. Was this posted in wrong thread? If there is anything missing in first post, let me know will try to give more details. Edit: hm.. trying to see where you got the optimize and bottleneck from.. perhaps my definition of word 'refactoring' is different, but I used the word refactoring to point out I'm trying to come up with 1 method of how I define and retrieve enum names, for display. From 3 most common different versions I use, I want to consolidate all into 1 implementation type. Of course I didn't want to choose the option that is significantly slower. So, perhaps 'consolidation of various code into single implementation' is more precise than 'refactoring'. So, if this is not refactoring, it wouldn't be the first time I use the wrong word.
  4. I actually thought GetEnumName would be much slower, but is only about 4x slower: Not bad at all for RTTI in Delphi 10.2.3! Perhaps new Delphi 11 RTTI will be even faster!
  5. Before I looked into the asm, I thought that literal/magic strings get 'allocated' with every call. I see it's not the case.
  6. Yes, custom strings, but not for different languages. Imagine countries or states, usually US/CA for United states/Canada or CA for California, some values just can't be 1:1 with enum names. Or in very rare cases this could be OK, but in 99% cases my enums have prefixes (to avoid forcing scoped enums) and don't match display strings. So, I'm refactoring from above 3 examples in my code to single example, so I have 1 type of implementation. The maintenance seems to be easiest with array[TEnum] of , most annoying is with Magic strings, of course.
  7. I know I can use System.TypInfo.GetEnumName but then I'm limited to the actual enum names instead of custom strings. Right?
  8. I'm trying to make compiler complain when adding new enum values and related code is not ready for new values: here is simple example of Project types and setting project names: type TProjectType = (ptMain, ptExternal, ptDivision, ptBranch); TProjectNames = array[TProjectType] of string; var xProjectNames: TProjectNames; procedure SaveProjectNames(aProjNames: TProjectNames); begin xProjectNames := aProjNames; end; function Convert(aProjNames: array of string): TProjectNames; var i: integer; begin Assert(Length(aProjNames) = (Ord(High(TProjectType)) + 1)); for i := Low(aProjNames) to High(aProjNames) do Result[TProjectType(i)] := aProjNames[i]; end; begin //SaveProjectNames(['a','b','c','d']); <- This doesn't work, so I need use Convert function to convert from open array to correct type SaveProjectNames(Convert(['a','b','c','d'])); end. When I add new project type into TProjectType, like ptCountry, I want compiler to complain that any related code, like SaveProjectNames should pass more values. With Assert in Convert function I make sure that everything starts failing in runtime, but it would be nice to have compiler show all the code that needs fixing. It would be easy if SaveProjectNames(['a','b','c','d']); would work, and then compiler would say it's not enough parameters, but open arrays and non-open arrays don't mix. Is that possible in my case?
  9. Lost of my reports are from 15+ years ago, so not using the best approach in design. Datetime and time are not used as filters, so no worries there. I'm not too experienced with dynamically cretingg UI controls based on data, so filters are definitely manual work and data always shown in virtual treeview. I didn't know about this $MESSAGE FATAL. It's almost like Assert for runtime. Pretty cool!
  10. Some very unique suggestions and probably very useful if it was just a single case of enum. Was looking for general solution I can apply to many enums (I guess I should have mentioned that in first post). Here is example where the connection gets lost: And setting projects filter with: vDataFilter.Projects([cbI.Checked, cbE.Checked, cbD.Checked, cbB.Checked, cbC.Checked, cbS.Checked, cbCity.Checked]); And then the conversion from open array to array[TProjectType] of string/boolean.. occurs. So, I'm not looking to redesign UI, just thought perhaps there was simple solution that will trigger alert to add new checkbox and its state as filter.
  11. Thanks, interesting suggestions, but they don't fit the need. I think this is my problem of how I designed reports. In cases where selection is a Listbox, the new project type will be automatically added as additional item because they get generated from enum. But in cases where I manually put checkbox on the form for each project type, I will just need to find them and add new one, when needed. I guess best option is to have 1 common method that creates a filter from selection of project types and then I can follow where this method is used, when new project is added. It would be really nice if compiler could distinguish Set, open arrays and enum arrays, so we can pass ['a','b','c'] into array[enum] of string. And then if enum changes to have 2 or 4 elements it would complain. Seems like a small update to compiler 🙂
  12. I was hoping there is a simple solution. With most of enums this is not a problem, but I have a few that span in multiple UI controls and that is something can't be simply changed. For example: checkboxes to select filter on project type - when new project type is added in enum, I need to add new checkbox on the form. If I can have compiler complain at the level where these checkboxes are transformed into data filter, I can see that a value/parameter is missing -> add new checkbox.
  13. Correct, compiler message that complains.. not sure which message that would be, but any alert that would show me all the code that is using this enum in a way that is not compatible anymore with new size of enum. The const is not good, values are dynamic.
  14. Mike Torrettinni

    Delphi compatibility with Windows 11?

    I never heard of aka.ms domain... I guess I'm out of the loop with the 'new' 🙂 Here is direct link: https://docs.microsoft.com/en-us/windows-hardware/design/minimum/windows-processor-requirements
  15. Mike Torrettinni

    Delphi compatibility with Windows 11?

    I didn't see anybody posted a link to list of CPUs with Windows 11 compatibility, so here it is (Intel and AMD): https://www.pcworld.com/article/3623192/what-cpus-can-run-windows-11.html My PC is 5 years old, but it has a CPU released in 2014, so not Windows 11 compatible, I guess.
  16. Mike Torrettinni

    Need suggestion on developing a custom component

    Yes, it's hard to imagine how to use your components if I'm not creating full blown HTML editor or email client. Simple examples like the one above, could be very useful. Look at the almdev style controls... long page of simple examples, menus, controls, options, selections... and more complex examples and designs.
  17. Mike Torrettinni

    Need suggestion on developing a custom component

    This would be great sample to showcase on your website what can be done. Perhaps also adding some text into the grid. Those full screenshots from projects in Gallery look great, but , except in a few examples, it's not really clear what is your component.
  18. I have a few examples of methods that return list of values in out parameter, like this: function AddItems(..., out aList: TList): boolean; begin for loop if condition then begin if aList = nil then aList := aList.Create; // only create aList if any items gets added aList.Add(); end Result := aList <> nil; end; Of course if no items are added, return false. Pascal analyzer says: Out parameter is read before set, which is true, but it only checks for nil. Is this a valid alert and I should redesign my methods, or just ignore it?
  19. Mike Torrettinni

    Out parameter is read before set

    Yes, now I understand. String variable gets cleared while List and integer don't: uses System.SysUtils, System.Generics.Collections; procedure Call(out aList: TList<string>; out aStr: string; out aInt: integer); begin end; var vList: TList<string>; s: string; i: integer; begin vList := TList<string>.Create; vList.Add('test'); s := 'delphi'; i := 19; Call(vList, s, i); vList.Add('test2'); // here list will have both strings in 'test' and 'test2' // s will be cleared!! // i remains 19
  20. Mike Torrettinni

    Out parameter is read before set

    I keep coming back to this thread and I think I finally see where I was wrong, I assumed that empty List (but created!) is a valid variable for out parameter, because I only get values added to the list and returned. So, when I created a List outside and pass it as out parameter, I didn't realize it will not pass List but a empty placeholder for a returned value, so nil List that needs to be created first, before any values are added. Even the documentation says it: "An out parameter, like a variable parameter, is passed by reference. With an out parameter, however, the initial value of the referenced variable is discarded by the routine it is passed to. The out parameter is for output only; that is, it tells the function or procedure where to store output, but does not provide any input. " I assumed empty list is empty, so all good, nothing to discard. In this example we can see that the actual List variable doesn't get destroyed/discarded as it stays valid after the method call: uses System.SysUtils, System.Generics.Collections; procedure Call(out aList: TList<string>); begin // no changes, no returned value in out parameter end; var vList: TList<string>; begin vList := TList<string>.Create; vList.Add('test'); Call(vList); vList.Add('test2'); // here list will have both strings, 'test' and 'test2' end. Interesting.
  21. Mike Torrettinni

    Out parameter is read before set

    You mean non-existing outside the method before the call, right? If yes then I see what you mean, and is only used outside after the function call.
  22. Mike Torrettinni

    Out parameter is read before set

    I see now, good example, thanks! And you are right, I got away with it because I didn't handle correctly the list outside the called function. It worked because I had .Free only on function result = True. So, it was a bit messed up the whole thing, but your example exposed my wrong way of doing it.
  23. Part of refactoring process and removing global variables I try to create units/classes that have as little as possible exposed to public. Of course this is not always possible, at least with enums. For a big project, where checking each unit is tedious work, is there a way I can get a list of all accessible global variables, consts, types, from current main form unit? I would like to see what is in the public/global accessible area. I hope this could also help me prepare my project for LSP or code insight in 10.5 as I suspect my projects fail because of so much stuff in global reach. Perhaps a third party tool can compile such list?
  24. Hm, probably not worth getting into this for what I need, but I never really looked into it so perhaps is really easy. Thanks, it's pretty extensive report, I think I used PasDoc many many years ago. Perhaps even early beta release, since it's been around since 2008.
  25. That make sense, perhaps I will do he same thing. At least some filtering results per unit and type of result.
×