📄 commonunit.pas
字号:
unit CommonUnit;
interface
uses
Controls,Forms,Graphics,
SysUtils,TypInfo,Math;
procedure RecordProcess(VarObject:TObject);
procedure ResizeProcess(VarObject:TObject);
function PropertiyExists(VarObject:TObject;VarPropertiyName:string):Boolean;
implementation
type TControlHack=class(TControl);
//在调用ResizeProcess函数前先调用本函数,保存窗口、控件参数
//参数1 varobject需要记录参数的窗口或控件
procedure RecordProcess(VarObject:TObject);
var
I:Integer;
begin
(VarObject as TForm).Hint:=(VarObject as TForm).Hint+'|'+IntToStr((VarObject as TForm).width)+';'+IntToStr((VarObject as TForm).height)+';'+IntToStr((VarObject as TForm).font.size);
for I:=0 to (VarObject as TForm).ComponentCount -1 do
begin
if (VarObject as TForm).Components[I].InheritsFrom(TControl) then
begin
((VarObject as TForm).Components[I] as TControl).Hint:=((VarObject as TForm).Components[I] as TControl).Hint+'|'+IntToStr(((VarObject as TForm).Components[I] as TControl).left)+';'+IntToStr(((VarObject as TForm).Components[I] as TControl).top)+';'+IntToStr(((VarObject as TForm).Components[I] as TControl).width)+';'+IntToStr(((VarObject as TForm).Components[I] as TControl).height);
//判断组件是否具有Font属性
if PropertiyExists((VarObject as TForm).Components[I],'Font') then
((VarObject as TForm).Components[I] as TControl).Hint:=((VarObject as TForm).Components[I] as TControl).Hint+';'+IntToStr(TControlHack((VarObject as TForm).Components[I] as TControl).Font.size);
end;
end;
end;
//在调用本函数前先调用RecordProcess函数,按比例改变窗口内各控件的大小、字号
//参数1 varobject需要缩放处理的窗口或控件
procedure ResizeProcess(VarObject:TObject);
var
I:Integer;
VarRateX:double;
VarRateY:double;
VarString:String;
begin
VarString:=(VarObject as TForm).Hint;
if pos('|',VarString)<>0 then delete(VarString,1,pos('|',VarString));
if pos('|',VarString)<>0 then delete(VarString,1,pos('|',VarString));
VarRateX:=((VarObject as TForm).width)/StrToInt(copy(VarString,0,pos(';',VarString)-1));
if pos(';',VarString)<>0 then delete(VarString,1,pos(';',VarString));
VarRateY:=((VarObject as TForm).height)/StrToInt(copy(VarString,0,pos(';',VarString)-1));
if pos(';',VarString)<>0 then delete(VarString,1,pos(';',VarString));
(VarObject as TForm).font.size:=Round(int(StrToInt(VarString)*min(VarRateX,VarRateY)));
for I:=0 to (VarObject as TForm).ComponentCount -1 do
begin
if (VarObject as TForm).Components[I].InheritsFrom(TControl) then
begin
VarString:=((VarObject as TForm).Components[I] as TControl).Hint;
if pos('|',VarString)<>0 then delete(VarString,1,pos('|',VarString));
if pos('|',VarString)<>0 then delete(VarString,1,pos('|',VarString));
((VarObject as TForm).Components[I] as TControl).left:=Round(int(StrToInt(copy(VarString,0,pos(';',VarString)-1))*VarRateX));
if pos(';',VarString)<>0 then delete(VarString,1,pos(';',VarString));
((VarObject as TForm).Components[I] as TControl).top:=Round(int(StrToInt(copy(VarString,0,pos(';',VarString)-1))*VarRateY));
if pos(';',VarString)<>0 then delete(VarString,1,pos(';',VarString));
((VarObject as TForm).Components[I] as TControl).width:=Round(int(StrToInt(copy(VarString,0,pos(';',VarString)-1))*VarRateX));
if pos(';',VarString)<>0 then delete(VarString,1,pos(';',VarString));
if pos(';',VarString)=0 then
//判断组件不具有Font属性
begin
((VarObject as TForm).Components[I] as TControl).height:=Round(int(StrToInt(VarString)*VarRateY));
end
else
//判断组件是否具有Font属性
if PropertiyExists((VarObject as TForm).Components[I],'Font') then
begin
((VarObject as TForm).Components[I] as TControl).height:=Round(int(StrToInt(copy(VarString,0,pos(';',VarString)-1))*VarRateY));
delete(VarString,1,pos(';',VarString));
TControlHack((VarObject as TForm).Components[I] as TControl).Font.size:=Round(int(StrToInt(VarString)*min(VarRateX,VarRateY)))
end;
end;
end;
end;
//判断组件是否具有某属性的函数
function PropertiyExists(VarObject:TObject;VarPropertiyName:string):Boolean;
begin
PropertiyExists:=False;
try
PropertiyExists:=Assigned(GetPropInfo(VarObject,VarPropertiyName));
except
Exit;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -