Hi Delphi XE2 TComponent has a new "Observers" property. Unfortunately the help entries for this are empty. Does anybody know what this new property is good for and how to use it?
Edit: Well i know that it is related to LiveBindings, but I would love to know a bit more about it, and since I have no access to XE2 source code, I can't investigate myself.
It is related to LiveBindings. A rather cool but extensive subject, explained in the new DocWiki for XE2.
The Delphi implementation of the observer pattern is explained here:
http://blogs.teamb.com/joannacarter/2004/06/30/690
I'll update the answer with more details as soon as I've had a chance to look at the source code.
The Delphi XE7 documentation now goes much deeper into the details of the Observers:
Observers is a read-only property that returns the TObservers added to
the TComponent, in order to use the notifications provided by the
observers either with LiveBindings or for the developers' own
purposes.
Note that the Observer in Fringe can be seen on the scene of many Pattern-related events.
Side note:
Observers might also be able to detect situations where a EProgrammerNotFound exception must be thrown by the RTL.
Related
I'm currently using the ID3DXAnimationController interface, but have for some time not understood what the concept of an 'event' is that the controller seems to reference.
MSDN and other references just seem to state this as some event running on the current track, without really mentioning what this means.
Would anyone be able to explain? (with concrete examples)
An animation event is one of these types D3DXEVENT_TYPE.
Remember that D3DX9 (along with D3DX10 and D3DX11) are deprecated. See MSDN and Living without D3DX
As answered in other SO questions modern Delphi finally supports compiler intrinsic functions like AtomicIncrement.
Is there somewhere a list of which intrinsic function is introduced in what version of Delphi so I could use {$if CompilerVersion ...} to keep the code backward compatible (with inline asm) and cleaner for future compilers?
Well, you can use the documentation, but I cannot vouch for its accuracy.
XE7: http://docwiki.embarcadero.com/RADStudio/XE7/en/Delphi_Intrinsic_Routines
XE6: http://docwiki.embarcadero.com/RADStudio/XE6/en/Delphi_Intrinsic_Routines
XE5: http://docwiki.embarcadero.com/RADStudio/XE5/en/Delphi_Intrinsic_Routines
XE4: http://docwiki.embarcadero.com/RADStudio/XE4/en/Delphi_Intrinsic_Routines
XE3: http://docwiki.embarcadero.com/RADStudio/XE3/en/Delphi_Intrinsic_Routines
XE2: http://docwiki.embarcadero.com/RADStudio/XE2/en/Delphi_Intrinsic_Routines
XE: http://docwiki.embarcadero.com/RADStudio/XE/en/Delphi_Intrinsic_Routines
2010: http://docwiki.embarcadero.com/RADStudio/2010/en/Delphi_Intrinsic_Routines
And so on.
An as it happens, this list of intrinsics is incomplete. It doesn't have the functions that you are interested in. Which is a shame. If you are interested in knowing which version those specific functions were added, then you can surely work that out. If you want to have an official list that covers every single function, then it would appear not to exist. I guess you will have to either live without it, or create the list.
Back to the documentation, you can consider this list:
http://docwiki.embarcadero.com/Libraries/XE7/en/System.AtomicIncrement
http://docwiki.embarcadero.com/Libraries/XE6/en/System.AtomicIncrement
http://docwiki.embarcadero.com/Libraries/XE5/en/System.AtomicIncrement
http://docwiki.embarcadero.com/Libraries/XE4/en/System.AtomicIncrement
http://docwiki.embarcadero.com/Libraries/XE3/en/System.AtomicIncrement
http://docwiki.embarcadero.com/Libraries/XE2/en/System.AtomicIncrement
Look at the final two. The XE3 link has info, and the XE2 link is empty. Which suggests that this function was added in XE3. A quick test confirms that.
Given the lack of reliability of the official documentation, are you prepared to trust to it?
So, my advice is that you test this yourself. That has the benefit that you will know for sure that your code is correct.
Im attempting to write a new component descendant from a common component (TDateTimePicker). My ultimate goal is to sub-class the TDateTimePicker so that when the user enters the component, the 'SelText' is set to a particular part of the DateTime.
At the moment, the behaviour of the TDateTimePicker is to focus the last selected text when it receives focus again. What i would like to acheive first, is to find out (look at) the code that actually is executed when the user focuses the TDateTimePicker.
I can see TDateTimePicker is a decendant of TCommonCalender which in turn is a decendant of TWinControl. But ive tried placing a breakpoint on procedures in TWinControl and they cannot be reached (which i guess is correct behaviour since a lot of components inherit from TWinControl).
So how do i find out what is happening when the user enters a TDateTimePicker? What code is run? Is it all hidden? I would hope this may shed some light on what i need to do to override the default bahaviour to accomplish my goal.
TDateTimePicker is a wrapper around a Windows Standard Control. The Delphi wrapper simply sends messages to the Windows control, so there's not much Delphi code to read.
You'll have to treat the TDateTimePicker as a "black box". Whatever happens in there, it's an implementation detail you're not supposed to care about. In fact the implementation details for the Date Time Picker have changed, for example, with Windows 7!
In Project|Options|Compiler check the 'Use debug DCUs' and the rebuild the application. Depending on the Delphi version this checkbox can be found in different places, this is for Delphi 2007.
I'm looking at the excellent dwscript for Delphi see here which provides a useful set of classes to implement a built in pascal script for your Application. I would very much appreciate some help with an example of how to link together the supplied debugging interface with an editor so that I can create breakpoints (and ideally see watches). Has anyone gone along this route please?
Thanks,
Brian
Most of the debugger doc is currently in this post
http://delphitools.info/2010/12/03/spotlight-on-dwss-idebugger/
Also the debugger interface hasn't changed much (if at all) since the original DWScript II (on SourceForge), so the old demos there should hopefully still work with minimal adjustments.
http://sourceforge.net/projects/dws/
For breakpoints, you basically just check the source position of the Expr you get in DoDebug/OnDebug against the list of breakpoints. One simple and efficient way is to merely use TBits -using it as a boolean array of which lines have a breakpoint).
Evaluating/watching requires looking up a symbol, which will give you it's stack address, you can then lookup the value in the stack.
I'll try to add/update a debugging tasks demo for v2.2 (unless someone else does it before me ;) )
edit: as of 11-02-14 there is a TdwsDebugger component to facilitate debugging tasks.
In Delphi; what are the differences between Application.MessageBox, Windows.MessageBox or Dialogs.MessageDlg?
Or which is more efficient to use computer memory?
Windows.MessageBox is the WinAPI MessageBox, Application.MessageBox is a wrapper around it. Dialogs.MessageDlg however is a VCL form. So if you are concerned about memory or thread safety, the first two might be better suited. MessageDlg OTOH is more flexible and easier to use (IMHO, of course).
Nowadays, I'd consider task dialogs (TaskDialogIndirect, TTaskDialog or another wrapper).
Windows MessageBox is localized by OS (Yes, No, Cancel...), MessageDlg can be localized by hand.
If I remember correctly, there is one important distinction bewteen the Delphi VCL message boxes and the Windows ones - you can specifiy flags that stop the Application messages from being serviced (eg MB_SYSTEMMODAL). This can be useful for displaying errors where you need to 'freeze' your application - the Delphi MessageDlg will still fire timer events even whilst on screen. See:
MSDN MessageBox stuff
Memory usage shouldn't be such a problem with message boxes. I personally prefer the VCL form (Dialogs.MessageBox) since I can localize it from the Consts.pas unit. I also like it from the fact that I can add custom controls to it, like checkboxes for "don't show this again" and other stuff like this.
Why do you care about the tiny amount of memory used by a message box? There are many other things you should be concerning yourself with when writing a Delphi app. In any case, as far as I'm aware these are all thin wrappers around the Windows MessageBox API.
They all do the same - invoke WinAPI function MessageBox(). The difference in resource consumption if any is minimal. If you care so much you can call MessageBox() directly - just include "uses Windows".