[fpc-devel] Parameters must match exactly?

Graeme Geldenhuys graemeg.lists at gmail.com
Mon May 17 11:41:22 CEST 2010


Hi,

Sorry, I'm still battling with this. My original code looked as follows:

procedure TfpgApplicationBase.CreateForm(AFormClass: TComponentClass; out
AForm: TfpgWindowBase);
begin
  try
    AForm := TfpgWindowBase(AFormClass.Create(self));
    if FMainForm = nil then
      FMainForm := AForm;
  except
    AForm := nil;
    raise;
  end;
end;


I then used that method as follows:

var
  BulkDiscountListForm: TBulkInvoiceRateListForm;

function DisplayMyForm: boolean:
begin
  fpgApplication.CreateForm(TBulkInvoiceRateListForm,
     BulkDiscountListForm);
  try
    Result := BulkDiscountListForm.ShowModal = mrOK;
    if Result then
      // save data
  finally
    BulkDiscountListForm.Free;
  end;
  ...
end;


This doesn't work with FPC 2.5.1.  I then removed the 'out' parameter type
and my code compiled, but now it gives the following compiler warning all
over the place for each form I create.


frm_bulkdiskcountlist.pas(55,3) Warning: Variable BulkDiscountListForm"
read but nowhere assigned


This is something the 'out' parameter type normally prevents. So now what?
 Looking at LCL's Application.CreateForm(), they do something totally
different. They use a 'out' parameter, but make it untyped???  Why untyped
(plain untyped pointer)? I don't want somebody passing a TStringList type
as the AForm parameter, which the compiler will not detect with a untyped
parameter. That is why I used TfpgWindowBase so I know only descendant
types of TfpgWindowBase is allowed.

Looking at the Lazarus code for Application.CreateForm. Now they do other
strange things too, creating a instance without calling the constructor
etc... This doesn't seem like something I want either and still doesn't
solve the problem where somebody could pass in any object type to CreateForm.

I'm out of ideas here...  :-/


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://opensoft.homeip.net/fpgui/




More information about the fpc-devel mailing list