SQL OOP problem : Too many actual parameters on ou

2019-06-14 20:42发布

问题:

Please help with the following:

ERROR : too many actual parameters on calling class procedure line.

Main UNIT:

procedure TForm1.btnbtbtn1Click(Sender: TObject);
var
  bwagwoord,bemail :boolean ;
  epos,wagwoord,safvoer :String ;
begin
  Form2.qryreg.Close;
  form2.qryreg.SQL.Text := 'select * from registertb ';
form2.qryreg.open ;

epos := edt1.text ;
wagwoord := edt2.text ;
safvoer := ' ';
bemail :=form2.qryreg.locate ('Email',epos,[]);
bwagwoord := form2.qryreg.Locate('Wagwoord',wagwoord,[]);


Login.create(epos,wagwoord,bepos,bwagwoord);
Login.toetslog(safvoer);
showmessage(safvoer);
end;

CLASS:

unit cls_login;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, Buttons, math, ExtCtrls;
type
Tlogin = class(Tobject)

private

Fepos :string ;
fwagwoord :string ;
Fbepos : Boolean;
fbwagwoord : Boolean;


Constructor Create(epos,wagwoord:String;bepos, bwagwoord: boolean);
procedure toetslog(var safvoer :string );
public
end;
implementation

{ Tlogin }
constructor Tlogin.Create(epos, wagwoord: String;bepos, bwagwoord: boolean);
begin
fepos := epos ;
fwagwoord := wagwoord ;
fbepos := bepos;
fbwagwoord := bwagwoord;
end;
procedure Tlogin.toetslog( var safvoer :String );
begin

if (fbepos = True) and (fbwagwoord = True)
then
begin
safvoer := 'Welcome '+' '+fepos
 end
else
safvoer := 'SORRY VERKEERD HEHE'+' '+fwagwoord ;
end;

end.    

回答1:

OK, I have been wading through your poorly formatted code, and I think I found the problem. Your question did not make it easy, though: as I said, your code shows poor formatting and the error message is probably wrong too. If the code had been formatted, and the error reported literally, the problem would have been rather obvious.

Your constructor TLogin.Create() and your method TLogin.toetslog() are both private. If you try to call them from another unit, they are not accessible. So, from the main unit, the only valid constructor is Create without parameters. If you call Create with parameters, then you will get the error "Too many parameters on call to..." or similar.

Do it this way:

type
  TLogin = class(TObject)
  private
    Fepos: string;
    Fwagwoord: string ;
    Fbepos: Boolean;
    Fbwagwoord: Boolean;
  public
    constructor Create(epos, wagwoord: string; bepos, bwagwoord: Boolean);
    procedure ToetsLog(var safvoer: string);
  end;

And call the constructor this way:

  Login := TLogin.Create(epos, wagwoord, bepos, bwagwoord);


回答2:

Hard to match the error message with the code but I think you're using/creating the Login object wrong.

  //Login.create(epos,wagwoord,bepos,bwagwoord);
  Login := TLogin.create(epos,wagwoord,bepos,bwagwoord);


标签: delphi oop