WalkingAway 1 Posted September 13, 2023 Is it possible to get / set through RTTI non standard type value? I tries, but always got something like 'invalid tapecast' error. Let say I have TFrameMeta<T: TFrame> = class(TGlobalMeta) TGlobalMeta here is: TGlobalMeta = class private What I want - to unified opportunity to set / get "Meta" value , it can be FirstFrame.Meta, SecondFrame.Meta, ... Now I have to write if FirstFrame.Meta is AccountFrame then ... else if FirstFrame.Meta is ReportFrame If I have 50 frames it is too boring. RTTI may help me Or maybe mnthere some libraries for that Thank a lot Also I want to link that kind of link to "Meta" to listview (TValue.From) for same purpose. With no success also so far... Share this post Link to post
Remy Lebeau 1436 Posted September 13, 2023 2 hours ago, WalkingAway said: Is it possible to get / set through RTTI non standard type value? I tries, but always got something like 'invalid tapecast' error. Can you show the actual code you are having trouble with? 2 hours ago, WalkingAway said: What I want - to unified opportunity to set / get "Meta" value , it can be FirstFrame.Meta, SecondFrame.Meta, ... What is "Meta" defined as? 2 hours ago, WalkingAway said: Now I have to write if FirstFrame.Meta is AccountFrame then ... else if FirstFrame.Meta is ReportFrame What is it you are trying to do with "Meta", exactly? We can't really help you without more detail. 2 hours ago, WalkingAway said: If I have 50 frames it is too boring. RTTI may help me Or maybe mnthere some libraries for that Or maybe just re-think your design? Perhaps interfaces are more suitable? Hard to say without seeing what you are actually trying to do. 2 hours ago, WalkingAway said: Also I want to link that kind of link to "Meta" to listview (TValue.From) for same purpose. With no success also so far... I'm sure there are ways to accomplish that, but again, it really depends on what your data looks like and how you are using it. Share this post Link to post
WalkingAway 1 Posted September 14, 2023 I have here such a sample app. This app using StandFrame component, but it can be plain / pure frame based app. Main question here is: Every frame has "meta" - information about itself (managed by FrameStand), and code is basically the same: procedure TMainForm.PictureButtonClick(Sender: TObject); var LFrameInfo: TFrameInfo<TPictureFrame>; begin LFrameInfo := FrameStand1.New<TPictureFrame>(); LFrameInfo.Frame.Description := 'Example description'; LFrameInfo.Show; end; procedure TMainForm.TextButtonClick(Sender: TObject); var LFrameInfo: TFrameInfo<TTextFrame>; begin LFrameInfo := FrameStand1.New<TTextFrame>(); LFrameInfo.Frame.Text := 'Example text'; LFrameInfo.Show; end; What I did here - one method for all frames (working) function GetFrameInfo<T>: TFrameInfo<T>; begin Result := FrameStand1.New<T>(); Result.Show; end; I'm able to set via RTTI "Text" property in one frame and "Description" in other as they are strings. For simple types it easy. But let's consider there property "MainFrame", it's type is TFrameInfo<T> or TFrameInfo<TFrame>. How to set it with RTTI? Because then I want to link it in the same manner to ListView like AItem.Data[ 'freame_info' ].AsType< TFrameInfo< TFrame > >; And then by clicking to open according frame. I don't entirely understand how to make RTTI understand my TFrameInfo<TFrame >> Thanks in advance demo.zip Share this post Link to post