Home > Back-end >  New food problem... Where is the great god??
New food problem... Where is the great god??

Time:09-25

I wrote a class, the class to do some database query in the query, so I put several fdquery members in class, in the constructor is assigned to them as an example, this right?? :

 



Tsuanfa=class (TObject)
Private
Query1: TFDQuery;
Query2: TFDQuery;
Query3: TFDQuery;


The constructor Tsuanfa. Create (q1, q2, q3: TFDQuery);
The begin
Query1:=q1;//assign right? Like this?
Query2:=q2;
Query3:=q3;
end;


//use:
SuanfaL:=Tsuanfa. Create (FDQuery3 FDQuery4, FDQuery5);
SuanfaL. Elo_ReDoAll (0);
SuanfaL. Free;



CodePudding user response:

Your q1 and q2, q3 didn't create an instance, DELPHI, declare the variable is not equal to create the instance
According to the writing class, you do this using the

//use:
//to create an instance
FDQuery3:=TFDQuery. Create;//the CREATE ever parameters, you see,
FDQuery4:=TFDQuery. Create;
FDQuery5:=TFDQuery. Create;
//to use
SuanfaL:=Tsuanfa. Create (FDQuery3 FDQuery4, FDQuery5);
SuanfaL. Elo_ReDoAll (0);
SuanfaL. Free;

Guess what you mean, however, is to realize such functions:?
Tsuanfa=class (TObject)
Private
FQuery1: TFDQuery;//private variables usually begins with F
FQuery2: TFDQuery;
FQuery3: TFDQuery;
.
//if the external program to invoke the three objects within the class, can be attribute to visit; If you don't call directly, need not statement (this application more generally)
Public
The property Query1: TFDQuery read FQuery1;
The property Query2: TFDQuery read FQuery2;
The property Query3: TFDQuery read FQuery3;
end;

The constructor Tsuanfa. Create;
The begin
FQuery1:=TFDQuery. Create;
FQuery2:=TFDQuery. Create;
FQquery3:=TFDQuery. Create;
end;
Destructor Tsuanfa. Destroy;
The begin
FQuery1. Free;
FQuery2. Free;
FQuery3. Free;
Inherited;
end;

CodePudding user response:

In class, you only declared the TFDQuery variables, when using, can only reference entity TFDQuery outside of class, so no closed data, the meaning is not big,
  • Related