我在书上看到这样一段自适应窗体的代码!
const displaywidth=800;
      displayheight=600;
type
  Tfooclass=class(Tcontrol);
//以下为Formcreate事件内写的代码:
var
 i:integer;
begin
 scaled:=true;
  if (screen.width<>displaywidth) then
    begin
      height:=longint(height)*longint(screen.height) div displayheight;
      width:=longint(width)*longint(screen.width) div displaywidth;
      scaleby(screen.width , displaywidth);
    end;
    for i:=controlcount-1 downto 0 do
    begin
      Tfooclass(controls[i]).Font.Size:=(newformwith div oldformwith)*Tfooclass(controls[i]).Font.Size;
    end;
end;
可是在调试过程中总是出现newformwith 和 oldformwith 没有定义,请教其在哪里定义
如果有好的方法请赐教,多谢!!!!!!!!!

解决方案 »

  1.   

    好像不需要这么烦,只要两行代码即可搞定  MainForm.AutoScroll:=False;
      Scaleby(Screen.Width,800);    //设计时屏幕设置为800*600  
      

  2.   

    procedure TfrmJtBaseScale.FormCreate(Sender: TObject);
    var
      i: integer;
      a: real;
    begin
      if Screen.Width <> DefaultWidth then
      begin
        height:=longint(height)*longint(screen.height) div DefaultHeight;
        width:=longint(width)*longint(screen.width) div DefaultWidth;
        scaleby(screen.width , DefaultWidth);
        for i := 0 to self.ControlCount -1 do
        begin
          a := screen.Height / DefaultHeight * TMyControl(self.Controls[i]).Font.Size;
          TMyControl(self.Controls[i]).Font.Size := trunc(a);
        end;
      end;
    end;
    用这个吧
      

  3.   

    不行呀,在改变字体大小的时候出现:
    DefaultHeight 和TMyControl未定义呀!!!!!
    再请教??