![]() |
|
#1
|
|||
|
|||
|
I afraid, I have never really got my head around passing parameters.
I want to scale my forms. I want to have a single procedure in fMain that works for all child forms with the on create event of that form. What is the correct Syntax ? Thanks Code:
procedure ScaleForm(FormName XXXXX);
var
rScale:Real;
begin
with FormName do begin
rScale:=Screen.Height/1000;
ScaleBy(Round(rScale*100),100);
Width:=Round(Width*rScale);
Height:=Round(Height*rScale);
Left:=Round((Screen.Width-Width)/2);
Top:=Round((Screen.Height-Height)/2);
end;
end;
procedure TfMembers.FormCreate(Sender: TObject);
begin
fMain.ScaleForm('fMembers');
end;
|
|
#2
|
|||
|
|||
|
You are sending the form as string. Better to send the object of the form.
Code:
procedure ScaleForm(FormName : TForm);
var
rScale:Real;
begin
with FormName do begin
rScale:=Screen.Height/1000;
ScaleBy(Round(rScale*100),100);
Width:=Round(Width*rScale);
Height:=Round(Height*rScale);
Left:=Round((Screen.Width-Width)/2);
Top:=Round((Screen.Height-Height)/2);
end;
end;
procedure TfMembers.FormCreate(Sender: TObject);
begin
fMain.ScaleForm(fMembers);
end;
__________________
Regards, Abdulaziz Jasser |
|
#3
|
|||
|
|||
|
Thanks I'll try it.
Really frustrated tonight. I work mainly on a 1400 x 1050 screen. I thought I would be clever and set my main form to a fixed 1250x1000 format and not allow scaling. Then I would use the FormScale routine on other screens to make it look reasonable . My laptop is 1280x768. I opened the same form in the Delphi IDE and Delphi changed the form's width and height by itself to something like 1023 x 760 So much for setting the scaling to false. You can't even force the form to the larger size even if you set in code with fmain.Width:=1250. It just ignores it. So any form I open on the laptop now has to be resized when I go back to the desktop. What a bugger. Any way to stop this ? |
|
#4
|
|||
|
|||
|
Im getting an error. Undeclared identifier ScaleForm.
Scaleform is at the top of my fMain code and fMain is created before my calling form so I'm not sure what is wrong. |
|
#5
|
|||
|
|||
|
Where is this "ScaleForm" procedure loated? In your code it should be located in fMain unit. Did you prototype it at the top of the main unit? Example:
Code:
type
TfMain = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
procedure ScaleForm(FormName : TForm); //The prototype of the proecure.
var
fMain: TfMain;
implementation
{$R *.dfm}
procedure ScaleForm(FormName : TForm);
var
rScale:Real;
begin
with FormName do begin
rScale:=Screen.Height/1000;
ScaleBy(Round(rScale*100),100);
Width:=Round(Width*rScale);
Height:=Round(Height*rScale);
Left:=Round((Screen.Width-Width)/2);
Top:=Round((Screen.Height-Height)/2);
end;
end;
__________________
Regards, Abdulaziz Jasser |
|
#6
|
|||
|
|||
|
I seem to have lost a posting.
[Error] uMembers.pas(140): Undeclared identifier: 'ScaleForm' Same thing if I use OnShow. Code:
begin Application.Initialize; Application.CreateForm(TfLogin, fLogin); Application.CreateForm(Tdm, dm); Application.CreateForm(TfMain, fMain); ....... Application.CreateForm(TfMembers, fMembers); ....... Application.Run; end. fMain Code:
{ Public declarations }
end;
procedure ScaleForm(FormName : TForm); //The prototype of the procedure.
var
fMain: TfMain;
implementation
uses uDM, uMembers, ......., uLogin;
{$R *.dfm}
procedure ScaleForm(FormName:tForm);
var
rScale:Real;
begin
with FormName do begin
width:=1250;
height:=1000;
rScale:=Screen.Height/1000;
ScaleBy(Round(rScale*100),100);
Width:=Round(1250*rScale);
Height:=Round(1000*rScale);
Left:=Round((Screen.Width-Width)/2);
Top:=Round((Screen.Height-Height)/2);
end;
end;
fMembers Code:
procedure TfMembers.FormCreate(Sender: TObject); begin fMain.ScaleForm(fMembers); end; |
|
#7
|
|||
|
|||
|
Tyr:
procedure TfMembers.FormCreate(Sender: TObject); begin ScaleForm(fMembers); end;
__________________
Regards, Abdulaziz Jasser |
|
#8
|
|||
|
|||
|
AND put "uMain" in the uses clause of "uMemebers".
__________________
Regards, Abdulaziz Jasser |
|
#9
|
|||
|
|||
|
That worked.
I would never have tried that option? It kind of goes againts all reasoning. If I use a DataModule dm both dm.tblTest.open and tblTest.open both work in the code. By the same reasoning, I would think fMain.ScaleForm and ScaleForm would have been the same. Thanks for the help. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|