弄完了,我的程序如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, inifiles, Buttons, Db, DBTables, DBGrids;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button3: TButton;
DBGrid1: TDBGrid;
Table1: TTable;
Database1: TDatabase;
DataSource1: TDataSource;
ListBox1: TListBox;
Label1: TLabel;
procedure GetValue(stockname,Value: string);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Tform1.GetValue(stockname,Value: string);
var iPosion: integer;
s1,s2,s3,s4,s5,s6:string;
begin
s1:=stockname;
iPosion := Pos(',', Value)-1;
s2:=copy(value,0,iposion);
value:=copy(value,iposion+2,length(value)-iposion);
iPosion := Pos(',', Value)-1;
s3:=copy(value,0,iposion);
value:=copy(value,iposion+2,length(value)-iposion);
iPosion := Pos(',', Value)-1;
s4:=copy(value,0,iposion);
value:=copy(value,iposion+2,length(value)-iposion);
iPosion := Pos(',', Value)-1;
s5:=copy(value,0,iposion);
value:=copy(value,iposion+2,length(value)-iposion);
iPosion := Pos(',', Value)-1;
s6:=copy(value,0,iposion);
if not table1.Active then table1.Open;
table1.append;
table1.FieldByName('stockid').asstring:=s1;
table1.FieldByName('curdate').asstring:=s2;
table1.FieldByName('openprice').asstring:=s3;
table1.FieldByName('highest').asstring:=s4;
table1.FieldByName('lowest').asstring:=s5;
table1.FieldByName('latest').asstring:=s6;
table1.post;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
I, J: integer;
F: TextFile;
FirstLine: string;
openprice, hightest: string;
tempstr: string;
begin
OpenDialog1.Options := [ofAllowMultiSelect, ofFileMustExist];
OpenDialog1.Filter := 'Text files (*.txt)|*.txt|All files (*.*)|*.*';
OpenDialog1.FilterIndex := 2; { start the dialog showing all files }
if OpenDialog1.Execute then
with OpenDialog1.Files do
for I := 0 to Count - 1 do
begin
listbox1.Items.LoadFromFile(Strings);
tempstr := ExtractFilename(Strings);
tempstr := copy(tempstr, 0, pos('.', tempstr) - 1);
for j := 1 to listbox1.Items.Count - 1 do
GetValue(tempstr,listbox1.Items[j]);
table1.Close;
table1.open;
end;
end;
end.