Home > Back-end >  Instances of the class
Instances of the class

Time:09-24

Members of the class have four respectively file name, path, exists, whether the packaging, among them, by traversing the file directory to get the full path and filename is obtained, and can judge whether there is any, then reads the configuration file, as long as there is, or can be packaged,
Traverse the file directory of the code is:
Void __fastcall Hfile: : SearchDir (AnsiString Dir, TStrings * FileList)
{
TSearchRec sr;
If (FindFirst (Dir + "\ \ *. *", faAnyFile, sr)==0)
{
Do
{
If (sr Name!=". "& amp; & The sr Name!="..
"){
FileList - & gt; Add (Dir + "\ " + sr. Name);
If (sr) Attr & amp; & FaAnyFile==faAnyFile)
SearchDir (Dir + "\ " + sr. The Name, the FileList);
}
} while (FindNext (sr)==0).
FindClose (sr);
}
}
Code for reading configuration files:
Void __fastcall Hfile: : ReadConfigFName (String, FName TStringList * FileList)
{
Ini TIniFile *=new TIniFile (" d: \ \ test ini ");
String secStr="playhistory";
Int nCount=ini - & gt; ReadInteger (secStr, "count", nCount);
For (int nIndex=1; NIndex & lt; NCount + 1; NIndex++)
{
String NewFName=ini - & gt; ReadString (secStr, "File" + IntToStr (nIndex), FName);
FileList - & gt; Add (NewFName);
}
The delete ini.
}
Establish a class for:
The class Hfile
{
Public:
Void __fastcall SearchDir (AnsiString Dir, TStrings * FileList);
Void __fastcall ReadConfigFName (String, FName TStringList * FileList);
Void __fastcall FileHandle ();
Private:
The String FileName.
String FilePath.
Bool IsFile;
Bool IsPack;
};
Now, my demand is that through the establishment of the object of the class, of course, the object of the class a lot, such as myfile1 myfile2,... , myfilei exactly how many is unknown, the four members in separately to each of the objects, and then for each object of the class in a Listview, now need to add a file handler class member functions FileHandle, four members will be required to fill the object of the class, I built a unit, everything here is complete, the main form is only responsible for Listview display, don't know what I say is clear enough?
  • Related