Home > Back-end >  Call the other window procedure of the events
Call the other window procedure of the events

Time:10-30

Masters help ah, I have two forms, made A procedure in A form, but the call in the B form, is always an error, or suggest not enough parameters, or suggest too many parameters, where is the problem really out?
A form of code: (you can compile A success)
The unit updateunit;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ComCtrls, IdBaseComponent IdComponent,
IdTCPConnection IdTCPClient, IdFTP inifiles, shellapi, jpeg.

Type
Tupdate=class (TForm)
Update: TButton;
Cancel: TButton;
ProgressBar1: TProgressBar;
Label1: TLabel;
ListView1: TListView;
IdFTP1: TIdFTP;
ProgressBar2: TProgressBar;
Label2: TLabel;

Private
{Private declarations}
Public
{Public declarations}
Procedure idftp1work (sender: Tobject; AWorkmode: Tworkmode; Const AWorkcount: integer);
Procedure idftp1workend (sender: Tobject; AWorkmode: Tworkmode);
Procedure loadini;
Procedure connectftp;

end;

Var
Update: Tupdate;
The host, username, password, host_new username_new, password_new: string;
Rootpath dirpath, dirpath_new exepath: string;
Conftpini conftpini_new: Tinifile;
Fmainexe fmainexe_new, fparam fparam_new: string;
Version, version_new: string;
Implementation

{$R *. DFM}

Procedure Tupdate. Idftp1work (sender: Tobject; AWorkmode: Tworkmode; Const AWorkcount: integer);
The begin
Progressbar1. Position:=aworkcount;
Application. ProcessMessages;
end;

Procedure Tupdate. Idftp1workend (sender: Tobject; AWorkmode: Tworkmode);
The begin
Progressbar1. Position:=0;
Progressbar2. StepBy (1);
end;

Procedure Tupdate. Loadini;//read ini information here
The begin
Conftpini:=Tinifile. Create (extractfilepath (application. ExeName) + 'FTP. Ini');
Host:=conftpini. ReadString (' ftpinfo ', 'host', ');
Username:=conftpini. ReadString (' ftpinfo ', 'username', ');
Password:=conftpini ReadString (' ftpinfo 'and' password ', ');
Dirpath:=conftpini ReadString (' ftpinfo ', 'dirpath', ');
Fmainexe:=conftpini ReadString (' coninfo ', 'main', ');
Fparam:=conftpini ReadString (' conftpini ', 'param', ');
Version:=conftpini ReadString (' version ', 'version', ')
end;

Procedure Tupdate. Connectftp;//connect to FTP server
The begin
Idftp1. Host:=Host;
Idftp1. Username: the Username=;
Idftp1. Password:=Password;
Idftp1. Port:=21;
Idftp1. The Connect ();
Rootpath:=idftp1. RetrieveCurrentDir;
end;

End.

B the form code:
The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls ComCtrls, IdBaseComponent IdComponent,
IdTCPConnection, IdTCPClient IdFTP;

Type
TForm1=class (TForm)
For: TButton;
Edit1: TEdit;
StatusBar1: TStatusBar;
Procedure FormCreate (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation
USES updateunit;//here refer to A form of pas file
{$R *. DFM}

Procedure TForm1. FormCreate (Sender: TObject);
The begin

Updateunit. Update. Loadini;
Updateunit. Update. Connectftp;//an error here,

end;

End.


-- -- -- -- -- I'd like to call on B form A form of Tupdate connectftp method, but an error, don't know where the problem, what parameter to preach to come over? Each prawn to help me have a look, thank you,

CodePudding user response:

Do you want to create A instance, through instance to access, otherwise the function declarations to the class level

CodePudding user response:

Agree with the moderator, A form to create an instance,

CodePudding user response:

Sweat, incredibly make such a mistake,,

CodePudding user response:

reference 1st floor BDMH response:
what do you want to create A instance, through the instance to visit, otherwise the function declarations to the class level of
I am A novice, don't know how to create A instance, can you help me to change on the above code? Thank you very much!

CodePudding user response:

Procedure TForm1. FormCreate (Sender: TObject);
Then begin the if not Assigned (updateunit. Update)
Updateunit. Update:=updateunit. Tupdate. Create (nil);
Updateunit. Update. Loadini;
Updateunit. Update. Connectftp;//an error here,

end;

CodePudding user response:

reference 5 floor xiaojun5556 reply:
procedure TForm1. FormCreate (Sender: TObject);
Then begin the if not Assigned (updateunit. Update)
Updateunit. Update:=updateunit. Tupdate. Create (nil);
Updateunit. Update. Loadini;
Updateunit...
is an error, but thank you.

CodePudding user response:

Sweat... ; Has such use, have not seen you say wrong

CodePudding user response:

Build another TUpdate variable,

CodePudding user response:

Procedure TForm1. FormCreate (Sender: TObject);
Var Fupdate: Tupdate;
The begin
Fupdate:=Tupdate. Create (Self);
Fupdate. Loadini;
Fupdate. Connectftp;
.
//Fupdate. Free;
end;

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related