Jump to content

Dave Novo

Members
  • Content Count

    151
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Dave Novo

  1. Dave Novo

    New to Delphi and to the forum - with questions

    Welcome to the Delphi world. There are lots of tools available for many of the questions your asked. Have a look at the subforum on this site and search for various tools and you will see many examples. Most of the tools have been around for a long time, and are very feature complete and differ by subtleties of usage etc. Delphi Third-Party - Delphi-PRAXiS [en] -for the diagrams, I know both TMS Software and Developer Express have flowcharting tools you can leverage. There are other lesser known ones that are available. Just google "delphi flowchart component" -Similar with Help tools. We used Help and Manual and liked it, but there are many other tools equally as valid. These do not even have to be delphi specific. -Please describe what "font oddities" you are seeing in more details. -Without knowing in more detail what you want, recommending a database is just throwing darts against the wall. All have their pros and cons.
  2. Is there an example anywhere of properly hooking up events to a newly created Observable list in order to be notified if items are added/removed to from the list
  3. Dave Novo

    CreateObservableList example in Spring4D

    ok, perfect, I got that working. thanks!
  4. Hello, Does spring4D have a similar method as the Python enumerate() method? I feel this should be possible, if the "standard enumerator" that is returned now was wrapped inside an enumerator that returned a record that contained the index and the original <T> itself. In fact, this special record could implement record based conversion methods to convert automatically to both an integer and T. I imagine coding something like this var myColl:=TCollections.CreateList<TSomeClass>; // add some stuff to the list for var curItem in myColl.EnumerateWithIndices do begin // at this point, curItem is really a record, with fields Index, TSomeClass someArrayOfInt[i]:=curItem; // implicit conversion to integer SomeClassList.Add(curItem); // adds the TSomeClass that is returned to another list, implicit conversion to TSomeClass end; Does something like this exist?
  5. Dave Novo

    Get Index of enumeration in spring4D

    thanks. I did not realize I had an older version. Just updated....
  6. Dave Novo

    Get Index of enumeration in spring4D

    By the way, I tried the code, based on @Stefan Glienke example above var foo:=TCollections.CreateList<string>; var indexedColl := TEnumerable.Select<string, Tuple<Integer,string>>(foo, function(const item: string ;const index: Integer): Tuple<Integer,string> begin Result := Tuple<integer,string>.Create(index, item); end); and it does not compile. I think the problem is that TEnumerable.Select expects a TFunc<T,TResult> The following seems to be okay var foo:=TCollections.CreateList<string>; var idx:=0; var indexedColl := TEnumerable.Select<string, Tuple<Integer,string>>(foo, function(item: string): Tuple<Integer,string> begin Result := Tuple<integer,string>.Create(idx, item); inc(idx); end);
  7. Dave Novo

    Get Index of enumeration in spring4D

    I guess I could wrap the above code into something like TEnumerateHelper<T>=class function CreateIndexEnumerator(list:IList<T>):<result is whatever the type of the .Select statement is> also, define a type TIndexedEnumItem<T>=Tuple<Integer,T> and consolidate that all to make somewhat simpler code to use on a day to day basis. I think different logic is needed though if the .Where predicate has an integer enumerator passed in.
  8. Dave Novo

    Get Index of enumeration in spring4D

    Hi Stefan, Firstly, I would like to say I think the Spring4D library is amazing, and you have done an amazing service for the Delphi community. Please take anything I write merely as a suggestion, not criticism in any way!!!!!! There seems to be little you cannot do in Spring4D if you are clever. I have been coding in Delphi for decades and recently had occasion to start programming a bit in Python. What I am amazed by is how little code I have to type in Python for common things. Of course, there are pros and cons to other aspects of Python (speed etc - that can be dealt with in a variety of other ways) but for the point I am making here it is just about code simplicity and clarity. I love IShared<T> because it removes hundreds of lines of boilerplate try..finally blocks that on one hand are simple, but the other clutter up the code with useless crap that distracts you from what you are trying to do. The python syntax of new_list = [expression for item in iterable if condition] where new_list is in and of itself an enumerable object that can be plugged into other lists makes the code so simple and clear. Comparing the code var indexedColl := TEnumerable.Select<TMyClass, Tuple<Integer,TMyClass>> (myColl, function(const item: TMyClass; const index: Integer): Tuple<Integer,TMyClass> begin Result := Tuple<integer,TMyClass>.Create(index, item); end) .Where( function(const tuple: Tuple<Integer,TMyClass>): Boolean begin Result := Odd(tuple.Value1); end); to the Python Version indexedColl = [y for x,y in enumerate(myColl) if x%2 != 0] Explanation for non-python people. x is the index, y is the element in myColl at that index. the if statement at the end filters for odd numbers. Of note, indexedColl can be passed as the enumerator directly into anything that accepts an enumerator. I 100% understand that of course Delphi syntax cannot be as simple as Python we have to be specify the types in the generic specialization somehow, but any way that can be moved towards a more simplistic syntax (at least for common use cases) would be helpful. Working with Python has been a real eye opener in the fact that you don't have to break your brain with generics to do everything. (you do have to break your brain in other ways, if people don't use type annotations for example and you spend 1 hour figuring out what type a method is expecting - but that is a different story). Even knowing what you are trying to do in the example above, I would really have to study the code diligently to understand exactly how all the pieces fit together to make it work.
  9. Dave Novo

    Get Index of enumeration in spring4D

    Hi Stefan, Sorry, I did not notice the .Where gets an index. But .Where does not seem to satisfy the first requirement. I guess I would have to create my own enumerator and capture it in the .Where method.
  10. Dave Novo

    Get Index of enumeration in spring4D

    As a follow up, another key nice addition would be able to do something like this for var curItem in myColl.EnumerateWithIndices([1,5,7,9]) which would return the "indexed enumerator record" for only indexes 1,5,7,9 For this example, you should be able to pass in any IEnumerator/IEnumerable<integer> or something like for var curItem in myColl.EnumerateWithIndices( function (zIdx:integer):Boolean begin result:=IsOdd(zIdx) end ); which would return an "indexed enumerator record" for only odd numbered indexes I will see if I can get a working example over the holidays....
  11. Hello, If I make a list<T> where T is a record, what is the best way to get access to the actual records in the list to make modifications to them? If I was using the built in TList<T> I would use the .List<T>, but Spring4D.IList<T> does not have a property to access the raw list. Is there another way to get access to the actual record instance in the list in order to modify it. calling .Items makes a copy of the underlying record it seems and if I try to enumerate through the list using the enumerator and set a property on the variable in the enumerator I get an error that I cannot set a control loop variable.
  12. It would be cool if the enumerator supported pointer access to the underlying element. Something like for var curPtr in List.Pointers<PRecord> do begin curPtr.SomeValue:=1; end In the case above, the Pointers record would return a pointer to the underlying item, cast to the pointer type passed in as T. This can be useful for records (and maybe other) to deal with a pointer to the underlying items
  13. I am a bit new to spring 4D, and am attempting to use ISet<T> as a replacement of the standard set of <type> in Delphi. How do you easily check if an value is in a ISet<T> The use case I have is with an enum. Where TEnumSet = set of enum; In Delphi I would do if myEnumToCheckFor in MySet then ..... I had expected to see a method ISet<T>.Contains<T>:Boolean, or something along those lines, but I don't see anything. It seems like ISet<T> has lots of helpful methods for dealing with other sets, but I cannot find anything to check if an individual item is in the set. Of course, I can create a new set that contains 1 item and use that, but it seems overkill to do presuming Myset:=ISet<some enum> if MySet.InsersetsWith(TCollections.CreateSet([myenumTocheckFor])) do.... am I missing something? note: sorry, I meant to put this in 3rd party, but somehow it ended up here. I cannot seem to find a way to move it to the 3rd party subforum.
  14. Dave Novo

    ISet<T> in spring4D

    The reason I was thinking of using ISet is just that Delphi is very verbose: if myEnum in myset then is not so bad but if [enum1,enum2] * myset <> [] then is obscure and if you dont use this syntax frequently you are constantly reminding yourself what the intention was, particularly for more complex set operations. I feel that if mySet.DoesNotContainAny([enum1,enum2]) then is much easier to understand the intention. Not as performant of course.
  15. Dave Novo

    ISet<T> in spring4D

    Oh thanks. I did not think to go all the way up to enumerable, as I am used to that interface just being for enumeration. I will investigate that further....
  16. Dave Novo

    Looking for a certain component

    This may just be a semantic issue. The OP wrote he was "storing" the sum in a label, maybe he meant display. @Anders Melander is correct, data should be stored in variables/fields etc. Of course, if you need to display to the user, some UI control is needed. I have seen too much code where some value was actually stored in a UI control, and the only way to get the current state of that value was to reference the UI control. That is bad.
  17. Dave Novo

    Parallelize Regex

    Parallelizing works well if you can break your overall job into multiple independent tasks, and each task can operate independently of the results of the other task. If the tasks depend on each other in any way, it becomes quite complex quite quickly, generally having to introduce locking and communication mechanisms. In the case of RegEx parsing, how would you break your overall search into multiple independent searches. I dont see an easy way to do this. Each match depends on the results of previous matches. I am not saying it cannot be done, someone might have thought of something extremely clever, but its going to be complicated I think.
  18. Dave Novo

    Simulate Multiple Inheritance

    The other thing I would suggest is to have a look at the "implements" keyword. Please consider the code below as pseudocode ICommonFuncs=Interface procedure CommonProc; end TCommonObj=class(TInterfacedObject,ICommonFunc) procedure CommonProc end TapRectangle=class(TRectangle, ICommonFunc) private FCommonObj:ICommonFunc function GetCommonFuncImp:TICommonFunc; public constructor Create; property CommonFuncImpl:ICommonFunc read GetCommonFuncImpl implements ICommonFunc; end constructor TapRectangle.Create; begin FCommonObj:=TCommonObj.Create as ICommonFunc; end The idea here is that the functionality needed for ICommonFunc is actually implemented by a separate object. When you query the ICommonFunc interface from TRectangle you get it from FCommobObj. You can then easily add the same functionality to TCircle in the same way. In general, FCommonObj may need some way to talk back to its owning object to get some specific information. This is helpful if the methods FCommonObj/ICommonFunc follow a template patter where most of the code is in TCommonObj but there is some specific information needed from TRectangle or TCircle.
  19. Dave Novo

    Minimum Viable Product (MVP)

    I agree with Anders. This question is impossible to answer. An MVP for a "Sale Management and POS software" for one group of products is completely different than from another group of products. i.e. an MVP for selling gumballs is a totally different ballgame from an MVP for a product cars. If deciding an MVP is so simple that you can create one from asking a 1 sentence question to a group of people who know nothing about what you are doing then there would be no need for any domain experts for anything in software development.
  20. Dave Novo

    Parallel.For optimization

    There is also FastMM5. However, I would suggest looking at your code and figuring out a way to allocate required memory (even if you have to overallocate) and minimize/eliminate heap memory allocations during the threading code.
  21. Hello Everyone, I am just wondering if below is simply a bug, or there is some method to the madness. One of the valid windows short date formats is the following So, one would think that if you change windows to the short date format above, and wrote the Delphi code fs:=TFormatSettings.Create; newDate:=StrToDate('05-Apr-17',fs) then you would get a valid date. However, you do not. I checked this on Win7 and Win10, with Delphi Sydney and Seattle. It is hard to believe something this ancient does not work. The fs record has the correct shortMonthNames loaded. There are a few strange issues. 1. The TFormatSettings.ShortDateFormat ends up being dd/MMM/yy because FixDateSeparator replaces the '-' with a '/'. I am not sure this is relevant though, as the TFormatSettings.DateSeparator is still '-' 2. The key thing that fails is TryStrToDate calls ScanDate which exits out because of if not (ScanNumber(S, Pos, N1, L1) and ScanChar(S, Pos, AFormatSettings.DateSeparator) and ScanNumber(S, Pos, N2, L2)) then Exit; i.e. it is trying to find a number, followed by a separator, followed by a number. Even though the current date format specifies that the month portion should be the short name format. Is there another date method I should be using that works more reliably. Or am I doing something wrong?
  22. Dave Novo

    TeeChart 11.3 to 12.1

    They did a bunch of work recently to autoscale fonts based on the DPI. There is are some new enums to control this TCanvasZoomText=(ztManual, ztNo, ztAuto); TCanvasZoomPen=(zpManual, zpNo, zpAuto);
  23. Dave Novo

    Docking Example

    Hello all, If you go to the Delphi help Docking (Delphi) - RAD Studio Code Examples (embarcadero.com) You see if refers to a "docking demo". The general help for the built is docking is woefully inadequate. If you go to RAD Studio Code Examples (embarcadero.com) You find that the code examples are supposed to be at Embarcadero Technologies · GitHub or GitHub - Embarcadero/RADStudio11Demos: Delphi and C++Builder Demos for Embarcadero RAD Studio version 11 I cannot find a docking demo in either location. Has this been removed from the demos? Or am I just going crazy and its really there. Searching the github for the work "dock" and also cloning the repo and searching for "dock" does not turn up any files
  24. Hello, Is there an example of how TPropertyChangedEventArgs and associated infrastructure is supposed to be used? I am hoping there is some magic somehow where I can get a notification that a property changed on a class, without having to modify the source of that class to throw an event. Not sure how this would be done, magic code hooks, VMT hijacking or some other craziness. But when I see some of the magic in Spring4D, I can believe that almost anything is possible 🙂
  25. I never meant to imply that it was unnecessary. In fact, I already applied your excellent code to my own code that was writing out CSV files from large 2D matrices of integers. I was just wondering if there was a wider variety of circumstances that I could also leverage this technique that I was not thinking of. In fact, I also have to write out large matrices of floating point values, so will try to modify the Delphi float conversion routines to work on array of char similar to what you proposed below. TBH though, I have not done much timing. I wonder if the overhead of writing the file to disk dwarfs the time it takes for the conversions.
×