Jump to content
Sign in to follow this  
dmitrybv

TRttiProperty.GetValue(TMemo) for CaretPosition raises 'Invalid class typecast' exception.

Recommended Posts

Hello.

The following code throws an 'Invalid class typecast' exception.

 

procedure TForm1.Button1Click(Sender: TObject);
var
  RttiContext: TRttiContext;
  LType: TRttiType;
  ACaretPositionProp: TRttiProperty;
  Val: TValue;
begin
  RttiContext := TRttiContext.Create;
  LType := RttiContext.GetType(TMemo);
  ACaretPositionProp := LType.GetProperty('CaretPosition');
  Val := ACaretPositionProp.GetValue(Memo1);
end;

 

Although it shouldn't.

 

Place a TMemo and a TButton on a Form and write the Button.OnClick event as described above.

 

Embarcadero® RAD Studio 12 Version 29.0.53571.9782

 Delphi 12 Update 2.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×