这个单元在我的程序中是作为一个公用单元来调用的, 在别的窗体中调用这个单元,但这个公用单元这样写好象有错编译通不过呀, 请帮忙改下,请指教!unit Unit2;interfaceuses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs;type TMyClass = Class(TObject) public procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); end; const ScreenHeight: integer = 1024; ScreenWidth: integer = 768;implementationprocedure TMyClass.FormCreate(Sender: TObject); var x, y: LongInt; begin form1.scaled := true; //有错 x := getSystemMetrics(SM_CXSCREEN); y := getSystemMetrics(SM_CYSCREEN); if (x <> ScreenHeight) or (y <> ScreenWidth) then begin form1.height:=form1.height*x DIV ScreenHeight; //有错 form1.width:=form1.width*y DIV ScreenWidth; //有错 scaleBy(x,ScreenHeight); end; end;procedure TMyClass.FormClose(Sender: TObject; var Action: TCloseAction); var x, y: LongInt; begin form1.scaled := true; //有错 x := getSystemMetrics(SM_CXSCREEN); y := getSystemMetrics(SM_CYSCREEN); if (x <> ScreenHeight) or (y <> ScreenWidth) then begin form1.height:=form1.height*x DIV ScreenHeight; //有错 form1.width:=form1.width*y DIV ScreenWidth; //有错 scaleBy(x,ScreenHeight); end; end;end.
你其他窗体调用的时候 要引用这个单元 然后在创建TMyClass这个类的实例
编译通过 unit Unit2;interfaceuses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs;type TMyClass = Class(TObject) public procedure FormCreate(form: Tform); procedure FormClose(form: Tform; var Action: TCloseAction); end; const ScreenHeight: integer = 1024; ScreenWidth: integer = 768;implementationprocedure TMyClass.FormCreate(form: Tform); var x, y: LongInt; begin form.scaled := true; //Óдí x := getSystemMetrics(SM_CXSCREEN); y := getSystemMetrics(SM_CYSCREEN); if (x <> ScreenHeight) or (y <> ScreenWidth) then begin form.height:=form.height*x DIV ScreenHeight; //Óдí form.width:=form.width*y DIV ScreenWidth; //Óдí form.ScaleBy(x,ScreenHeight); end; end;procedure TMyClass.FormClose(form: Tform; var Action: TCloseAction); var x, y: LongInt; begin form.scaled := true; //Óдí x := getSystemMetrics(SM_CXSCREEN); y := getSystemMetrics(SM_CYSCREEN); if (x <> ScreenHeight) or (y <> ScreenWidth) then begin form.height:=form.height*x DIV ScreenHeight; //Óдí form1.width:=form1.width*y DIV ScreenWidth; //Óдí form.ScaleBy(x,ScreenHeight); end; end;end.
在别的窗体中调用这个单元,但这个公用单元这样写好象有错编译通不过呀,
请帮忙改下,请指教!unit Unit2;interfaceuses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs;type
TMyClass = Class(TObject)
public
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
end;
const
ScreenHeight: integer = 1024;
ScreenWidth: integer = 768;implementationprocedure TMyClass.FormCreate(Sender: TObject);
var
x, y: LongInt;
begin
form1.scaled := true; //有错
x := getSystemMetrics(SM_CXSCREEN);
y := getSystemMetrics(SM_CYSCREEN);
if (x <> ScreenHeight) or (y <> ScreenWidth) then
begin
form1.height:=form1.height*x DIV ScreenHeight; //有错
form1.width:=form1.width*y DIV ScreenWidth; //有错
scaleBy(x,ScreenHeight);
end;
end;procedure TMyClass.FormClose(Sender: TObject; var Action: TCloseAction);
var
x, y: LongInt;
begin
form1.scaled := true; //有错
x := getSystemMetrics(SM_CXSCREEN);
y := getSystemMetrics(SM_CYSCREEN);
if (x <> ScreenHeight) or (y <> ScreenWidth) then
begin
form1.height:=form1.height*x DIV ScreenHeight; //有错 form1.width:=form1.width*y DIV ScreenWidth; //有错
scaleBy(x,ScreenHeight);
end;
end;end.
unit Unit2;interfaceuses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs;type
TMyClass = Class(TObject)
public
procedure FormCreate(form: Tform);
procedure FormClose(form: Tform; var Action: TCloseAction);
end;
const
ScreenHeight: integer = 1024;
ScreenWidth: integer = 768;implementationprocedure TMyClass.FormCreate(form: Tform);
var
x, y: LongInt;
begin
form.scaled := true; //Óдí
x := getSystemMetrics(SM_CXSCREEN);
y := getSystemMetrics(SM_CYSCREEN);
if (x <> ScreenHeight) or (y <> ScreenWidth) then
begin
form.height:=form.height*x DIV ScreenHeight; //Óдí
form.width:=form.width*y DIV ScreenWidth; //Óдí
form.ScaleBy(x,ScreenHeight);
end;
end;procedure TMyClass.FormClose(form: Tform; var Action: TCloseAction);
var
x, y: LongInt;
begin
form.scaled := true; //Óдí
x := getSystemMetrics(SM_CXSCREEN);
y := getSystemMetrics(SM_CYSCREEN);
if (x <> ScreenHeight) or (y <> ScreenWidth) then
begin
form.height:=form.height*x DIV ScreenHeight; //Óдí form1.width:=form1.width*y DIV ScreenWidth; //Óдí
form.ScaleBy(x,ScreenHeight);
end;
end;end.
FormClose函数的第二个参数var Action: TCloseAction去掉,函数中没有用到