Delphi Frame Destroy/Hide - delphi

HI
I have an application with more than one frame that act as forms.
I have temporary files I need to delete when the user moves from a certain frame and I currently delete the file when they press OK or CANCEL.
If they just close the application I also want to delete the temporary files but cannot determine when the frame is destroyed.
Regards, Pieter

To detect when a frame is destroyed, override its destructor, Destroy.
If overriding the destructor is not appropriate (say, if the files belong to the enclosing form rather than the frame), then you can use component notification. After you create the frame, call its FreeNotification method, passing in a reference to the enclosing form. When the frame is destroyed, it will call the form's Notification method. Override that method in your form, and if the component is the frame, delete the files. (That method may be called many times in your program, so checking the AComponent parameter is important.)

Related

When to use didMoveToWindow method?

I have been searching around for this particular method:didMoveToWindow() however I haven't found any concrete information.
Could someone explain why and when should someone use this method and when is it called?
This method is called by iOS when a UIView is added to the Window object.
You are supposed to override it to make your app do something at the same that.
The default implementation of this method does nothing. Subclasses can
override it to perform additional actions whenever the window changes.
The window property may be nil by the time that this method is called,
indicating that the receiver does not currently reside in any window.
This occurs when the receiver has just been removed from its superview
or when the receiver has just been added to a superview that is not
attached to a window. Overrides of this method may choose to ignore
such cases if they are not of interest.
https://developer.apple.com/reference/uikit/uiview/1622527-didmovetowindow

DirectX10/ShapDX Custom control

I am trying to create custom control with directx10/direct2D output (panel, not a form). I do all rendering in the overriding OnPaint method, however I have read somewhere that it is wrong and RenderLoop should be used instead. But where should I insert RenderLoop.Run if I can write code only inside of the control? Thank you.
You would create a thread, and have RenderLoop.Run inside the thread. When you do this you have to make sure that events sent back and forth between the components are invoked in a safe manner.

Custom TControl doesn't paint at design time until cut and pasted

I have an odd issue with TChromeTabs. I know it must be something simple, but I can't figure out what needs to be done to fix it.
When I initially drop the TChromeTabs control on a form it is completely transparent. If I cut the control then paste it back to the form the contents are displayed correctly. The contents also appear if I close, then re-open the form.
As I have no idea why this is happening I can't really give you any code samples. However, you can download the source code here: http://code.google.com/p/delphi-chrome-tabs/downloads/list.
Your control doesn't paint itself because you disable painting. You call BeginUpdate in the constructor, and you don't call EndUpdate until the Loaded method is called. But Loaded is only called when loading a control from a persisted state. Usually, we think of that as being when the control is loaded from a DFM file, but the IDE uses the same technique to allow putting controls on the clipboard.
You haven't noticed this before because, apparently, you only test your control by opening a pre-made demo project. The demo project has a control in its DFM file, so the only code path you exercise is the DFM case. You don't exercise the path where the constructor is called directly — when the control is first dropped on a form, or when the control is created "dynamically" in code.
To fix this, begin by getting rid of the BeginUpdate call in your constructor. Instead, to check whether your control is still in the process of being constructed, check csCreating in ControlState.
You can also get rid of your stsLoading state. Delphi already gives you that with the csLoading bit of ComponentState. Besides, your use of stsLoading is wrong since you set it in the constructor, just like you do with BeginUpdate.
Instead of relying on Loaded being called, you might wish to move certain code into the AfterConstruction method. Put code there that needs to run after your component is created but that has nothing to do with loading properties from a DFM (or other persistence source). I'm not sure I see anything in your Loaded method that really belongs there. Nearly all of it should be able to occur in the constructor.
You should also be aware of the CreateWnd method. It's called when your control's window handle gets allocated. That's where you should start allowing paint operations to occur. When you don't have a window handle, you have nothing to paint to.

How do I re-layout and re-paint a field when a Manager calls setPositionChild(Field)?

My class extends Manager and calls setPositionChild(Field f) to change f's position. After calling setPositionChild() method, how do I apply the position(i.e. re-layout and re-paint) so I can see the changes?
I tried to call invalidate(), which did not work.
invalidate() just forces a repaint, it doesn't redo the whole layout, as you noticed.
You can force a relayout by going up to the parent Screen object, and calling invalidateLayout(). Forcing the layout will almost certainly call setPositionChild() on the field you are trying to move, so you will want to make sure the new field position is preserved by the manager layout code. This may mean you need to write a custom manager.

blackberry layout change height of field

I have a custom field I have created that loads images from a url. What I would like to do is have the field take up no space and then when the image is loaded resize itself to the size of the image. I have almost everything done but I can't work out a way to get the layout to be re done after the image is loaded. It works if I specify the size of the image beforehand. Calling invalidateLayout on the parent will not work as the screen is visible, but just calling invalidate does nothing. What steps to I have to go through to make a field resize?
It would also be preferable if I could call the method on the custom view rather than the parent but this is not essential.
This is for blackberry 4.5.0.
First of all, you will have to invalidate the parent manager, because it does need the new size of your custom field in order to redraw correctly the whole manager. (If there is other fields in the manager after your custom one, or even a scroll).
In the top of my head, here's two solutions you can try to implement :
When your custom field is done downloading the image, call the parent manager to invalidate all fields in it (you will have to hold a reference to the parent manager in your custom field)
-- or --
create the custom field object, without adding it to the manager. Start downloading you image, when it is done, call a parent specific method that will add the custom field to the manager (you will still have to hold a reference to the parent manager in your custom field) (You can use insert if you want to add it between two field already present on the manager). Like that you will not have to resize the field, but only add it to the manager when it is ready to be shown.
Answer to your comment :
Then you should use the synchronized scope :
synchronized(UiApplication.getUiApplication().getEventLock())) {
// UI Code here
}
Basically in this scope, you should only use an invalidate, do your size change somewhere else, before this call.

Resources