---- Question 2 and Solutions
Each record in the introduction table In addition to the content in the ISO file, you also need the type, period, and ID number of the book, and TPGCSV only handle data related to data in the text file when inserting a new record, so The content of these fields requires us to join. Needless to say, naturally think of the AfterInsert event in Table. But the question is, my table is in the DataModule unit, I must pass the parameters to the AfterInsert event, trouble! At the same time, such processing will bring confusion on maintenance, and events that occur in a unit should be processed by functions or processes in this unit. So, I thought I wrote a process in the current unit, and then assigned this process to the AFTERINSERT event when the program is run, and then disabled after the introduction. Feasible, but still trouble! Since most of the cases will encounter such problems, why is there a hundred, pack this incident?
As with the same problem, we still need an event processing process after INSERT. This time should you add? Everyone will see it in an eye:
Procedure tpgcsv.csvtodataset;
Begin
...
FDataSet.disableControls;
While (Not Eof (FSTOP) DO
Begin
// read from CSV
Readln (FFile, Recordstring);
// xm4014's mode
IF assigned (fregulateString) THEN
Fregulatestring (Self, Recordstring);
// Add New Record
Try
FDataSet.Append;
/ / Should be added here!
// xm4014's mode
IF assigned (fafterInsert) THEN
AfterInsert (Self, FDataSet);
...
For i: = 1 to CountMapItems DO
...
END;
Similarly, here you need to define new event declarations and event properties, because you need to pass the fdataSet parameters, declare that the code can see the Delphi control (2) (http://www.9cbs.net/develop/read_article. ASP? ID = 11855).
Re-compiling the control, you can add code, period, and ID number to the book, period, and ID number to the AFTERINSERT event.
---- Question Three and Solutions
The problem involving the database is now resolved. But there is also a display problem. The program requires the import progress with the ProgressBar. In order to set the value of ProgressBar.max, how many records I need to know in the ISO file before importing, ie A similar to RecordCount properties. But there is no such property in the TPGCSV.
Then let's add such an attribute.
// xm4014's mode
Property CSVRecordcount: Integer Read FcsvrecordCount Write FcsvrecordCount Default 0;
How to assign it? It is very simple, you can scan the ISO file with readln (f), and then add the number of scans.
The key is where this is handled. It is clear that for the same file, such a job can only be done once. Since it is necessary to re-statistics for different files, we can scan your text files every time you set the file name properties.
Ok, find the file name attribute of TPGCSV
Property CSVFile: String Read Fcsvfile Write Fcsvfile;
Do a small change
New attribute statement
Property CSVFile: String Read Fcsvfile Write SetCsVFile; Press Ctrl Shift C to write setsVfile method code as follows
Procedure tpgcsv.setfcsvfile (const value: string);
VAR
F1: TextFile;
ICOUNT: INTEGER;
Begin
IF FCSVFILE <> Value Then
Begin
FCSVFILE: = Value;
/ / The file name is changed, then rescan, change the value of fcsvrecordcount
If FileExists (Value) THEN
Begin
AssignFile (F1, Value);
RESET (F1);
ICOUNT: = 0;
While Not Eof (F1) DO
Begin
Readln (F1);
ICOUNT;
END;
FCSVRecordcount: = iCount;
END;
END;
END;
After compilation, we can get a recorded value for the CSVRecordCount property before the import operation:
Progressbar1.min: = 0;
Progressbar1.max: = pgcsv1.csvrecord;
The above procedure is debugged at Delphi 6.0 / Win98
Write here is basically a big success. In fact, the modifications you have made before and after the fingers can be drawn. But this is a little upgrade, let me really feel more, I have a hand, I think, I will use it next time. At the time, I will get together to get its value. And after such an analysis, I also grow a lot, and a few drops more than half a scoop, huh!
It should be pointed out that TPGCSV is a simple control, which is neither a complicated relationship, nor involves calls to the VCL core content, so there is not much concern when modified. Once the source code involves When a complicated hierarchy is required, you need to think about each line of code you added or modified, otherwise, it may take a mess, and finally want to look back. Therefore, what I said is the principle In fact, it relies on the function of the control itself without the changes in substantial content. To reach the realm they want, you (I am also) will continue to work hard!
(With: TPGCSV download address http://www.internet-bj.com/delphikongjian.asp?id=2)