Jump to content

Anders Melander

Members
  • Content Count

    2815
  • Joined

  • Last visited

  • Days Won

    153

Everything posted by Anders Melander

  1. Anders Melander

    How can to set up an umbrella unit?

    Not directly; Delphi unfortunately doesn't support "wildcard" includes like that. The way I do it, for something like dialogs, is to associate each dialog with an interface and then separate the implementation of the dialog from the interface: unit Foo.Dialogs.Bar.API; type IFooDialogBar = interface ['{4279694B-C3D6-4B2A-A134-CEACDF6185AF}'] function Execute: boolean; end; unit Foo.Dialogs.Bar; interface uses Forms, Foo.Dialogs.Bar.API; type TFormFooBar = class(TForm, IFooDialogBar) // ...other stuff here... private // IFooDialogBar function Execute: boolean; end; implementation function TFormFooBar.Execute: boolean; begin Result := (ShowModal = mrOK); end; In order to create the dialog you could use a factory function like Peter suggested: function FooDialogBar: IFooDialogBar; begin Result := TFormFooBar.Create(nil); end; You will then have to manage the lifetime of the dialog somehow. Since you are accessing the dialog object via an interface you can't just free it once you are done with it. It will have to be done via reference counting. Unfortunately the default TComponent reference counting will not do it so it will have to be modified (overridden). I have a dialog manager that takes care of all this without the need to modify anything. It handles both modal and non-modal dialogs. I'm in the process of adding it to the translation manager project, so the code it will probably be public later tonight or tomorrow. The dialog manager is used like this: // Register the dialog API in the initialization section of the disloag unit initialization DialogManager.RegisterDialogClass(IFooDialogBar, TFormFooBar); end; ... // Create dialog var DialogBar := DialogManager.CreateDialog(IFooDialogBar) as IFooDialogBar; // Display dialog if (DialogBar.Execute) then begin ... end; // Lifetime is controlled via reference counting. // When interface goes out of scope, the dialog object is destroyed. ...
  2. Anders Melander

    Change a forms OnShow Event?

    It's really hard to understand what you are doing from your description. Please show us the code of a minimal example instead (and please use the code tag). // Like this
  3. In TFormSplash.UpdateBannerImage: if (Scale = 255) then PixDst^ := PixSrc^ else if (Scale = 0) then PixDst^ := PixSrc^ or $00FFFFFF // *** Change this *** else begin RGB := PixSrc^ and $00FFFFFF; RGB := RGB xor $00FFFFFF; // *** Add this *** PixDst^ := (PixSrc^ and $FF000000) or (Div255((RGB shr 16) * Scale) shl 16) or (Div255((RGB shr 8 and $FF) * Scale) shl 8) or (Div255((RGB and $FF) * Scale)); PixDst^ := PixDst^ xor $00FFFFFF; // *** Add this *** end; This isn't the most elegant solution but since the original code was a bit of a hack (which is also why the solution isn't obvious at all) I guess it doesn't matter. Anyway, what it does is invert the color of the source pixel, blend it with the (black) text, and then invert the result again.
  4. Anders Melander

    UI code optimization logic

    Very nice!
  5. I dunno. I think it's pointless. I mean, properties? Pfft! What's the point? Delphi is dead anyway and if there's one thing the past 30 years has shown it is that the design is flawed beyond repair but we were just too ignorant to notice. If only we had been told about this before. The shame is unbearable.
  6. Yes, yes, we see now. How could we have been so blind? Totally different things. Totally! Now, run along.
  7. The inconsistency, as you call it, is by design and just because you want the design to be different doesn't make the design wrong. Even Windows' own modal dialog function works the same way; Internally it implements a message loop which exits once a flag has been set (by the EndDialog function).
  8. If you use ShowModal then you are using the modal loop built into the VCL which relies on exiting the loop when ModalResult<>mrNone. If you disagree with that design then don't use ShowModal; Use Show and build your own modal handling around it. And good luck doing that without a loop which monitors some kind of state flag. I don't think you have thought this through.
  9. That makes better sense because there was something really fishy about the prerequisites of that project. I once designed, on paper, a large enterprise support system in which one of the key components was a telekinetic interface. The goal of the design was to get fired (long story). It sounds as if these people used the same strategy.
  10. Anders Melander

    Event handler in thread

    I agree. One of the things that have helped me tremendously over the years as a software developer is my (hobby) background in first analog electronics and then digital, hardware and then software. It gives one a deep understanding of how things work and why. There was also an early phase where I ventured into chemistry but, although I got really good at blowing shit up, I don't think that particular skill set has helped me much 🙂 (and thanks 😘 )
  11. Anders Melander

    Event handler in thread

    You don't need an owner; Just specify nil as the owner in the constructor and remember that you have to destroy the object in the thread destructor (or on exiting Execute, if you create it there). Generally, the purpose of Owner is to have a TComponent destroyed automatically when the owner is destroyed, which is handy when you place stuff on a form. For dynamically created components it is better to control the lifetime (Create/Destroy) explicitly so you have complete control of what is going on and when. It also makes the code easier to understand when you don't rely on implicit behavior.
  12. Anders Melander

    Event handler in thread

    Yes. It doesn't hurt but if you are not referencing the type then you might as well delete it. I couldn't spot any obvious issues after a brief look through the source. One thing I would do though, is to move the TCommPortDriver.Create into the Execute method so it is constructed in the context of the thread, instead of the calling thread (which is supposedly the main thread).
  13. Anders Melander

    Reduce exe weight : Link with runtime package

    So use an installer or zip the files. I'm not buying the argument that users can't figure out how to unzip a file or run an installer. IME, they can if they have to.
  14. Anders Melander

    Reduce exe weight : Link with runtime package

    Yes it is because it trashes the page cache. If memory is low then something else has to be paged out before the exe can be extracted to memory - and then paged out.
  15. Anders Melander

    Event handler in thread

    CommPortReceiveData is a method pointer. @CommPortReceiveData is a pointer to a method pointer. You have declared TCommPortReceiveData as a "procedure of object". That makes it a method pointer so this: procedure CommPortReceiveData(Sender: TObject; DataPtr: Pointer; DataSize: Cardinal); is wrong (it's not a method; It's a procedure) while this: procedure TUploadThread.CommPortReceiveData(Sender: TObject; DataPtr: Pointer; DataSize: Cardinal); is correct. You haven't declared the method. You have declared a pointer to a method. Your declaration in TUploadThread should look like this instead: TUploadThread = class(TThread) private ...other stuff... procedure CommPortReceiveData(Sender: TObject; DataPtr: Pointer; DataSize: Cardinal); ...more stuff... end;
  16. Anders Melander

    Current Generation methods in Apps under Windows 7?

    I wouldn't know; I'm not confused - but that shouldn't stop people from explaining if they find joy in that. It should have been obvious that I know recent Delphi versions doesn't support being installed on Windows 7, given that I've installed and run several versions on Windows 7 and of course got told by the installer that it wasn't supported. I also stated that I hadn't encountered any problem with Delphi applications running on Windows 7.
  17. Anders Melander

    VCL resizeable and moveable label

    And it shouldn't; It is functionality that belongs in another layer. Keep it simple.
  18. Anders Melander

    I keep being off by one

    Trace Into = Step Into But you don't need to trace into. You can just place a breakpoint inside your square function. This is a very simple problem so I suggest you try to single-step through it "in your head" first; What happens when you call square(0), square(1), etc.
  19. Anders Melander

    Current Generation methods in Apps under Windows 7?

    Thanks for clearing that up - or not.
  20. Anders Melander

    Current Generation methods in Apps under Windows 7?

    Okay, but it seems it doesn't. At least I haven't encountered anything in it that did.
  21. Anders Melander

    Current Generation methods in Apps under Windows 7?

    I don't think that list is up to date given that Delphi has complained when you tried to install it on Windows 7 since 10.3 (AFAIR). That said, I upgraded my main system from Windows 7 to 10 last year but before then I didn't have any problems with the IDE or applications not working on Win7.
  22. Anders Melander

    VCL resizeable and moveable label

    Btw, you should let the TSizeableLabel own the HostedLabel so this: HostedLabel := TLabel.Create(AOwner); should be: HostedLabel := TLabel.Create(Self); - And there you have an example of when to use Self. Now since the HostedLabel is owned by the control, it will be destroyed automatically when the control is destroyed (the base class TComponent takes care of that), so you can must get rid of the HostedLabel.Free.
×