Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass a form to a procedure (Delphi for .Net).

Status
Not open for further replies.

MacCybex

Programmer
Nov 25, 2004
11
LV
Have a form:

type
frmMain = class(System.Windows.Forms.Form)

Need to pass it to a procedure:
procedure ReadSettings(var frmMain: frmMain);

But when I start to compile this code:
ReadSettings(frmMain);
I receive this message:
[Pascal Error] MainForm.pas(148): E2033 Types of actual and formal var parameters must be identical

Please help me to solve this problem.
 
If I were you, I would not give the form type and the form variable the same name. Instead name the type TfrmMain and leave the variable named as it is.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
As far as I have found out in this version of Delphi (for .Net) both name and type have a same name :). Unlike in Delphi it was Name and TName.

But I've sold the problem by using Self operator, like this:
ReadSettings(sMain, Self);
 
Oh ok, thanks for the info.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
I think that the reason for the error message is that the compiler doesn't know whether or not you are passing in the actual form or the type - which is why self does work.

Just because it is permissable for an object and a type to have the same name does not mean that it is a requirement. Personally, I would never do that if for no other reason than because of the confusion that it can cause (as you have experienced).

Hope this helps.

[vampire][bat]
 
Thanks for the advice, but in Delphi for .Net it is a little bit different than in usual one(for Win32 as it is called in BDS2006). And I am using it for a few days only, figuring everything out.
 
That does not change anything that I said before - you do not have to give objects the same name as their type.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top