XylemFlow 8 Posted October 23, 2023 (edited) I have created a TFrame at design time using the form designer. I then create several instances of the frame at run time. Is there a way to set a property of the underlying TFrame for all instances at once instead of having to iterate over all instances? For example, when a user changes the language at run time the captions and hints of the buttons in the TFrame need to be updated for all instances. Edited October 23, 2023 by XylemFlow Share this post Link to post
M.Joos 30 Posted October 23, 2023 I don't think there is an easy solution. If you really wanna go that route, you would need to intercept the instance creation process by e.g. overwriting the NewInstance method of your FrameXY class. Within that you could then add each created instance into a class var array or a class var TList. You could then e.g add a class procedure "SetLanguage" to your class from within you could iterate over all your instances and delegate this call to a regular instance method. Share this post Link to post
Uwe Raabe 2057 Posted October 23, 2023 Another approach would be to declare a TMessage descendant that the frame (and probably also any form) subscribes to during creation and unsubscribes from on destruction. Then you can broadcast this message when the language changes. uses System.Messaging; type TLanguageMessage = class(TMessage<string>); ... procedure TMyFrame.HandleLanguageMessage(const Sender: TObject; const M: TMessage); begin var msg := M as TLanguageMessage; SwitchToLanguage(M.Value); end; ... TMyFrame.Create FLanguageMessageID := TMessageManager.DefaultManager.SubscribeToMessage(TLanguageMessage, HandleLanguageMessage); ... TMyFrame.Destroy TMessageManager.DefaultManager.Unsubscribe(TLanguageMessage, FLanguageMessageID, True); ... NotifyLanguage TMessageManager.DefaultManager.SendMessage(nil, TLanguageMessage.Create('DE')); 2 Share this post Link to post