Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2012, 06:55 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default Passing parameters to procedures.

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;
Reply With Quote
  #2  
Old 07-21-2012, 10:59 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,773
Default

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
Reply With Quote
  #3  
Old 07-21-2012, 12:06 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

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 ?
Reply With Quote
  #4  
Old 07-22-2012, 06:19 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

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.
Reply With Quote
  #5  
Old 07-22-2012, 08:25 AM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,773
Default

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
Reply With Quote
  #6  
Old 07-22-2012, 08:39 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

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;
Reply With Quote
  #7  
Old 07-22-2012, 09:25 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,773
Default

Tyr:

procedure TfMembers.FormCreate(Sender: TObject);
begin
ScaleForm(fMembers);
end;
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #8  
Old 07-22-2012, 09:26 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,773
Default

AND put "uMain" in the uses clause of "uMemebers".
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
  #9  
Old 07-22-2012, 09:34 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 09:58 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.