Jump to content

Leaderboard


Popular Content

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

  1. Leaving aside the issues that are commented on by other, instead of if Supports(fBaseFrameClass, ISupportTask) then (fBaseFrame as ISupportTask).CheckTask; surely you need var Task: ISupportTask; ... if Supports(fBaseFrame, ISupportTask, Task) then Task.CheckTask; Two changes: Ask the implementing object rather than the class whether or not the interface is supported. Use the three argument overload of Supports so that you can get the interface while you are querying for it.
  2. Fr0sT.Brutal

    Are there any free DBGrid components out there?

    If you'd switched it first to awesome-pascal list you'd found that grid much more early 😉
  3. Rollo62

    Modernizing the Dev-C++ IDE

    Hi there, I like the modernizing of the old Dev-C++ IDE very much 👍 Well done. This is very important, I think, to follow with a good and stable base towards new OS and market paradigms. It looks fresh and modern, while still keeping the good old qualities, without overdoing things. All in all very well able to keep current users and likely to catch some new friends in the future too. We have the saying: "The eye eats with you", and I think that is pretty much true.
  4. Fellow Delphi developers, This is with great pleasure that we announce the immediate availability of HelpNDoc 7.1, an easy to use yet powerful help authoring tool producing CHM help files, responsive HTML 5 and mobile Web Sites, DocX and PDF manuals, ePub and Kindle eBooks as well as Qt Help files from a single source. HelpNDoc is Free for personal use and evaluation purposes and is available at: https://www.helpndoc.com HelpNDoc 7.1 provides many new features and enhancements including the ability to define default image settings; An improved spell checker which also checks snippets; New barcode symbologies; And many additional enhancements and bug fixes... You can learn more about this update at: https://www.helpndoc.com/news-and-articles/2021-02-02-define-default-image-settings-enhanced-spell-checker-and-new-barcode-symbologies-in-helpndoc-7.1/ Video of some of the new features in HelpNDoc 7.1: Download HelpNDoc now and use it for free for personal and evaluation purposes: https://www.helpndoc.com/download Follow our step-by-step video guides to learn how to use HelpNDoc: Best regards, John, HelpNDoc team. https://www.helpndoc.com
  5. Yes, I put it on ToDo list to revisit - 5 years ago when I tried to implement it it was 10x slower than normal StringReplace call, perhaps because they way I was concatenation strings. Now I can probably improve it, I just need to book the time. Good thing is nobody is disputing that Pos is good improvement to use with StringReplace, when we don't know if call is actually needed or not - if sub string is in the string. Of course for repetitive calls, like in my case.
  6. That's not the right way to solve this. The right way is to iterate over the string once rather than 5-10 times. Why would you want to iterate over the string so many times?
  7. Which is perfectly fine. This is not a side effect of Supports() itself, but rather is due to your mismanagement of your interfaced object. Your TMyFrame class has reference counting enabled on it, but your fBaseClass member is not maintaining an active interface reference to the object, so the object has an initial reference count of 0 instead of 1, and then your cast to ISupportTask increments the reference count to 1 instead of 2, and then releasing that ISupportTask decrements the reference count to 0 instead of 1, freeing the object. As Dalija said, you need to change this line: fBaseFrame : TBaseFrame; To this instead: fBaseFrame : IInterface; And then this change this: procedure TForm22.FormDestroy(Sender: TObject); begin fBaseFrame.Free; end; To this instead: procedure TForm22.FormDestroy(Sender: TObject); begin fBaseFrame := nil; end; Or, simply get rid of the OnDestroy handler completely, since the fBaseFrame member will be finalized anyway then the TForm22 object is destroyed, releasing the reference for you. And, as David mentioned, you should change this: procedure TForm22.Button1Click(Sender: TObject); begin if Supports( fBaseFrameClass, ISupportTask ) then (fBaseFrame as ISupportTask).CheckTask; end; To this instead: procedure TForm22.Button1Click(Sender: TObject); var Task: ISupportTask; begin if Supports( fBaseFrame, ISupportTask, Task ) then Task.CheckTask; end;
  8. Dalija Prasnikar

    I got bitten by an interface!

    As long as your variable is some interface type, reference counting will be properly initialized and you don't have to worry about memory management of Support destroying your instance. Code @David Heffernan posted for calling Support function is better one than your example. But this was not the root cause of your problems. You can also disable reference counting mechanism with the code @Alexander Elagin posted. In this case you have to Free the instance when you are done, but there is another catch, you need to make sure that at that point you don't have any active interface references to your object because automatic _Release that compiler inserts after that interface reference goes out of scope will access already destroyed object instance - which can lead to a crash.
  9. ... or simply add the _AddRef, _Release (wasn't there a 3rd one?) methods required for an interface implementation to your ancestor class and let them do nothing.
  10. Dalija Prasnikar

    I got bitten by an interface!

    You are experiencing classic issue of "mixing objects and interfaces" Your TBaseFrame class has enabled reference counting and you are using it like normal class. You should store it in interface reference - fBaseFrame: IInterface (or whatever other interface type suits you the best) and you should not call Free on it (you cannot call it on interface, but point is that its memory will be automatically handled so you don't have to worry about it) https://dalijap.blogspot.com/2018/03/dont-mix-objects-and-interfaces.html
  11. Pos is much faster than Replace so what are you wondering about? Of course to not call Replace at all is faster than call it.
  12. Nothing needs to be fixed. StringReplace is giving correct output, isn't it? You absolutely don't want to be calling Pos inside an efficient implementation of StringReplace. All that you are learning is that StringReplace is not efficiently written. The correct way to deal with that is to find/write and use a more efficient function to replace text. That is of course if this is a bottleneck in your code. Have you checked? BTW, do you really have calls to Pos littered through your code whenever you call StringReplace?
  13. Anders Melander

    32bit bitmap

    If you're using Delphi 7 then you will have to use 3rd party components. For example Graphics32 - and better hurry because I plan to drop support for Delphi 7 in Graphics32 the first chance I get.
  14. David Heffernan

    32bit bitmap

    Really? I mean true for bmp files but Windows API supports 32 bit bitmaps fine so far as I know.
  15. Ok, well Yes, it doesn't use Pos to check if it needs replacing at all. System.SysUtils.StringReplace: "FoundPos := Pos(xOldPattern, Str, FoundPos);" Fail. Aha, I just noticed StrigReplace has rfIgnoreCase flag. 6th line in System.SysUtils.StringReplace: "if rfIgnoreCase in Flags then" Fail. Your test case: vNewStr := 'Fail.'; if Pos(cNoFind, cLongStr) > 0 then vNewStr := StringReplace(cLongStr, cNoFind, cReplace, [rfReplaceAll]); Writeln(vNewStr); Fail.
  16. Maybe you have a special, dedicated RTL shipped with Delphi. Was it in a golden envelope?
×