Setting the Size of a Modal Form called by a Main Form

Why do I get an error for clicking on btnMaxClick?


{code}
unit uEnv;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs;

type
  TfrmEnv = class(TForm)
    img0101: TImageControl;
    img0201: TImageControl;
    img0301: TImageControl;
    img0401: TImageControl;
    img0501: TImageControl;
    img0601: TImageControl;
    img0701: TImageControl;
    img0102: TImageControl;
    img0202: TImageControl;
    img0302: TImageControl;
    img0402: TImageControl;
    img0502: TImageControl;
    img0602: TImageControl;
    img0702: TImageControl;
    btnGo: TButton;
    btnMax: TButton;
    procedure btnGoClick(Sender: TObject);
    procedure mRefreshForm(Sender: TObject);
    procedure btnMaxClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmEnv: TfrmEnv;

implementation

{$R *.fmx}

procedure TfrmEnv.btnGoClick(Sender: TObject);
begin
  mRefreshForm(Sender);

end;

procedure TfrmEnv.btnMaxClick(Sender: TObject);
begin
 frmEnv.ClientWidth := 1600;
 frmEnv.ClientHeight := 900;
end;

procedure TfrmEnv.mRefreshForm(Sender: TObject);
var
  i : Integer; // loop incrementer
  iCol : Integer;
  iRow : Integer;
  xColRow : String;
  himgControl : TImageControl;

begin

  iCol := 1;
  iRow := 1;
  xColRow := 'img' + Format('%.2d', [iCol]) + Format('%.2d', [iRow]);

  for i := 1 to 7 do
  begin
    xColRow := 'img' + Format('%.2d', [iCol]) + Format('%.2d', [iRow]);
    himgControl := FindComponent(xColRow) as TImageControl;
    himgControl.Position.X := (51 * iCol) - 50;
    himgControl.Position.Y := 1;
    iCol := iCol + 1;
  end;

end;

end.

{code}
0
Thomas
2/15/2013 11:02:13 PM
embarcadero.delphi.firemonkey 4901 articles. 4 followers. Follow

14 Replies
1471 Views

Similar Articles

[PageSpeed] 7
Get it on Google Play
Get it on Apple App Store

Le 15/02/13 23:02, Thomas Clark a écrit :

> Why do I get an error for clicking on btnMaxClick?

Well, you don't specify the error, but I can guess that is has something 
to do with access violation.

> {code}
> var
>    frmEnv: TfrmEnv;
>
> implementation
>
> {$R *.fmx}
>
> procedure TfrmEnv.btnGoClick(Sender: TObject);
> begin
>    mRefreshForm(Sender);
>
> end;
>
> procedure TfrmEnv.btnMaxClick(Sender: TObject);
> begin
>   frmEnv.ClientWidth := 1600;
>   frmEnv.ClientHeight := 900;
> end;
> {code}

What you are doing is accessing the var frmEnv, which has not been 
instantiated.

All Delphi classes have an intrinsic "self" variable, which you use to 
access the current instance of the class.

The var that is "helpfully" included in the unit template should be 
completely removed and never, ever used.

The only time you keep that var is for the main form of the app, since 
that is what is referenced in the Application.CreateForm call in the 
..dpr file.

Your code should read:

{code}
procedure TfrmEnv.btnMaxClick(Sender: TObject);
begin
   self.ClientWidth := 1600;
   self.ClientHeight := 900;
end;
{code}

Joanna

-- 
Joanna Carter [Team OOAD]
0
Joanna
2/15/2013 11:46:49 PM
Joanna Carter (Team OOAD) wrote:

> Your code should read:
> 
> {code}
> procedure TfrmEnv.btnMaxClick(Sender: TObject);
> begin
>    self.ClientWidth := 1600;
>    self.ClientHeight := 900;
> end;
> {code}

The self part isn't really needed and can be omitted.

PS You misspelled Self ;-)

-- 
Pieter

"He loves nature in spite of what it did to him." 
 -- Forrest Tucker
0
Pieter
2/16/2013 12:40:01 AM
Joanna and All:

It's alive!  Meaning it works!  Thanks again.  I promise that these baby steps will sink in for me.  

Okay next question, which I hope is easy...   How do I get self.WindowState.wsMaximized to work?  I have tried every combination I can think of and a crawler search and nada.

Also, I was pretty sure my error with manually setting the height and width of the form would be readily apparent to an experienced programmer since there was only two lines of code in the button max click procedure.  If it hadn't been isolated in this way I definitely would have included the error.  Sorry if this caused any problems.

I did remove the " var frmEnv : TfrmEnv".  I understand now that it was declared but not instantiated.  Further, that there is no need because of the 'self'' thing.  Just so I get a grip on programming terms is self more accurately described as a variable, handle, or something else?  Also, purely for educational purposes (not to be used here) how would I have instantiated the frmEnv?

Finally, is there a Firemonkey guide that indexes all the properties and methods and shows actual code examples of how to make use of the firemonkey objects/classes?

I am so frustrated with the Delphi help file... here's the relevant part of the entry:

{code}
property WindowState default TWindowState.wsNormal;

Set WindowState to minimize, maximize, or restore the form window. Read WindowState to determine whether the form is minimized, maximized, or in a normal state. 

Possible values for the WindowState property are: 

wsMaximized 
wsMinimized 
wsNormal 
{code}

So I know I can manipulate it, but for the life of me I can't figure out how to change the WindowState.  I've tried self.WindowState := wsMaximized; self.WindowState := wsMaximized; self.WindowState.wsMaximized, etc. and so forth all to no avail.  There has got to be a handy reference out there.

Edited by: Thomas Clark on Feb 16, 2013 8:26 AM
0
Thomas
2/16/2013 4:26:40 PM
Peiter and All:

Yah that seems to work without, but I think it's probably a good idea for me to use 'self' handle.  By typing self and then a period the autocomplete feature kicks into gear and it is helpful to make sure you are not making a spelling error and to see what one's options are.  

FoxPro had the same thing but it was called 'thisform'.  Not necessary but very handy to navigate your way through properties, events, and methods.

> {quote:title=Pieter Zijlstra wrote:}{quote}
> The self part isn't really needed and can be omitted.
0
Thomas
2/16/2013 4:35:18 PM
Le 16/02/13 16:26, Thomas Clark a écrit :

> Okay next question, which I hope is easy... How do I get
> self.WindowState.wsMaximized to work? I have tried every combination
> I can think of and a crawler search and nada.

If you want to maximise the window, set self.WindowState := wsMaximised?

> I did remove the " var frmEnv : TfrmEnv". I understand now that it
> was declared but not instantiated. Further, that there is no need
> because of the 'self'' thing. Just so I get a grip on programming
> terms is self more accurately described as a variable, handle, or
> something else?

All classes include "self", which is a reference to the current instance 
of the class in which you are writing code.

Do you know about and understand object-oriented programming principles 
yet? If not, just ask and we can point you in the right direction :-)

> Also, purely for educational purposes (not to be used
> here) how would I have instantiated the frmEnv?

If you look at the .dpr file, you will see it gets used there to 
automatically instantiate every form class that you write. This is so 
wrong because it means that even form classes that never get called 
still get created and consume memory.

> Finally, is there a Firemonkey guide that indexes all the properties
> and methods and shows actual code examples of how to make use of the
> firemonkey objects/classes?

Well, you could check the Wiki but, from what I can gather from those 
who use it, it is far from comprehensive and there are not that many 
examples.

> I am so frustrated with the Delphi help file... here's the relevant
> part of the entry:
>
> {code}
> property WindowState default TWindowState.wsNormal;
>
> Set WindowState to minimize, maximize, or restore the form window.
> Read WindowState to determine whether the form is minimized, maximized,
> or in a normal state.
>
> Possible values for the WindowState property are:
>
> wsMaximized
> wsMinimized
> wsNormal
> {code}
>
> So I know I can manipulate it, but for the life of me I can't figure
> out how to change the WindowState.  I've tried self.WindowState :=
> wsMaximized; self.WindowState := wsMaximized;
> self.WindowState.wsMaximized, etc. and so forth all to no avail.
> There has got to be a handy reference out there.

I'm sorry but it is several years since I used Delphi and, apart from 
the syntax I mentioned earlier, I can't remember enough about the VCL - 
my speciality is teaching OO but I do remember how to write Delphi code ;-)

Joanna

-- 
Joanna Carter [Team OOAD]
0
Joanna
2/16/2013 4:46:49 PM
Le 16/02/13 16:35, Thomas Clark a écrit :

> Yah that seems to work without, but I think it's probably a good idea
> for me to use 'self' handle.

If I may correct you here... unless you are doing "under the hood" stuff 
with forms, you are very unlikely to use handles - there is only ever 
one per form and, for what you are doing, you don't need to touch it.

I suppose you could call "self" a variable but it is intrinsic to a 
class and should never (normally) be assigned to, only referenced.

Any "variable" that is declared in a class is, more properly, called a 
field.

The term "variable" normally refers to those variables declared 
following a var marker at the beginning of a method.

Joanna

-- 
Joanna Carter [Team OOAD]
0
Joanna
2/16/2013 4:56:06 PM
Thomas Clark wrote:

>By typing self and then a period the autocomplete feature kicks into
>gear and it is helpful to make sure you are not making a spelling
>error and to see what one's options are.

Just can type ctrl-space to activate code completion whereever you want
(you dont need to type self).
0
Marius
2/16/2013 4:57:24 PM
Le 16/02/13 16:57, Marius . a écrit :

> Just can type ctrl-space to activate code completion whereever you want
> (you dont need to type self).

The only problem with doing this, without a preceding "variable" and 
dot, is that you tend to get a massive list of everything available, not 
just the form class's members.

Joanna

-- 
Joanna Carter [Team OOAD]
0
Joanna
2/16/2013 5:01:14 PM
Joanna Carter (Team OOAD) wrote:

>The only problem with doing this, without a preceding "variable" and 
>dot, is that you tend to get a massive list of everything available,
>not just the form class's members.

True. For the lazy typers, "self" is always the first item in the list
;)
0
Marius
2/16/2013 5:27:28 PM
> {quote:title=Joanna Carter (Team OOAD) wrote:}{quote}
> Le 16/02/13 16:26, Thomas Clark a écrit :
> 
> If you want to maximise the window, set self.WindowState := wsMaximised?

I tried precisely that and get an error.

{code}
procedure TfrmEnv.btnMaxClick(Sender: TObject);
begin
 self.WindowState := wsMaximized;
 self.ClientWidth := 1600;
 self.ClientHeight := 900;
end;
{code}

and the resulting error is:

{code}
[DCC Error] uEnv.pas(52): E2003 Undeclared identifier: 'wsMaximized'
{code}

I also tried this (and many other variations):

{code}
procedure TfrmEnv.btnMaxClick(Sender: TObject);
begin
 self.WindowState.wsMaximized;
 self.ClientWidth := 1600;
 self.ClientHeight := 900;
end;
{code}

and the resulting error is:

{code}
[DCC Error] uEnv.pas(52): E2018 Record, object or class type required
{code}


Note: My installation has wsMaximiZed not wsMaximiSed under the object inspector for that property.

Edited by: Thomas Clark on Feb 16, 2013 11:32 AM
0
Thomas
2/16/2013 7:36:09 PM
Le 16/02/13 19:36, Thomas Clark a écrit :

> Note: My installation has wsMaximiZed not wsMaximiSed under the object inspector for that property.

OK, I just did a quick Google for "FireMonkey maximize form" and, 
amongst others, I got this...

https://forums.embarcadero.com/message.jspa?messageID=408494#408494

As you will see, Delphi enumerations now take the enum type as well as 
the value.

i.e.

self.WindowState := TWindowState.wsMaximized

Sorry about the spelling of maximised, I tend to forget Americans can't 
spell <gd&r>

Joanna

-- 
Joanna Carter [Team OOAD]
0
Joanna
2/16/2013 7:46:21 PM
> {quote:title=Joanna Carter (Team OOAD) wrote:}{quote}
> Do you know about and understand object-oriented programming principles 
> yet? If not, just ask and we can point you in the right direction :-)

I would say my knowledge of OOP is imperfect.  I understand inheritance.  I understand if you want to use a class you instantiate it and it becomes an object that you can address at runtime (and design time if the IDE allows it).  In Foxpro I created my own edtBox classes based upon the parent class.  I added properties to the edtBox.  I even created non-visual objects that held application methods and properties.  For instance oApplication.Version would hold the version number of my program.  Once the no
n-visual object was instantiated globally in the main program all the forms would be able to see it.  I can't remember all the properties and methods that eventually made it into my oApplication because it has been 10 years ago or so since I did anything major with FoxPro.
0
Thomas
2/16/2013 7:46:27 PM
Yay, that worked perfect. I searched Delphi WindowState and came up with stuff that didn't work.

But to my larger point.  I wish the help file actually showed you the simple example instead of:

{code}
property WindowState: TWindowState read FWindowState write SetWindowState default TWindowState.wsNormal;

Description
Represents how the form appears on the screen. 

Set WindowState to minimize, maximize, or restore the form window. Read WindowState to determine whether the form is minimized, maximized, or in a normal state. 

Possible values for the WindowState property are: 

wsMaximized 
wsMinimized 
wsNormal 
{code}

It sure would make learning this a whole lot easier.  :)

> {quote:title=Joanna Carter (Team OOAD) wrote:}{quote}
> Le 16/02/13 19:36, Thomas Clark a écrit :
> 
> > Note: My installation has wsMaximiZed not wsMaximiSed under the object inspector for that property.
> 
> OK, I just did a quick Google for "FireMonkey maximize form" and, 
> amongst others, I got this...
> 
> https://forums.embarcadero.com/message.jspa?messageID=408494#408494
> 
> As you will see, Delphi enumerations now take the enum type as well as 
> the value.
> 
> i.e.
> 
> self.WindowState := TWindowState.wsMaximized
> 
> Sorry about the spelling of maximised, I tend to forget Americans can't 
> spell <gd&r>

Now that's Funny!
0
Thomas
2/16/2013 7:59:56 PM
Le 16/02/13 19:59, Thomas Clark a écrit :

> Yay, that worked perfect. I searched Delphi WindowState and came up
> with stuff that didn't work.
>
> But to my larger point.  I wish the help file actually showed you the
> simple example instead of:
>
> {code}
> property WindowState: TWindowState read FWindowState write
> SetWindowState default TWindowState.wsNormal;
>
> Description Represents how the form appears on the screen.
>
> Set WindowState to minimize, maximize, or restore the form window.
> Read WindowState to determine whether the form is minimized,
> maximized, or in a normal state.
>
> Possible values for the WindowState property are:
>
> wsMaximized wsMinimized wsNormal
> {code}
>
> It sure would make learning this a whole lot easier.  :)

Indeed, it looks like the help could do with some help ;-)

Given this poor level of documentation, in this case, I think the way 
you need to work with it is to check the type of the property and, even 
though there was no link or explanation, to go on to look up the type of 
the property, which is how I found the answer.

Obviously this is help for those who know what to look for - not much 
fun though :-(

Joanna

-- 
Joanna Carter [Team OOAD]
0
Joanna
2/16/2013 8:49:32 PM
Reply:

Similar Artilces:

Setting Main Form and Calling Another Form
Hi All: Again, I am new to Delphi. I am using XE2 Pro. I am attempting my first app. I want it to have multiple forms, with the Main form calling other forms. How do I set which form is the form that opens at the start of application? How do I get frmMain to call frmSecondary? Thanks in advance. > {quote:title=Thomas Clark wrote:}{quote} > Hi All: > > Again, I am new to Delphi. I am using XE2 Pro. > > I am attempting my first app. I want it to have multiple forms, with the Main form calling other forms. > > How do I set which form is the f...

How do I mark a form as being the main form? Main form drop down is blank!
So I found online that I can go to Project->Options The Under Forms, pick the main form. The problem is that the Main form drop down is blank, all the forms appear under 'Available forms' but just not in that drop down. any thoughts? Thank you! Matt You have to have the following code on your main form: void setAsMainForm() { TfrmMain::SetAsMainForm(); } on your main form. IW does this automatically when you create a new project. I usually just rename the created form to whatever I want the main form named. On 7/23/2012 6:54 AM, Matthew Czarnek wrote: >...

Calling a form from different forms as modal ...
Hii want to write a form which user chooses some values from itand make it modal (which user can't do anything else on this site without  closing or choosing something.)it can be done with module popup extender on the same page.But i want to call the same popup (or form) from several forms without rewritten it. how can i do this ?.. fer  inherits? register popup scripts from server?...

Modal form, how to notice click on main form
Problem: I need a form which drops down similar to a combo box. When one clicks on an area outside this form, this form should close again. Trial: I tried first to handle this with a modeless form and the LostFocus event but the problem is that the form itself includes buttons for child forms which get the focus then. Besides i want the return value which would make life easier for me dealing with a modeless dialog. Question: Now is there any way to get a feedback if the user tries to click on the main form? You get a system beep when you do this, is the operating system laun...

Modal form not closing when form.modalresult is set to 1... ??
I've got a form which I show modally at program startup... it's a program registration form that permits the user to enter a product key, similar to the same thing seen in many other programs. The form is opened with: *regform.showmodal;* and within the regform, after the product key is entered (or not), it should be closing down with the following statement: *regform.modalresult:=1;* However, the form doesn't dissapear.... it's still behind the main form, and if the main form is minimized, it's still visible. In the project source, this form is created just bef...

Forms or No Forms
Hope this isn't a repeat.  I looked and didn't find anything. Say for example you had a web page with around 20 fields retrive and update to a database with differing datatypes.  Some fields will have some special controls (dropdowns, radios, buttons, etc) that interact with other parts of the page.  What is the best and/or most efficient code to make the page. Would you use a Formview bound to a standard ADO.net SQL connection and edit the templates. Use a Formview bound to an Object Data Source and edit within the templates. Or use an Object Data Source and bind the...

How do I know the called form is returned to the calling form?
My FormA called FormB. When FormB is released, the calling form(FormA) can drive any event, or any kind of method to know that? You could do it by setting and checking a variable in the UserSession. FormB could set a value like UserSession.FormBKilled : Boolean. FormA could then check that value and act upon it. The other option would be to have form B call a method, or set a value, on FormA before it gets destroyed. procedure TFormB.ExitBtnClick(sender: TObject); var AForm : TIWForm; begin WebApplication.SetActiveForm(WebApplication.FindComponent('FormA') as TIWContai...

Can you make Forms semi-modal then postback to calling form??
I leave a Sales form to go to a Sales Item Wizard form. We'd like to make the Wizard modal in the sense that the user must finish building the order before returning or doing anything else. While on the Wizard Form, the user clicks server side dropdown boxes to help build the order. This seems to kill the modality of the form. The data created by the Wizard is currently sent to session variables. We've tried Javascript, but the modality still dies when making trips to the server to run dropdownsboxes. How can I call a Form and make it modal until the user has selected from 3 or...

Changing Modal Forms to Non-modal Forms
Hello, How can one change a form, created as a modal form, to become a non-modal form? Cheers, -Bill hi: use a text editor to change WDialog to WModelessDialog in the following line in the .wxf file of the form: @begin Object "Powersoft_WCM::WDialog" It's the 3rd or 4th line in the file. William Burdgick wrote in message <36C65E90.DBF0DE93@2xtreme.net>... >Hello, > >How can one change a form, created as a modal form, to become a >non-modal form? > >Cheers, >-Bill > We use a routine called SetModal to set the mo...

Tooltip displayed as part of the main form instead of the child modal form
I have a main form that I open. Then, from that form I open another form that is modal but is still part of the same application and shares the same taskbar button as the main form. The problem is, when I hover over the controls on the modal form that have tooltips, the modal form gets sent to the back and the main form comes to the front. The tooltip box is now displayed as part of the main form and not the modal form. How can I fix this so that the modal form remains in the front of the main form an d the tooltip box appears as part of the modal form and not the main form? Andy Smith ...

form within form
The form in the content page is simply accessing an ajax/google javascript function, but because the master page has the "form... runat=server" bit in it, when the form in the content page is submitted, it submits the main form, not the google map form!  I don't want any postback on the google content page javascript form, just a "<form name="addr" method="post" action="" onsubmit="javascript:..." so that it simply runs the javascript on the page without a post back... I investigated "attribute.add" but it seems I ...

Independent Forms of the Main Form
Hi... Im creating a form independent of the main form. But when that form call another modal form, i want to that modal only "locks" the indepent form, and not the entire application. I´ve tried to use PopupParent property, but didnt have effect or im using in the wrong way. To do that im doing this: // FORM 1: The main form type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; procedure TForm1.Button1Click(Sender: TObject); be...

Positioning a form relative to a calling form
I'm ShowModal-ing a form, and in the Show event I open and show a from that I'm using as a data-entry toolbar. The problem is setting the position relative to the modal form. I try to capture the current position of the modal form in a TPoint, but I seem to be getting the original design position, not the current position. And that's a problem on monitors with lower resolution than my development box because it pushes the toolbar form to the right. The modal form is poMainFormCenter. The called/toolbar form is poDesigned. In my OnShow handler in the modal form: ...

How to pass a set of values from form to form
I have a winform that opens another form when the user presses F1 in a textbox. The user is suposed to select a row from a list of options in a datagrid. I want to get the values he selected and bring them to the winform where he pressed F1. The problem is that I don't know how to pass a value or a set of values from form to form. Could you help me? Sample code would be perfect ;) Thanks in advance. Hi, Check this Article. This Also, this Article might be of use to you. Thanks.regards,Harishhttp://geekswithblogs.net/ranganh...

Web resources about - Setting the Size of a Modal Form called by a Main Form - embarcadero.delphi.firemonkey

Help:Contents/Account settings and maintenance - Wikipedia, the free encyclopedia
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc. , a non-profit organization.

Campaign setting - Wikipedia, the free encyclopedia
A campaign setting is usually a fictional world which serves as a setting for a role-playing game or wargame campaign. A campaign is a series ...

Privacy Setting For New Facebook Users Aged 13-17 Now Defaults To ‘Friends’
Facebook is changing the initial default privacy setting for users aged 13 through 17 to friends, from friends of friends, but those teen users ...

Facebook changes default privacy settings for new users to friends-only
Facebook announced today a shift in privacy settings for new users. Now, when someone signs up for a profile, their default posting status is ...

Helicopter missing after setting off from Tamworth to Northern Beaches - DailyTelegraph Search Search ...
MILLIONAIRES Richard and Carolyn Green have been killed along with filmmaker friend John Davis in a tragic helicopter accident while travelling ...

Helicopter missing after setting off from Tamworth to Northern Beaches
MILLIONAIRES Richard and Carolyn Green have been killed along with filmmaker friend John Davis in a tragic helicopter accident while travelling ...

Has Windows 10 November Update (Threshold 2) reset your privacy settings and default apps?
... 10 has caused greater privacy concerns than any previous version of the operating system. You may well have spent some time tweaking settings ...

Robot price-setting has just begun
Uber gets criticism for surge pricing, but dynamic pricing is showing up in more and more places.

See Just Cause 3 running on max settings in 4K
After the whole usual pre-release kerfuffle and grumbling about Just Cause 3 running at 1080p on PS4 and 900p on Xbox One, here is some dedicated ...

Xbox One update brings back Xbox 360's universal controller settings
You don't need to drop $150 on the Xbox One Elite controller to get access to one of its most prominent features: remapping the gamepad's buttons. ...

Resources last updated: 11/22/2015 4:46:26 PM