[fpc-devel] Parameters must match exactly?

Michael Van Canneyt michael at freepascal.org
Fri May 14 16:50:36 CEST 2010



On Fri, 14 May 2010, Graeme Geldenhuys wrote:

> Hi,
>
> I tried using FPC 2.5.1 today to see how compatible is our application with
> it compared to FPC 2.4.1
>
> I got stacks of the following errors.  Why is this change forced in FPC
> 2.5.1?  TBulkInvoiceRateListForm class is a descendant of TfpgWindowBase so
> there should be a problem. I don't understand. :-/
>
> -------------
> frm_bulkinvoiceratelist.pas(84,77) Error: Call by var for arg no. 2 has to
> match exactly: Got "TBulkInvoiceRateListForm" expected "TfpgWindowBase"
> fpg_base.pas(2207,31) Hint: Found declaration:
> TfpgApplicationBase.CreateForm(TComponentClass,out TfpgWindowBase);
> frm_bulkinvoiceratelist.pas(307) Fatal: There were 1 errors compiling
> module, stopping
> --------------------
>
>
> To get my code to compile again, I have to change the following code from
>
> fpgApplication.CreateForm(TBulkInvoiceRateListForm, BulkDiscountListForm);
>
> ...to this...
>
> fpgApplication.CreateForm(TBulkInvoiceRateListForm,
>    TfpgWindowBase(BulkDiscountListForm));
>
> Now I have to include ugly casts all over the place. :-(
>
>
> I got similar issues with TStrings and TStringList. TStringList is a
> descendant of TStrings, but I can't pass a TStringList type as a parameter
> to a method declared with TStrings.
>
>
> Maybe I don't understand the var parameter correctly (but haven't tested to
> see what happens if I remove var from parameter list). If I have a class
> instance, when should I pass it to a method or function/procedure as var
> and when don't I need to use var parameters?

You only need var/out when you want to change the instance pointer, i.e. 
switch to another instance. And I count FreeAndNil() among this. (.Free
on the other hand is still possible, but not recommended).

If  you just want to set properties or call methods on an existing instance,
there is no need to use out or var.

Michael.



More information about the fpc-devel mailing list