cast TObject using his ClassType?

前端 未结 5 1229
抹茶落季
抹茶落季 2021-01-13 07:27

how can i make my code to work ? :) i`ve tried to formulate this question but after several failed attempts i think you guys will spot the problem faster looking at the code

5条回答
  •  被撕碎了的回忆
    2021-01-13 08:01

    There is no need to cast to TMemo and TEdit separately, as they are both descendants from common parent class, which have ReadOnly property:

    procedure TForm1.FormCreate(Sender: TObject);
    
      procedure P(const Obj: TComponent);
      begin
        if Obj is TCustomEdit then
          TCustomEdit(Obj).ReadOnly := True;
      end;
    
    begin
      P(Memo1);
      P(Edit1);
    end;
    

提交回复
热议问题